aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/abstract/interval.lux
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/test/lux/abstract/interval.lux60
1 files changed, 39 insertions, 21 deletions
diff --git a/stdlib/source/test/lux/abstract/interval.lux b/stdlib/source/test/lux/abstract/interval.lux
index 92f2a6faf..1a15336f5 100644
--- a/stdlib/source/test/lux/abstract/interval.lux
+++ b/stdlib/source/test/lux/abstract/interval.lux
@@ -20,14 +20,15 @@
[math
["r" random (#+ Random)]]]
{1
- ["." / (#+ Interval) (",@." equivalence)]})
+ ["." / (#+ Interval) ("#@." equivalence)]})
(template [<name> <cmp>]
[(def: #export <name>
(Random (Interval Nat))
(do r.monad
[bottom r.nat
- top (|> r.nat (r.filter (|>> (n.= bottom) not)))]
+ top (r.filter (|>> (n.= bottom) not)
+ r.nat)]
(if (<cmp> top bottom)
(wrap (/.between n.enum bottom top))
(wrap (/.between n.enum top bottom)))))]
@@ -49,6 +50,21 @@
..outer
..singleton))
+(def: types
+ Test
+ (do r.monad
+ [inner ..inner
+ outer ..outer
+ singleton ..singleton]
+ ($_ _.and
+ (_.test (%.name (name-of /.inner?))
+ (/.inner? inner))
+ (_.test (%.name (name-of /.outer?))
+ (/.outer? outer))
+ (_.test (%.name (name-of /.singleton?))
+ (/.singleton? singleton))
+ )))
+
(def: boundaries
Test
(do r.monad
@@ -56,14 +72,14 @@
top r.nat
#let [interval (/.between n.enum bottom top)]]
($_ _.and
- (_.test "A boundary value belongs to its interval."
+ (_.test (%.name (name-of /.within?))
(and (/.within? interval bottom)
(/.within? interval top)))
- (_.test "An interval starts with its bottom."
+ (_.test (%.name (name-of /.starts-with?))
(/.starts-with? bottom interval))
- (_.test "An interval ends with its top."
+ (_.test (%.name (name-of /.ends-with?))
(/.ends-with? top interval))
- (_.test "The boundary values border the interval."
+ (_.test (%.name (name-of /.borders?))
(and (/.borders? interval bottom)
(/.borders? interval top)))
)))
@@ -80,7 +96,7 @@
right-outer ..outer]
($_ _.and
(_.test "The union of an interval to itself yields the same interval."
- (,@= some-interval (/.union some-interval some-interval)))
+ (/@= some-interval (/.union some-interval some-interval)))
(_.test "The union of 2 inner intervals is another inner interval."
(/.inner? (/.union left-inner right-inner)))
(_.test "The union of 2 outer intervals yields an inner interval when their complements don't overlap, and an outer when they do."
@@ -101,7 +117,7 @@
right-outer ..outer]
($_ _.and
(_.test "The intersection of an interval to itself yields the same interval."
- (,@= some-interval (/.intersection some-interval some-interval)))
+ (/@= some-interval (/.intersection some-interval some-interval)))
(_.test "The intersection of 2 inner intervals yields an inner interval when they overlap, and an outer when they don't."
(if (/.overlaps? left-inner right-inner)
(/.inner? (/.intersection left-inner right-inner))
@@ -116,7 +132,7 @@
[some-interval ..interval]
($_ _.and
(_.test "The complement of a complement is the same as the original."
- (,@= some-interval (|> some-interval /.complement /.complement)))
+ (/@= some-interval (|> some-interval /.complement /.complement)))
(_.test "The complement of an interval does not overlap it."
(not (/.overlaps? some-interval (/.complement some-interval))))
)))
@@ -135,10 +151,10 @@
#let [left (/.singleton n.enum l)
right (/.singleton n.enum r)]]
($_ _.and
- (_.test "'precedes?' and 'succeeds?' are symetric."
+ (_.test (format (%.name (name-of /.precedes?)) " &&& " (%.name (name-of /.succeeds?)))
(and (/.precedes? right left)
(/.succeeds? left right)))
- (_.test "Can check if an interval is before or after some element."
+ (_.test (format (%.name (name-of /.before?)) " &&& " (%.name (name-of /.after?)))
(and (/.before? m left)
(/.after? m right)))
)))
@@ -157,14 +173,14 @@
#let [int-left (/.between n.enum t1 t2)
int-right (/.between n.enum b t1)]]
($_ _.and
- (_.test "An interval meets another if its top is the other's bottom."
+ (_.test (%.name (name-of /.meets?))
(/.meets? int-left int-right))
- (_.test "Two intervals touch one another if any one meets the other."
+ (_.test (%.name (name-of /.touches?))
(/.touches? int-left int-right))
- (_.test "Can check if 2 intervals start together."
+ (_.test (%.name (name-of /.starts?))
(/.starts? (/.between n.enum b t2)
(/.between n.enum b t1)))
- (_.test "Can check if 2 intervals finish together."
+ (_.test (%.name (name-of /.finishes?))
(/.finishes? (/.between n.enum b t2)
(/.between n.enum t1 t2)))
)))
@@ -220,13 +236,15 @@
(<| (_.context (%.name (name-of /.Interval)))
($_ _.and
($equivalence.spec /.equivalence ..interval)
+ (<| (_.context "Types.")
+ ..types)
(<| (_.context "Boundaries.")
..boundaries)
- (<| (_.context "Union.")
+ (<| (_.context (%.name (name-of /.union)))
..union)
- (<| (_.context "Intersection.")
+ (<| (_.context (%.name (name-of /.intersection)))
..intersection)
- (<| (_.context "Complement.")
+ (<| (_.context (%.name (name-of /.complement)))
..complement)
(<| (_.context "Positioning/location.")
..location)
@@ -236,14 +254,14 @@
..overlap)
)))
-(def: #export (spec (^open ",@.") gen-sample)
+(def: #export (spec (^open "/@.") gen-sample)
(All [a] (-> (Interval a) (Random a) Test))
(<| (_.context (%.name (name-of /.Interval)))
(do r.monad
[sample gen-sample]
($_ _.and
(_.test "No value is bigger than the top."
- (,@< ,@top sample))
+ (/@< /@top sample))
(_.test "No value is smaller than the bottom."
- (order.> ,@&order ,@bottom sample))
+ (order.> /@&order /@bottom sample))
))))