aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/specification/lux/abstract/apply.lux
diff options
context:
space:
mode:
authorEduardo Julian2022-11-05 21:23:20 -0400
committerEduardo Julian2022-11-05 21:23:20 -0400
commitfd8ea1e1b9cae781abe42aeadda2e0ef149994d6 (patch)
tree7fdc152ac481d4f2a8b7be12c98d11a8c644f541 /stdlib/source/specification/lux/abstract/apply.lux
parent736521eb56a45122eb0a545b677d3ffca1451080 (diff)
Property-based testing can now log/print successful seeds from run.
Diffstat (limited to '')
-rw-r--r--stdlib/source/specification/lux/abstract/apply.lux101
1 files changed, 45 insertions, 56 deletions
diff --git a/stdlib/source/specification/lux/abstract/apply.lux b/stdlib/source/specification/lux/abstract/apply.lux
index 607024f11..eaf4d741c 100644
--- a/stdlib/source/specification/lux/abstract/apply.lux
+++ b/stdlib/source/specification/lux/abstract/apply.lux
@@ -16,64 +16,53 @@
[\\library
["[0]" / (.only Apply)]]
[//
- [functor (.only Injection Comparison)]])
+ ["[0]S" functor (.only Injection Comparison)]])
-(def (identity injection comparison (open "/#[0]"))
+(def .public (spec injection comparison it)
(All (_ f) (-> (Injection f) (Comparison f) (Apply f) Test))
- (do [! random.monad]
- [sample (at ! each injection random.nat)]
- (_.test "Identity."
- ((comparison n.=)
- (/#on sample (injection function.identity))
- sample))))
+ (<| (_.for [/.Apply])
+ (type.let [:$/1: (-> Nat Nat)])
+ (do [! random.monad]
+ [sample random.nat
+ increase (is (Random :$/1:)
+ (at ! each n.+ random.nat))
+ decrease (is (Random :$/1:)
+ (at ! each n.- random.nat))])
+ (all _.and
+ (_.for [/.functor]
+ (functorS.spec injection comparison (the /.functor it)))
-(def (homomorphism injection comparison (open "/#[0]"))
- (All (_ f) (-> (Injection f) (Comparison f) (Apply f) Test))
- (do [! random.monad]
- [sample random.nat
- increase (at ! each n.+ random.nat)]
- (_.test "Homomorphism."
- ((comparison n.=)
- (/#on (injection sample) (injection increase))
- (injection (increase sample))))))
+ (_.coverage [/.on]
+ (let [(open "/#[0]") it
-(def (interchange injection comparison (open "/#[0]"))
- (All (_ f) (-> (Injection f) (Comparison f) (Apply f) Test))
- (do [! random.monad]
- [sample random.nat
- increase (at ! each n.+ random.nat)]
- (_.test "Interchange."
- ((comparison n.=)
- (/#on (injection sample) (injection increase))
- (/#on (injection increase) (injection (is (-> (-> Nat Nat) Nat)
- (function (_ f) (f sample)))))))))
+ identity!
+ ((comparison n.=)
+ (/#on (injection sample)
+ (injection function.identity))
+ (injection sample))
-(def (composition injection comparison (open "/#[0]"))
- (All (_ f) (-> (Injection f) (Comparison f) (Apply f) Test))
- (type.let [:$/1: (-> Nat Nat)]
- (do [! random.monad]
- [sample random.nat
- increase (is (Random :$/1:)
- (at ! each n.+ random.nat))
- decrease (is (Random :$/1:)
- (at ! each n.- random.nat))]
- (_.test "Composition."
- ((comparison n.=)
- (|> (injection (is (-> :$/1: :$/1: :$/1:)
- function.composite))
- (/#on (injection increase))
- (/#on (injection decrease))
- (/#on (injection sample)))
- (/#on (/#on (injection sample)
- (injection increase))
- (injection decrease)))))))
-
-(def .public (spec injection comparison apply)
- (All (_ f) (-> (Injection f) (Comparison f) (Apply f) Test))
- (_.for [/.Apply]
- (all _.and
- (..identity injection comparison apply)
- (..homomorphism injection comparison apply)
- (..interchange injection comparison apply)
- (..composition injection comparison apply)
- )))
+ homomorphism!
+ ((comparison n.=)
+ (/#on (injection sample) (injection increase))
+ (injection (increase sample)))
+
+ interchange!
+ ((comparison n.=) (/#on (injection sample) (injection increase))
+ (/#on (injection increase) (injection (is (-> (-> Nat Nat) Nat)
+ (function (_ f) (f sample))))))
+
+ composition!
+ ((comparison n.=)
+ (|> (injection (is (-> :$/1: :$/1: :$/1:)
+ function.composite))
+ (/#on (injection increase))
+ (/#on (injection decrease))
+ (/#on (injection sample)))
+ (/#on (/#on (injection sample)
+ (injection increase))
+ (injection decrease)))]
+ (and identity!
+ homomorphism!
+ interchange!
+ composition!)))
+ )))