aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux
diff options
context:
space:
mode:
authorEduardo Julian2021-12-25 22:05:54 -0400
committerEduardo Julian2021-12-25 22:05:54 -0400
commit00d92539208da86557e592a8c8df03d3b08e6b40 (patch)
treea71cc9e5f41c230f07956301263a710689e9dc85 /stdlib/source/test/lux
parent63b45e09c5f5ceb59a48ed05cdc2d2c6cb038a7b (diff)
Dusting off the pure-Lux JVM compiler machinery. [Part 2]
Diffstat (limited to 'stdlib/source/test/lux')
-rw-r--r--stdlib/source/test/lux/data/collection/array.lux71
-rw-r--r--stdlib/source/test/lux/tool.lux21
-rw-r--r--stdlib/source/test/lux/tool/compiler/arity.lux29
3 files changed, 87 insertions, 34 deletions
diff --git a/stdlib/source/test/lux/data/collection/array.lux b/stdlib/source/test/lux/data/collection/array.lux
index d9e3f01c2..2eca1688b 100644
--- a/stdlib/source/test/lux/data/collection/array.lux
+++ b/stdlib/source/test/lux/data/collection/array.lux
@@ -1,27 +1,28 @@
(.using
- [library
- [lux "*"
- ["_" test {"+" Test}]
- [abstract
- [monad {"+" do}]
- [\\specification
- ["$[0]" equivalence]
- ["$[0]" monoid]
- ["$[0]" mix]
- ["$[0]" functor {"+" Injection}]]]
- [control
- ["[0]" maybe]]
- [data
- ["[0]" bit]
- [collection
- ["[0]" list]
- ["[0]" set]]]
- [math
- ["[0]" random {"+" Random}]
- [number
- ["n" nat]]]]]
- [\\library
- ["[0]" / {"+" Array}]])
+ [library
+ [lux "*"
+ ["_" test {"+" Test}]
+ [abstract
+ [monad {"+" do}]
+ [\\specification
+ ["$[0]" equivalence]
+ ["$[0]" monoid]
+ ["$[0]" mix]
+ ["$[0]" functor {"+" Injection}]]]
+ [control
+ ["[0]" maybe]]
+ [data
+ ["[0]" bit]
+ ["[0]" text ("[1]#[0]" equivalence)]
+ [collection
+ ["[0]" list]
+ ["[0]" set]]]
+ [math
+ ["[0]" random {"+" Random}]
+ [number
+ ["n" nat]]]]]
+ [\\library
+ ["[0]" / {"+" Array}]])
(def: injection
(Injection Array)
@@ -29,7 +30,7 @@
(def: bounded_size
(Random Nat)
- (# random.monad each (|>> (n.% 100) (n.+ 1))
+ (# random.monad each (|>> (n.% 20) ++)
random.nat))
(def: structures
@@ -54,8 +55,28 @@
base random.nat
shift random.nat
.let [expected (n.+ base shift)]
- the_array (random.array size random.nat)]
+ the_array (random.array size random.nat)
+ evens (random.array size (random.only n.even? random.nat))]
($_ _.and
+ (let [(^open "/#[0]") /.functor
+ choose (: (-> Nat (Maybe Text))
+ (function (_ value)
+ (if (n.even? value)
+ {.#Some (# n.decimal encoded value)}
+ {.#None})))]
+ (_.cover [/.one]
+ (case [(|> evens
+ (/#each (# n.decimal encoded))
+ (/.read! 0))
+ (/.one choose evens)]
+ [{.#Some expected} {.#Some actual}]
+ (text#= expected actual)
+
+ [{.#None} {.#None}]
+ true
+
+ _
+ false)))
(_.cover [/.example]
(# (maybe.equivalence n.equivalence) =
(/.example n.even? the_array)
diff --git a/stdlib/source/test/lux/tool.lux b/stdlib/source/test/lux/tool.lux
index 3a9f547cd..5a7509b99 100644
--- a/stdlib/source/test/lux/tool.lux
+++ b/stdlib/source/test/lux/tool.lux
@@ -4,17 +4,20 @@
["_" test {"+" Test}]]]
["[0]" / "_"
[compiler
- [language
- [lux
- ["[1][0]" syntax]
- [phase
- ["[1][0]" analysis]
- ["[1][0]" synthesis]]]]]])
+ ["[1][0]" arity]
+ ... [language
+ ... [lux
+ ... ["[1][0]" syntax]
+ ... [phase
+ ... ["[1][0]" analysis]
+ ... ["[1][0]" synthesis]]]]
+ ]])
(def: .public test
Test
($_ _.and
- /syntax.test
- /analysis.test
- /synthesis.test
+ /arity.test
+ ... /syntax.test
+ ... /analysis.test
+ ... /synthesis.test
))
diff --git a/stdlib/source/test/lux/tool/compiler/arity.lux b/stdlib/source/test/lux/tool/compiler/arity.lux
new file mode 100644
index 000000000..0e9f3f25d
--- /dev/null
+++ b/stdlib/source/test/lux/tool/compiler/arity.lux
@@ -0,0 +1,29 @@
+(.using
+ [library
+ [lux "*"
+ ["_" test {"+" Test}]
+ [abstract
+ [monad {"+" do}]]
+ [data
+ ["[0]" bit ("[1]#[0]" equivalence)]]
+ [math
+ ["[0]" random {"+" Random}]
+ [number
+ ["n" nat]]]]]
+ [\\library
+ ["[0]" /]])
+
+(def: .public test
+ Test
+ (<| (_.covering /._)
+ (_.for [/.Arity])
+ (do [! random.monad]
+ [arity (# ! each (n.% 3) random.nat)]
+ ($_ _.and
+ (_.cover [/.nullary?]
+ (bit#= (n.= 0 arity) (/.nullary? arity)))
+ (_.cover [/.unary?]
+ (bit#= (n.= 1 arity) (/.unary? arity)))
+ (_.cover [/.multiary?]
+ (bit#= (n.>= 2 arity) (/.multiary? arity)))
+ ))))