Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions LSpec.lean
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import LSpec.LSpec
import LSpec.Instances
import LSpec.SlimCheck
module
public import LSpec.LSpec
public import LSpec.Instances
public import LSpec.SlimCheck
5 changes: 4 additions & 1 deletion LSpec/Instances.lean
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import LSpec.LSpec
module
public import LSpec.LSpec

/-!
# Testable Instances
Expand All @@ -16,6 +17,7 @@ LSpec to test equality, inequality, and bounded quantification directly.
-/

namespace LSpec
public section

/-- Testable instance for decidable equality. -/
instance (priority := 50) (x y : α) [DecidableEq α] [Repr α] : Testable (x = y) :=
Expand Down Expand Up @@ -85,4 +87,5 @@ instance Nat.Testable_forall_lt
| .isFalse h failedAt totalTests msg => .isFalse (λ h' => h λ n hn => h' _ (Nat.le_succ_of_le hn)) failedAt totalTests msg
| .isFailure failedAt totalTests msg => .isFailure failedAt totalTests msg

end
end LSpec
7 changes: 4 additions & 3 deletions LSpec/LSpec.lean
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Lean
import LSpec.SlimCheck.Checkable
module
public import LSpec.SlimCheck.Checkable

/-!
# The core `LSpec` framework
Expand Down Expand Up @@ -64,7 +64,7 @@ Use `check` and `checkIO` (without apostrophe) for simpler output.
-/

namespace LSpec

public section
/--
The main typeclass of propositions that can be tested by `LSpec`.

Expand Down Expand Up @@ -585,4 +585,5 @@ def lspecEachIO (l : List α) (f : α → IO TestSeq) : IO UInt32 := do
| (false, msg) => IO.eprintln msg; pure false
if success then return 0 else return 1

end
end LSpec
7 changes: 4 additions & 3 deletions LSpec/SlimCheck.lean
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import LSpec.SlimCheck.Gen
import LSpec.SlimCheck.Checkable
import LSpec.SlimCheck.Sampleable
module
public import LSpec.SlimCheck.Gen
public import LSpec.SlimCheck.Checkable
public import LSpec.SlimCheck.Sampleable
12 changes: 8 additions & 4 deletions LSpec/SlimCheck/Checkable.lean
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Henrik Böving, Simon Hudon
-/

import LSpec.SlimCheck.Sampleable
import Lean
module
public import LSpec.SlimCheck.Sampleable
public import Lean.Elab.Tactic.Basic
meta import Lean.Elab.Tactic.Basic

/-!
# `Checkable` Class
Expand Down Expand Up @@ -61,7 +63,7 @@ random testing
-/

namespace SlimCheck

public section
/-- Result of trying to disprove `p`
The constructors are:
* `success : (PSum Unit p) → TestResult p`
Expand Down Expand Up @@ -127,6 +129,7 @@ instance (priority := low) : PrintableProp p where
class Checkable (p : Prop) where
run (cfg : Configuration) (minimize : Bool) : Gen (TestResult p)

@[expose]
def NamedBinder (_n : String) (p : Prop) : Prop := p

namespace TestResult
Expand Down Expand Up @@ -458,7 +461,7 @@ open Lean

/-- Traverse the syntax of a proposition to find universal quantifiers
quantifiers and add `NamedBinder` annotations next to them. -/
partial def addDecorations (e : Expr) : Expr :=
meta partial def addDecorations (e : Expr) : Expr :=
e.replace fun expr => match expr with
| Expr.forallE name type body data =>
let n := name.toString
Expand Down Expand Up @@ -507,4 +510,5 @@ def Checkable.check (p : Prop) (cfg : Configuration := {})
-- #eval Checkable.check (∀ (x : (Nat × Nat)), x.fst - x.snd - 10 = x.snd - x.fst - 10) Configuration.verbose
-- #eval Checkable.check (∀ (x : Nat) (h : 10 < x), 5 < x) Configuration.verbose

end
end SlimCheck
3 changes: 3 additions & 0 deletions LSpec/SlimCheck/Control/DefaultRange.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Copyright (c) 2022 Hanting Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hanting Zhang
-/
module

/-!
# Bounded and DefaultRange classes
Expand All @@ -29,6 +30,7 @@ Lean developers, please forgive us.
-/

namespace SlimCheck
public section

class Bounded (α : Type u) where
lo : α
Expand Down Expand Up @@ -58,4 +60,5 @@ instance : DefaultRange Int where
lo := - Int.ofNat (USize.size / 2)
hi := Int.ofNat (USize.size / 2 - 1)

end
end SlimCheck
5 changes: 4 additions & 1 deletion LSpec/SlimCheck/Control/Random.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Copyright (c) 2022 Henrik Böving. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Henrik Böving
-/
import LSpec.SlimCheck.Control.DefaultRange
module
public import LSpec.SlimCheck.Control.DefaultRange

/-!
# Rand Monad and Random Class
Expand All @@ -29,6 +30,7 @@ defining objects that can be created randomly.
-/

namespace SlimCheck
public section

/-- A monad to generate random objects using the generic generator type `g` -/
abbrev RandT (g : Type) := StateM (ULift g)
Expand Down Expand Up @@ -133,4 +135,5 @@ def IO.runRand (cmd : Rand α) : BaseIO α := do
def IO.runRandWith (seed : Nat) (cmd : Rand α) : BaseIO α := do
pure $ (cmd.run (ULift.up $ mkStdGen seed)).1

end
end SlimCheck
5 changes: 4 additions & 1 deletion LSpec/SlimCheck/Gen.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Copyright (c) 2021 Henrik Böving. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Henrik Böving, Simon Hudon
-/
import LSpec.SlimCheck.Control.Random
module
public import LSpec.SlimCheck.Control.Random

/-!
# `Gen` Monad
Expand All @@ -19,6 +20,7 @@ random testing
-/

namespace SlimCheck
public section

open Random

Expand Down Expand Up @@ -118,4 +120,5 @@ end Gen
def Gen.run (x : Gen α) (size : Nat) : BaseIO α :=
IO.runRand $ ReaderT.run x ⟨size⟩

end
end SlimCheck
6 changes: 5 additions & 1 deletion LSpec/SlimCheck/Sampleable.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Copyright (c) 2022 Henrik Böving. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Henrik Böving, Simon Hudon
-/
import LSpec.SlimCheck.Gen
module
public import LSpec.SlimCheck.Gen

/-!
# `SampleableExt` Class
Expand Down Expand Up @@ -63,6 +64,7 @@ random testing
-/

namespace SlimCheck
public section

open Random

Expand Down Expand Up @@ -205,6 +207,7 @@ instance Prop.sampleableExt : SampleableExt Prop where
end Samplers

/-- An annotation for values that should never get shrinked. -/
@[expose]
def NoShrink (α : Type u) := α

namespace NoShrink
Expand All @@ -223,4 +226,5 @@ instance sampleableExt [SampleableExt α] [Repr α] : SampleableExt (NoShrink α

end NoShrink

end
end SlimCheck