diff options
Diffstat (limited to 'stdlib/source/test')
-rw-r--r-- | stdlib/source/test/aedifex/artifact/time.lux | 9 | ||||
-rw-r--r-- | stdlib/source/test/aedifex/artifact/time/date.lux | 2 | ||||
-rw-r--r-- | stdlib/source/test/aedifex/artifact/time/time.lux | 10 | ||||
-rw-r--r-- | stdlib/source/test/lux.lux | 42 | ||||
-rw-r--r-- | stdlib/source/test/lux/ffi.js.lux | 20 | ||||
-rw-r--r-- | stdlib/source/test/lux/macro/poly/json.lux | 3 | ||||
-rw-r--r-- | stdlib/source/test/lux/type.lux | 4 | ||||
-rw-r--r-- | stdlib/source/test/lux/type/unit.lux | 194 |
8 files changed, 248 insertions, 36 deletions
diff --git a/stdlib/source/test/aedifex/artifact/time.lux b/stdlib/source/test/aedifex/artifact/time.lux index 4bf63018c..b14032a8c 100644 --- a/stdlib/source/test/aedifex/artifact/time.lux +++ b/stdlib/source/test/aedifex/artifact/time.lux @@ -11,7 +11,9 @@ [parser ["<.>" text]]] [math - ["." random (#+ Random)]] + ["." random (#+ Random)] + [number + ["i" int]]] [time ["." instant]]] {#program @@ -22,7 +24,10 @@ (def: #export random (Random /.Time) - random.instant) + (do random.monad + [date /date.random + time /time.random] + (wrap (instant.from_date_time date time)))) (def: #export test Test diff --git a/stdlib/source/test/aedifex/artifact/time/date.lux b/stdlib/source/test/aedifex/artifact/time/date.lux index 0f4b5b7d3..932d1698e 100644 --- a/stdlib/source/test/aedifex/artifact/time/date.lux +++ b/stdlib/source/test/aedifex/artifact/time/date.lux @@ -23,7 +23,7 @@ (random.one (function (_ raw) (try.to_maybe (do try.monad - [year (|> raw date.year year.value i.abs (i.% +10,000) year.year)] + [year (|> raw date.year year.value i.abs (i.% +9,000) (i.+ +1,000) year.year)] (date.date year (date.month raw) (date.day_of_month raw))))) diff --git a/stdlib/source/test/aedifex/artifact/time/time.lux b/stdlib/source/test/aedifex/artifact/time/time.lux index bd9bbe071..cd70d1c83 100644 --- a/stdlib/source/test/aedifex/artifact/time/time.lux +++ b/stdlib/source/test/aedifex/artifact/time/time.lux @@ -1,7 +1,7 @@ (.module: [lux #* ["_" test (#+ Test)] - ["." time (#+ Time)] + ["." time] [abstract [monad (#+ do)]] [control @@ -16,12 +16,18 @@ {#program ["." /]}) +(def: #export random + (Random /.Time) + (random.one (|>> time.clock (set@ #time.milli_second 0) time.time) + random.time)) + (def: #export test Test (<| (_.covering /._) + (_.for [/.Time]) ($_ _.and (do random.monad - [expected random.time] + [expected ..random] (_.cover [/.format /.parser] (|> expected /.format diff --git a/stdlib/source/test/lux.lux b/stdlib/source/test/lux.lux index 40a797177..d305c19c9 100644 --- a/stdlib/source/test/lux.lux +++ b/stdlib/source/test/lux.lux @@ -206,25 +206,25 @@ (def: sub_tests Test - (let [tail (: (List Test) - (for {@.old (list)} - (list /extension.test)))] - (_.in_parallel (list& /abstract.test - /control.test - /data.test - /locale.test - /macro.test - /math.test - /meta.test - /time.test - ## /tool.test - /type.test - /world.test - /ffi.test - (for {@.jvm (#.Cons /target/jvm.test tail) - @.old (#.Cons /target/jvm.test tail)} - tail) - )))) + (with_expansions [<target> (for {@.jvm (~~ (as_is /target/jvm.test)) + @.old (~~ (as_is /target/jvm.test))} + (~~ (as_is))) + <extension> (for {@.old (~~ (as_is))} + (~~ (as_is /extension.test)))] + (`` (_.in_parallel (list /abstract.test + /control.test + /data.test + /locale.test + /macro.test + /math.test + /meta.test + /time.test + ## /tool.test + /type.test + /world.test + /ffi.test + <target> + <extension>))))) (def: test Test @@ -248,12 +248,12 @@ ..templates) (<| (_.context "Cross-platform support.") ..cross_platform_support) - + ..sub_tests ))) (program: args (<| io _.run! - (_.times 100) + ((debug.private _.times') (#.Some 2,000) 100) ..test)) diff --git a/stdlib/source/test/lux/ffi.js.lux b/stdlib/source/test/lux/ffi.js.lux index 5ffe1fbeb..ded33ed08 100644 --- a/stdlib/source/test/lux/ffi.js.lux +++ b/stdlib/source/test/lux/ffi.js.lux @@ -19,22 +19,26 @@ ## On Nashorn (/.import: java/lang/String - (new [Uint8Array /.String]) - (getBytes [/.String] Uint8Array)) + ["#::." + (new [Uint8Array /.String]) + (getBytes [/.String] Uint8Array)]) ## On Node (/.import: Buffer - (#static from [/.String /.String] Buffer) - (toString [/.String] /.String)) + ["#::." + (#static from [/.String /.String] Buffer) + (toString [/.String] /.String)]) ## On the browser (/.import: TextEncoder - (new [/.String]) - (encode [/.String] Uint8Array)) + ["#::." + (new [/.String]) + (encode [/.String] Uint8Array)]) (/.import: TextDecoder - (new [/.String]) - (decode [Uint8Array] /.String)) + ["#::." + (new [/.String]) + (decode [Uint8Array] /.String)]) (def: #export test Test diff --git a/stdlib/source/test/lux/macro/poly/json.lux b/stdlib/source/test/lux/macro/poly/json.lux index f69af1397..0931481da 100644 --- a/stdlib/source/test/lux/macro/poly/json.lux +++ b/stdlib/source/test/lux/macro/poly/json.lux @@ -1,6 +1,7 @@ (.module: [lux #* ["_" test (#+ Test)] + ["." debug] [abstract codec [monad (#+ do)] @@ -85,7 +86,7 @@ (def: qty (All [unit] (Random (unit.Qty unit))) - (|> random.int (\ random.monad map unit.in))) + (\ random.monad map (debug.private unit.in) random.int)) (def: gen_record (Random Record) diff --git a/stdlib/source/test/lux/type.lux b/stdlib/source/test/lux/type.lux index b490469cf..654aeb748 100644 --- a/stdlib/source/test/lux/type.lux +++ b/stdlib/source/test/lux/type.lux @@ -23,7 +23,8 @@ ["#." implicit] ["#." quotient] ["#." refinement] - ["#." resource]]) + ["#." resource] + ["#." unit]]) (def: short (Random Text) @@ -176,4 +177,5 @@ /quotient.test /refinement.test /resource.test + /unit.test ))) diff --git a/stdlib/source/test/lux/type/unit.lux b/stdlib/source/test/lux/type/unit.lux new file mode 100644 index 000000000..291f6f6b2 --- /dev/null +++ b/stdlib/source/test/lux/type/unit.lux @@ -0,0 +1,194 @@ +(.module: + [lux #* + ["_" test (#+ Test)] + ["." debug] + ["." meta] + [abstract + [monad (#+ do)] + [equivalence (#+ Equivalence)] + {[0 #spec] + [/ + ["$." equivalence] + ["$." order] + ["$." enum]]}] + [macro + [syntax (#+ syntax:)] + ["." code]] + [math + ["." random (#+ Random)] + [number + ["i" int] + ["." ratio ("#\." equivalence)]]]] + {1 + ["." /]}) + +(template [<name> <type> <unit>] + [(def: (<name> range) + (-> Nat (Random (/.Qty <type>))) + (|> random.int + (\ random.monad map (i.% (.int range))) + (random.filter (|>> (i.= +0) not)) + (\ random.monad map (\ <unit> in))))] + + [meter /.Meter /.meter] + [second /.Second /.second] + ) + +(def: polymorphism + Test + ($_ _.and + (_.for [/.equivalence] + ($equivalence.spec /.equivalence (..meter 1,000))) + (_.for [/.order] + ($order.spec /.order (..meter 1,000))) + (_.for [/.enum] + ($enum.spec /.enum (..meter 1,000))) + )) + +(/.unit: What what) + +(def: unit + Test + (do random.monad + [expected random.int] + (_.for [/.Unit] + (`` ($_ _.and + (~~ (template [<type> <unit>] + [(_.cover [<type> <unit>] + (|> expected + (\ <unit> in) + (\ <unit> out) + (i.= expected)))] + + [/.Gram /.gram] + [/.Meter /.meter] + [/.Litre /.litre] + [/.Second /.second] + )) + (_.cover [/.Pure /.pure /.number] + (|> expected + /.pure + /.number + (i.= expected))) + (_.cover [/.unit:] + (|> expected + (\ ..what in) + (\ ..what out) + (i.= expected))) + ))))) + +(syntax: (natural) + (\ meta.monad map + (|>> code.nat list) + meta.count)) + +(with_expansions [<from> (..natural) + <to> (..natural)] + (/.scale: How how + [<from> <to>]) + + (def: how::from <from>) + (def: how::to <to>) + ) + +(def: scale + Test + (do {! random.monad} + [small (|> random.int + (\ ! map (i.% +1,000)) + (\ ! map (\ /.meter in))) + large (|> random.int + (\ ! map (i.% +1,000)) + (\ ! map (i.* +1,000,000,000)) + (\ ! map (\ /.meter in))) + #let [(^open "meter\.") (: (Equivalence (/.Qty /.Meter)) + /.equivalence)] + unscaled (|> random.int + (\ ! map (i.% +1,000)) + (\ ! map (i.* (.int how::to))) + (\ ! map (\ /.meter in)))] + (_.for [/.Scale] + (`` ($_ _.and + (~~ (template [<type> <scale>] + [(_.cover [<type> <scale>] + (|> large + (\ <scale> scale) + (: (/.Qty (<type> /.Meter))) + (\ <scale> de_scale) + (: (/.Qty /.Meter)) + (meter\= large)))] + + [/.Kilo /.kilo] + [/.Mega /.mega] + [/.Giga /.giga] + )) + (~~ (template [<type> <scale>] + [(_.cover [<type> <scale>] + (|> small + (\ <scale> scale) + (: (/.Qty (<type> /.Meter))) + (\ <scale> de_scale) + (: (/.Qty /.Meter)) + (meter\= small)))] + + [/.Milli /.milli] + [/.Micro /.micro] + [/.Nano /.nano] + )) + (_.cover [/.re_scale] + (|> large (: (/.Qty /.Meter)) + (\ /.kilo scale) (: (/.Qty (/.Kilo /.Meter))) + (/.re_scale /.kilo /.milli) (: (/.Qty (/.Milli /.Meter))) + (/.re_scale /.milli /.kilo) (: (/.Qty (/.Kilo /.Meter))) + (\ /.kilo de_scale) (: (/.Qty /.Meter)) + (meter\= large))) + (_.cover [/.scale:] + (and (|> unscaled + (\ ..how scale) + (\ ..how de_scale) + (meter\= unscaled)) + (ratio\= [..how::from + ..how::to] + (\ ..how ratio)))) + ))))) + +(def: arithmetic + Test + (do random.monad + [#let [zero (\ /.meter in +0) + (^open "meter\.") (: (Equivalence (/.Qty /.Meter)) + /.equivalence)] + left (random.filter (|>> (meter\= zero) not) (..meter 1,000)) + right (..meter 1,000) + extra (..second 1,000)] + (`` ($_ _.and + (~~ (template [<q> <i>] + [(_.cover [<q>] + (i.= (<i> (\ /.meter out left) (\ /.meter out right)) + (\ /.meter out (<q> left right))))] + + [/.+ i.+] + [/.- i.-] + )) + (_.cover [/.*] + (let [expected (i.* (\ /.meter out left) (\ /.meter out right)) + actual ((debug.private /.out) (: (/.Qty [/.Meter /.Meter]) + (/.* left right)))] + (i.= expected actual))) + (_.cover [/./] + (|> right + (/.* left) + (/./ left) + (meter\= right))) + )))) + +(def: #export test + Test + (<| (_.covering /._) + (_.for [/.Qty]) + ($_ _.and + ..polymorphism + ..unit + ..scale + ..arithmetic + ))) |