aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/test/aedifex/artifact/build.lux34
-rw-r--r--stdlib/source/test/lux/abstract.lux2
-rw-r--r--stdlib/source/test/lux/abstract/hash.lux39
-rw-r--r--stdlib/source/test/lux/data/collection/list.lux5
-rw-r--r--stdlib/source/test/lux/data/collection/set.lux5
-rw-r--r--stdlib/source/test/lux/data/collection/set/multi.lux8
-rw-r--r--stdlib/source/test/lux/data/maybe.lux5
-rw-r--r--stdlib/source/test/lux/data/name.lux5
-rw-r--r--stdlib/source/test/lux/data/text.lux4
-rw-r--r--stdlib/source/test/lux/locale.lux22
-rw-r--r--stdlib/source/test/lux/time/month.lux93
11 files changed, 199 insertions, 23 deletions
diff --git a/stdlib/source/test/aedifex/artifact/build.lux b/stdlib/source/test/aedifex/artifact/build.lux
new file mode 100644
index 000000000..d0920b44c
--- /dev/null
+++ b/stdlib/source/test/aedifex/artifact/build.lux
@@ -0,0 +1,34 @@
+(.module:
+ [lux #*
+ ["_" test (#+ Test)]
+ [abstract
+ [monad (#+ do)]
+ {[0 #spec]
+ [/
+ ["$." equivalence]]}]
+ [control
+ ["." try ("#\." functor)]
+ [parser
+ ["<.>" xml]]]
+ [math
+ ["." random]]]
+ {#program
+ ["." /]})
+
+(def: #export test
+ Test
+ (<| (_.covering /._)
+ (_.for [/.Build]
+ ($_ _.and
+ (_.for [/.equivalence]
+ ($equivalence.spec /.equivalence random.nat))
+
+ (do random.monad
+ [expected random.nat]
+ (_.cover [/.format /.parser]
+ (|> expected
+ /.format
+ (<xml>.run /.parser)
+ (try\map (\ /.equivalence = expected))
+ (try.default false))))
+ ))))
diff --git a/stdlib/source/test/lux/abstract.lux b/stdlib/source/test/lux/abstract.lux
index 9fd3986b8..b31c10617 100644
--- a/stdlib/source/test/lux/abstract.lux
+++ b/stdlib/source/test/lux/abstract.lux
@@ -8,6 +8,7 @@
["#/." cofree]]
["#." enum]
["#." equivalence]
+ ["#." hash]
["#." fold]
["#." functor
["#/." contravariant]]
@@ -46,6 +47,7 @@
/codec.test
/enum.test
/equivalence.test
+ /hash.test
/fold.test
/interval.test
/monoid.test
diff --git a/stdlib/source/test/lux/abstract/hash.lux b/stdlib/source/test/lux/abstract/hash.lux
new file mode 100644
index 000000000..c527fb9c9
--- /dev/null
+++ b/stdlib/source/test/lux/abstract/hash.lux
@@ -0,0 +1,39 @@
+(.module:
+ [lux #*
+ ["_" test (#+ Test)]
+ [abstract
+ [monad (#+ do)]
+ {[0 #spec]
+ [/
+ [functor
+ ["$." contravariant]]]}]
+ [data
+ ["." bit ("#\." equivalence)]]
+ [math
+ ["." random]
+ [number
+ ["." nat]]]]
+ {1
+ ["." / (#+ Hash)
+ [//
+ [equivalence (#+ Equivalence)]]]})
+
+(def: #export test
+ Test
+ (do random.monad
+ [leftN random.nat
+ rightN random.nat
+ #let [hash (: (Equivalence (/.Hash Nat))
+ (structure
+ (def: (= (^open "left\.") (^open "right\."))
+ (and (bit\= (left\= (left\hash leftN) (left\hash leftN))
+ (right\= (right\hash leftN) (right\hash leftN)))
+ (bit\= (left\= (left\hash rightN) (left\hash rightN))
+ (right\= (right\hash rightN) (right\hash rightN)))
+ (bit\= (left\= (left\hash leftN) (left\hash rightN))
+ (right\= (right\hash leftN) (right\hash rightN)))))))]]
+ (<| (_.covering /._)
+ ($_ _.and
+ (_.for [/.functor]
+ ($contravariant.spec hash nat.hash /.functor))
+ ))))
diff --git a/stdlib/source/test/lux/data/collection/list.lux b/stdlib/source/test/lux/data/collection/list.lux
index 6306f62fc..3efc42254 100644
--- a/stdlib/source/test/lux/data/collection/list.lux
+++ b/stdlib/source/test/lux/data/collection/list.lux
@@ -7,6 +7,7 @@
{[0 #spec]
[/
["$." equivalence]
+ ["$." hash]
["$." monoid]
["$." fold]
["$." functor]
@@ -49,6 +50,10 @@
($_ _.and
(_.for [/.equivalence]
($equivalence.spec (/.equivalence n.equivalence) ..random))
+ (_.for [/.hash]
+ (|> random.nat
+ (\ random.monad map (|>> list))
+ ($hash.spec (/.hash n.hash))))
(_.for [/.monoid]
($monoid.spec (/.equivalence n.equivalence) /.monoid ..random))
(_.for [/.fold]
diff --git a/stdlib/source/test/lux/data/collection/set.lux b/stdlib/source/test/lux/data/collection/set.lux
index 6f981af91..282749f5e 100644
--- a/stdlib/source/test/lux/data/collection/set.lux
+++ b/stdlib/source/test/lux/data/collection/set.lux
@@ -7,6 +7,7 @@
{[0 #spec]
[/
["$." equivalence]
+ ["$." hash]
["$." monoid]]}]
[data
["." bit ("#\." equivalence)]
@@ -33,6 +34,10 @@
($_ _.and
(_.for [/.equivalence]
($equivalence.spec /.equivalence (random.set n.hash size random.nat)))
+ (_.for [/.hash]
+ (|> random.nat
+ (\ random.monad map (|>> list (/.from_list n.hash)))
+ ($hash.spec /.hash)))
(_.for [/.monoid]
($monoid.spec /.equivalence (/.monoid n.hash) (random.set n.hash size random.nat)))
diff --git a/stdlib/source/test/lux/data/collection/set/multi.lux b/stdlib/source/test/lux/data/collection/set/multi.lux
index 9d9572795..718c971c3 100644
--- a/stdlib/source/test/lux/data/collection/set/multi.lux
+++ b/stdlib/source/test/lux/data/collection/set/multi.lux
@@ -7,7 +7,8 @@
["." predicate]
{[0 #spec]
[/
- ["$." equivalence]]}]
+ ["$." equivalence]
+ ["$." hash]]}]
[data
["." bit ("#\." equivalence)]
[collection
@@ -50,6 +51,11 @@
(`` ($_ _.and
(_.for [/.equivalence]
($equivalence.spec /.equivalence (..random diversity n.hash ..count random.nat)))
+ (_.for [/.hash]
+ (|> random.nat
+ (\ random.monad map (function (_ single)
+ (/.add 1 single (/.new n.hash))))
+ ($hash.spec /.hash)))
(_.cover [/.to_list /.from_list]
(|> sample
diff --git a/stdlib/source/test/lux/data/maybe.lux b/stdlib/source/test/lux/data/maybe.lux
index 64f9b5ff5..017d0799b 100644
--- a/stdlib/source/test/lux/data/maybe.lux
+++ b/stdlib/source/test/lux/data/maybe.lux
@@ -6,6 +6,7 @@
{[0 #spec]
[/
["$." equivalence]
+ ["$." hash]
["$." monoid]
["$." functor]
["$." apply]
@@ -31,6 +32,10 @@
($_ _.and
(_.for [/.equivalence]
($equivalence.spec (/.equivalence n.equivalence) (random.maybe random.nat)))
+ (_.for [/.hash]
+ (|> random.nat
+ (\ random.monad map (|>> #.Some))
+ ($hash.spec (/.hash n.hash))))
(_.for [/.monoid]
($monoid.spec (/.equivalence n.equivalence) /.monoid (random.maybe random.nat)))
(_.for [/.functor]
diff --git a/stdlib/source/test/lux/data/name.lux b/stdlib/source/test/lux/data/name.lux
index 7912994c3..f68a58d9a 100644
--- a/stdlib/source/test/lux/data/name.lux
+++ b/stdlib/source/test/lux/data/name.lux
@@ -6,6 +6,7 @@
{[0 #spec]
[/
["$." equivalence]
+ ["$." hash]
["$." order]
["$." codec]]}]
[control
@@ -45,6 +46,10 @@
($_ _.and
(_.for [/.equivalence]
($equivalence.spec /.equivalence (..random sizeM1 sizeS1)))
+ (_.for [/.hash]
+ (|> (random.ascii 2)
+ (\ ! map (|>> [""]))
+ ($hash.spec /.hash)))
(_.for [/.order]
($order.spec /.order (..random sizeM1 sizeS1)))
(_.for [/.codec]
diff --git a/stdlib/source/test/lux/data/text.lux b/stdlib/source/test/lux/data/text.lux
index a5d11685f..c89ca97ba 100644
--- a/stdlib/source/test/lux/data/text.lux
+++ b/stdlib/source/test/lux/data/text.lux
@@ -6,6 +6,7 @@
{[0 #spec]
[/
["$." equivalence]
+ ["$." hash]
["$." order]
["$." monoid]]}]
[control
@@ -238,6 +239,9 @@
($_ _.and
(_.for [/.equivalence]
($equivalence.spec /.equivalence (random.ascii 2)))
+ (_.for [/.hash]
+ (|> (random.ascii 2)
+ ($hash.spec /.hash)))
(_.for [/.order]
($order.spec /.order (random.ascii 2)))
(_.for [/.monoid]
diff --git a/stdlib/source/test/lux/locale.lux b/stdlib/source/test/lux/locale.lux
index 5693eb2c4..23cb63a97 100644
--- a/stdlib/source/test/lux/locale.lux
+++ b/stdlib/source/test/lux/locale.lux
@@ -5,7 +5,8 @@
[monad (#+ do)]
{[0 #spec]
[/
- ["$." equivalence]]}]
+ ["$." equivalence]
+ ["$." hash]]}]
[math
["." random (#+ Random) ("#\." monad)]]
[data
@@ -51,6 +52,25 @@
($_ _.and
(_.for [/.equivalence]
($equivalence.spec /.equivalence ..random_locale))
+ (_.for [/.hash]
+ (do {! random.monad}
+ [fixed_language ..random_language
+ fixed_territory ..random_territory
+ fixed_encoding ..random_encoding]
+ ($_ _.and
+ (|> ..random_language
+ (\ ! map (function (_ language)
+ (/.locale language (#.Some fixed_territory) (#.Some fixed_encoding))))
+ ($hash.spec /.hash))
+ (|> ..random_territory
+ (\ ! map (function (_ territory)
+ (/.locale fixed_language (#.Some territory) (#.Some fixed_encoding))))
+ ($hash.spec /.hash))
+ (|> ..random_encoding
+ (\ ! map (function (_ encoding)
+ (/.locale fixed_language (#.Some fixed_territory) (#.Some encoding))))
+ ($hash.spec /.hash))
+ )))
(do random.monad
[language ..random_language
diff --git a/stdlib/source/test/lux/time/month.lux b/stdlib/source/test/lux/time/month.lux
index d7078fa65..2cecfced6 100644
--- a/stdlib/source/test/lux/time/month.lux
+++ b/stdlib/source/test/lux/time/month.lux
@@ -1,38 +1,89 @@
(.module:
[lux #*
- ["%" data/text/format (#+ format)]
["_" test (#+ Test)]
[abstract
+ [monad (#+ do)]
+ ["." predicate]
{[0 #spec]
[/
["$." equivalence]
+ ["$." hash]
["$." order]
["$." enum]]}]
+ [control
+ ["." try ("#\." functor)]
+ ["." exception]]
+ [data
+ [collection
+ ["." set]
+ ["." list ("#\." functor fold)]]]
[math
- ["r" random (#+ Random) ("#\." monad)]]]
+ ["." random (#+ Random)]
+ [number
+ ["n" nat]]]]
{1
- ["." / (#+ Month)]})
+ ["." /
+ [//
+ ["." duration]]]})
-(def: #export month
- (Random Month)
- (r.either (r.either (r.either (r\wrap #/.January)
- (r.either (r\wrap #/.February)
- (r\wrap #/.March)))
- (r.either (r\wrap #/.April)
- (r.either (r\wrap #/.May)
- (r\wrap #/.June))))
- (r.either (r.either (r\wrap #/.July)
- (r.either (r\wrap #/.August)
- (r\wrap #/.September)))
- (r.either (r\wrap #/.October)
- (r.either (r\wrap #/.November)
- (r\wrap #/.December))))))
+(def: #export random
+ (Random /.Month)
+ (let [december (/.number #/.December)]
+ (|> random.nat
+ (\ random.monad map (|>> (n.% december) inc))
+ (random.one (|>> /.by_number try.to_maybe)))))
(def: #export test
Test
- (<| (_.context (%.name (name_of /._)))
+ (<| (_.covering /._)
+ (_.for [/.Month])
($_ _.and
- ($equivalence.spec /.equivalence ..month)
- ($order.spec /.order ..month)
- ($enum.spec /.enum ..month)
+ (_.for [/.equivalence]
+ ($equivalence.spec /.equivalence ..random))
+ (_.for [/.hash]
+ ($hash.spec /.hash ..random))
+ (_.for [/.order]
+ ($order.spec /.order ..random))
+ (_.for [/.enum]
+ ($enum.spec /.enum ..random))
+
+ (do random.monad
+ [expected ..random
+ invalid (random.filter (predicate.unite (n.< (/.number #/.January))
+ (n.> (/.number #/.December)))
+ random.nat)]
+ ($_ _.and
+ (_.cover [/.number /.by_number]
+ (|> expected
+ /.number
+ /.by_number
+ (try\map (\ /.equivalence = expected))
+ (try.default false)))
+ (_.cover [/.invalid_month]
+ (case (/.by_number invalid)
+ (#try.Failure error)
+ (exception.match? /.invalid_month error)
+
+ (#try.Success _)
+ false))
+ (_.cover [/.year]
+ (let [all (list.size /.year)
+ uniques (set.size (set.from_list /.hash /.year))]
+ (and (n.= (/.number #/.December)
+ all)
+ (n.= all
+ uniques))))
+ (_.cover [/.days]
+ (let [expected (.nat (duration.query duration.day duration.normal_year))]
+ (|> /.year
+ (list\map /.days)
+ (list\fold n.+ 0)
+ (n.= expected))))
+ (_.cover [/.leap_year_days]
+ (let [expected (.nat (duration.query duration.day duration.leap_year))]
+ (|> /.year
+ (list\map /.leap_year_days)
+ (list\fold n.+ 0)
+ (n.= expected))))
+ ))
)))