aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test
diff options
context:
space:
mode:
authorEduardo Julian2022-03-05 04:30:09 -0400
committerEduardo Julian2022-03-05 04:30:09 -0400
commita7fc50b1906fa97fb56d5ebe3d3fff7baee276da (patch)
treec62e695c6dc264533abe4003a6338d4a39e958c0 /stdlib/source/test
parentab9dc5fd656ef42dbb0192f96d34e1c7b451a430 (diff)
Optimizations for the pure-Lux JVM compiler. [Part 5]
Diffstat (limited to 'stdlib/source/test')
-rw-r--r--stdlib/source/test/lux/control/parser/synthesis.lux78
-rw-r--r--stdlib/source/test/lux/data/binary.lux5
-rw-r--r--stdlib/source/test/lux/data/collection/array.lux198
-rw-r--r--stdlib/source/test/lux/target/python.lux56
4 files changed, 290 insertions, 47 deletions
diff --git a/stdlib/source/test/lux/control/parser/synthesis.lux b/stdlib/source/test/lux/control/parser/synthesis.lux
index 7ee6a59e6..0a2f2fbeb 100644
--- a/stdlib/source/test/lux/control/parser/synthesis.lux
+++ b/stdlib/source/test/lux/control/parser/synthesis.lux
@@ -1,37 +1,37 @@
(.using
- [library
- [lux "*"
- ["_" test {"+" Test}]
- [abstract
- ["[0]" monad {"+" do}]]
- [control
- [pipe {"+" case>}]
- ["<>" parser]
- ["[0]" try]
- ["[0]" exception]]
- [data
- ["[0]" bit]
- ["[0]" text]
- [collection
- ["[0]" list ("[1]#[0]" functor)]]]
- [math
- ["[0]" random {"+" Random}]
- [number
- ["n" nat]
- ["[0]" i64]
- ["[0]" frac]]]
- [meta
- ["[0]" symbol]]
- [tool
- [compiler
- [reference {"+" }
- ["[0]" variable {"+" Variable}]]
- [language
- [lux
- [analysis {"+" Environment}]
- ["[0]" synthesis {"+" Synthesis}]]]]]]]
- [\\library
- ["[0]" /]])
+ [library
+ [lux "*"
+ ["_" test {"+" Test}]
+ [abstract
+ ["[0]" monad {"+" do}]]
+ [control
+ [pipe {"+" case>}]
+ ["<>" parser]
+ ["[0]" try]
+ ["[0]" exception]]
+ [data
+ ["[0]" bit]
+ ["[0]" text]
+ [collection
+ ["[0]" list ("[1]#[0]" functor)]]]
+ [math
+ ["[0]" random {"+" Random}]
+ [number
+ ["n" nat]
+ ["[0]" i64]
+ ["[0]" frac]]]
+ [meta
+ ["[0]" symbol]]
+ [tool
+ [compiler
+ [reference {"+" }
+ ["[0]" variable {"+" Variable}]]
+ [language
+ [lux
+ [analysis {"+" Environment}]
+ ["[0]" synthesis {"+" Synthesis}]]]]]]]
+ [\\library
+ ["[0]" /]])
(template: (!expect <pattern> <value>)
[(case <value>
@@ -80,7 +80,7 @@
))]
[/.bit /.bit! random.bit synthesis.bit bit.equivalence]
- [/.i64 /.i64! (# ! each .i64 random.nat) synthesis.i64 i64.equivalence]
+ [/.i64 /.i64! random.i64 synthesis.i64 i64.equivalence]
[/.f64 /.f64! random.safe_frac synthesis.f64 frac.equivalence]
[/.text /.text! (random.unicode 1) synthesis.text text.equivalence]
[/.local /.local! random.nat synthesis.variable/local n.equivalence]
@@ -94,7 +94,7 @@
($_ _.and
(do [! random.monad]
[expected_bit random.bit
- expected_i64 (# ! each .i64 random.nat)
+ expected_i64 random.i64
expected_f64 random.safe_frac
expected_text (random.unicode 1)]
(_.cover [/.tuple]
@@ -165,7 +165,7 @@
(_.for [/.Parser])
($_ _.and
(do [! random.monad]
- [expected (# ! each (|>> synthesis.i64) random.nat)]
+ [expected (# ! each (|>> synthesis.i64) random.i64)]
(_.cover [/.result /.any]
(|> (/.result /.any (list expected))
(!expect (^multi {try.#Success actual}
@@ -175,13 +175,13 @@
(!expect (^multi {try.#Failure error}
(exception.match? /.empty_input error)))))
(do [! random.monad]
- [expected (# ! each (|>> synthesis.i64) random.nat)]
+ [expected (# ! each (|>> synthesis.i64) random.i64)]
(_.cover [/.unconsumed_input]
(|> (/.result /.any (list expected expected))
(!expect (^multi {try.#Failure error}
(exception.match? /.unconsumed_input error))))))
(do [! random.monad]
- [dummy (# ! each (|>> synthesis.i64) random.nat)]
+ [dummy (# ! each (|>> synthesis.i64) random.i64)]
(_.cover [/.end! /.expected_empty_input]
(and (|> (/.result /.end! (list))
(!expect {try.#Success _}))
@@ -189,7 +189,7 @@
(!expect (^multi {try.#Failure error}
(exception.match? /.expected_empty_input error)))))))
(do [! random.monad]
- [dummy (# ! each (|>> synthesis.i64) random.nat)]
+ [dummy (# ! each (|>> synthesis.i64) random.i64)]
(_.cover [/.end?]
(and (|> (/.result /.end? (list))
(!expect {try.#Success #1}))
diff --git a/stdlib/source/test/lux/data/binary.lux b/stdlib/source/test/lux/data/binary.lux
index e2072944f..d179058fd 100644
--- a/stdlib/source/test/lux/data/binary.lux
+++ b/stdlib/source/test/lux/data/binary.lux
@@ -14,8 +14,9 @@
["[0]" exception {"+" Exception}]]
[data
[collection
- [array {"+"}]
- ["[0]" list ("[1]#[0]" functor)]]]
+ ["[0]" list ("[1]#[0]" functor)]
+ [array
+ [\\unsafe {"+"}]]]]
[math
["[0]" random {"+" Random}]
[number
diff --git a/stdlib/source/test/lux/data/collection/array.lux b/stdlib/source/test/lux/data/collection/array.lux
index 2eca1688b..b0daba12a 100644
--- a/stdlib/source/test/lux/data/collection/array.lux
+++ b/stdlib/source/test/lux/data/collection/array.lux
@@ -3,14 +3,17 @@
[lux "*"
["_" test {"+" Test}]
[abstract
+ [functor {"+"}]
[monad {"+" do}]
+ ["[0]" monoid
+ ["$[1]" \\specification]]
+ ["[0]" mix {"+" Mix}
+ ["$[1]" \\specification]]
[\\specification
["$[0]" equivalence]
- ["$[0]" monoid]
- ["$[0]" mix]
["$[0]" functor {"+" Injection}]]]
[control
- ["[0]" maybe]]
+ ["[0]" maybe ("[1]#[0]" functor)]]
[data
["[0]" bit]
["[0]" text ("[1]#[0]" equivalence)]
@@ -22,7 +25,8 @@
[number
["n" nat]]]]]
[\\library
- ["[0]" / {"+" Array}]])
+ ["[0]" / {"+" Array}
+ ["!" \\unsafe]]])
(def: injection
(Injection Array)
@@ -110,6 +114,184 @@
(/.any? n.even? the_array)))
)))
+(def: test|unsafe
+ Test
+ (<| (_.covering !._)
+ (_.for [!.Array])
+ (do [! random.monad]
+ [size ..bounded_size
+ base random.nat
+ shift random.nat
+ dummy (random.only (|>> (n.= base) not) random.nat)
+ .let [expected (n.+ base shift)]
+ the_array (random.array size random.nat)
+ evens (random.array size (random.only n.even? random.nat))]
+ (`` ($_ _.and
+ (_.for [!.=]
+ ($equivalence.spec (function (_ left right)
+ (!.= n.equivalence left right))
+ (random.array size random.nat)))
+ (_.for [!.composite]
+ ($monoid.spec (/.equivalence n.equivalence)
+ (implementation
+ (def: identity (!.empty 0))
+ (def: (composite left right)
+ (!.composite left right)))
+ (random.array size random.nat)))
+ (_.for [!.each]
+ ($functor.spec ..injection /.equivalence
+ (function (_ $ it)
+ (!.each $ it))))
+ (_.for [!.mix]
+ ($mix.spec ..injection /.equivalence
+ (: (Mix !.Array)
+ (function (_ $ init it)
+ (!.mix (function (_ index item output)
+ ($ item output))
+ init
+ it)))))
+
+ (_.cover [!.empty !.size]
+ (n.= size (!.size (: (Array Nat)
+ (!.empty size)))))
+ (_.cover [!.type]
+ (case !.Array
+ (^ (<| {.#Named (symbol !.Array)}
+ {.#UnivQ (list)}
+ {.#Primitive nominal_type (list {.#Parameter 1})}))
+ (same? !.type nominal_type)
+
+ _
+ false))
+ (_.cover [!.lacks?]
+ (let [the_array (|> (!.empty 2)
+ (: (Array Nat))
+ (!.has! 0 expected))]
+ (and (not (!.lacks? 0 the_array))
+ (!.lacks? 1 the_array))))
+ (_.cover [!.item !.has!]
+ (|> (!.empty 2)
+ (: (Array Nat))
+ (!.has! 0 expected)
+ (!.item 0)
+ (n.= expected)))
+ (_.cover [!.lacks!]
+ (|> (!.empty 1)
+ (: (Array Nat))
+ (!.has! 0 expected)
+ (!.lacks! 0)
+ (!.lacks? 0)))
+ (_.cover [!.revised!]
+ (|> (!.empty 1)
+ (: (Array Nat))
+ (!.has! 0 base)
+ (!.revised! 0 (n.+ shift))
+ (!.item 0)
+ (n.= expected)))
+ (_.cover [!.upsert!]
+ (let [the_array (|> (!.empty 2)
+ (: (Array Nat))
+ (!.has! 0 base)
+ (!.upsert! 0 dummy (n.+ shift))
+ (!.upsert! 1 base (n.+ shift)))]
+ (and (n.= expected (!.item 0 the_array))
+ (n.= expected (!.item 1 the_array)))))
+ (do !
+ [occupancy (# ! each (n.% (++ size)) random.nat)]
+ (_.cover [!.occupancy !.vacancy]
+ (let [the_array (loop [output (: (Array Nat)
+ (!.empty size))
+ idx 0]
+ (if (n.< occupancy idx)
+ (again (!.has! idx expected output)
+ (++ idx))
+ output))]
+ (and (n.= occupancy (!.occupancy the_array))
+ (n.= size (n.+ (!.occupancy the_array)
+ (!.vacancy the_array)))))))
+ (do !
+ [the_list (random.list size random.nat)
+ .let [the_array (!.clone the_array)
+ members (|> the_array (!.list {.#None}) (set.of_list n.hash))]
+ default (random.only (function (_ value)
+ (not (or (n.even? value)
+ (set.member? members value))))
+ random.nat)]
+ (_.cover [!.of_list !.list]
+ (and (|> the_list !.of_list (!.list {.#None})
+ (# (list.equivalence n.equivalence) = the_list))
+ (|> the_array (!.list {.#None}) !.of_list
+ (!.= n.equivalence the_array))
+ (exec
+ (!.only! n.even? the_array)
+ (list.every? (function (_ value)
+ (or (n.even? value)
+ (same? default value)))
+ (!.list {.#Some default} the_array))))))
+ (do !
+ [amount (# ! each (n.% (++ size)) random.nat)]
+ (_.cover [!.copy!]
+ (let [copy (: (Array Nat)
+ (!.empty size))]
+ (exec (!.copy! amount 0 the_array 0 copy)
+ (# (list.equivalence n.equivalence) =
+ (list.first amount (!.list {.#None} the_array))
+ (!.list {.#None} copy))))))
+ (_.cover [!.clone]
+ (let [clone (!.clone the_array)]
+ (and (not (same? the_array clone))
+ (!.= n.equivalence the_array clone))))
+ (let [the_array (!.clone the_array)
+ evens (|> the_array (!.list {.#None}) (list.only n.even?))
+ odds (|> the_array (!.list {.#None}) (list.only n.odd?))]
+ (_.cover [!.only!]
+ (exec (!.only! n.even? the_array)
+ (and (n.= (list.size evens) (!.occupancy the_array))
+ (n.= (list.size odds) (!.vacancy the_array))
+ (|> the_array
+ (!.list {.#None})
+ (# (list.equivalence n.equivalence) = evens))))))
+ (let [choose (: (-> Nat (Maybe Text))
+ (function (_ value)
+ (if (n.even? value)
+ {.#Some (# n.decimal encoded value)}
+ {.#None})))]
+ (_.cover [!.one]
+ (|> evens
+ (!.one choose)
+ (maybe#each (text#= (|> evens
+ (!.each (# n.decimal encoded))
+ (!.item 0))))
+ (maybe.else false))))
+ (_.cover [!.example]
+ (# (maybe.equivalence n.equivalence) =
+ (!.example n.even? the_array)
+ (list.example n.even? (!.list {.#None} the_array))))
+ (_.cover [!.example']
+ (case [(!.example n.even? the_array)
+ (!.example' (function (_ idx member)
+ (n.even? member))
+ the_array)]
+ [{.#Some expected} {.#Some [idx actual]}]
+ (and (not (!.lacks? idx the_array))
+ (n.= expected actual)
+ (n.= actual (!.item idx the_array)))
+
+ [{.#None} {.#None}]
+ true
+
+ _
+ false))
+ (_.cover [!.every?]
+ (# bit.equivalence =
+ (list.every? n.even? (!.list {.#None} the_array))
+ (!.every? n.even? the_array)))
+ (_.cover [!.any?]
+ (# bit.equivalence =
+ (list.any? n.even? (!.list {.#None} the_array))
+ (!.any? n.even? the_array)))
+ )))))
+
(def: .public test
Test
(<| (_.covering /._)
@@ -130,7 +312,10 @@
(/.empty size)))))
(_.cover [/.type_name]
(case /.Array
- (^ {.#Named _ {.#UnivQ _ {.#Primitive nominal_type (list {.#Parameter 1})}}})
+ (^ (<| {.#Named (symbol /.Array)}
+ {.#Named (symbol !.Array)}
+ {.#UnivQ (list)}
+ {.#Primitive nominal_type (list {.#Parameter 1})}))
(same? /.type_name nominal_type)
_
@@ -163,7 +348,6 @@
(/.write! 0 expected))]
(and (/.contains? 0 the_array)
(not (/.contains? 1 the_array)))))
-
(_.cover [/.update!]
(let [the_array (|> (/.empty 1)
(: (Array Nat))
@@ -242,4 +426,6 @@
(and (n.= (list.size evens) (/.occupancy the_array))
(n.= (list.size odds) (/.vacancy the_array))
(|> the_array (/.list {.#None}) (# (list.equivalence n.equivalence) = evens))))))
+
+ ..test|unsafe
))))
diff --git a/stdlib/source/test/lux/target/python.lux b/stdlib/source/test/lux/target/python.lux
index 8ff0e74a2..b09be8b72 100644
--- a/stdlib/source/test/lux/target/python.lux
+++ b/stdlib/source/test/lux/target/python.lux
@@ -459,6 +459,7 @@
(do [! random.monad]
[$var/0 (# ! each (|>> %.nat (format "v0_") /.var) random.nat)
$var/1 (# ! each (|>> %.nat (format "v1_") /.var) random.nat)
+ $def (# ! each (|>> %.nat (format "def_") /.var) random.nat)
expected/0 random.safe_frac
expected/1 random.safe_frac
dummy/0 random.safe_frac
@@ -529,6 +530,37 @@
(:as Bit)
not)
))
+ (_.cover [/.globals/0]
+ (|> (..statement
+ (function (_ $output)
+ ($_ /.then
+ (/.def $def (list $var/0)
+ (/.return (/.in? /.globals/0 (/.string (/.code $var/0)))))
+ (/.set (list $output) (/.and (/.not (/.in? /.globals/0 (/.string (/.code $var/0))))
+ (/.not (/.apply/* (list (/.float dummy/0)) $def))))
+ (/.set (list $var/0) (/.float dummy/0))
+ (/.set (list $output) (/.and $output
+ (/.in? /.globals/0 (/.string (/.code $var/0))))))))
+ (:as Bit)))
+ (_.cover [/.locals/0]
+ (|> (..statement
+ (function (_ $output)
+ ($_ /.then
+ (/.def $def (list $var/0)
+ (/.return (/.in? /.locals/0 (/.string (/.code $var/0)))))
+ (/.set (list $output) (/.and (/.not (/.in? /.locals/0 (/.string (/.code $var/0))))
+ (/.apply/* (list (/.float dummy/0)) $def)))
+ (/.set (list $var/0) (/.float dummy/0))
+ (/.set (list $output) (/.and $output
+ (/.in? /.locals/0 (/.string (/.code $var/0))))))))
+ (:as Bit)))
+ (_.cover [/.import]
+ (|> (..statement
+ (function (_ $output)
+ ($_ /.then
+ (/.import "math")
+ (/.set (list $output) (/.in? /.globals/0 (/.string "math"))))))
+ (:as Bit)))
(_.for [/.Access]
..test|access)
)))
@@ -665,6 +697,23 @@
{.#None}))))
(:as Nat)
(n.= expected)))
+ (_.cover [/.break]
+ (|> (..statement
+ (function (_ $output)
+ ($_ /.then
+ (/.set (list $output) (/.int +0))
+ (/.set (list $iteration) (/.int +0))
+ (/.while (/.< (/.int (.int (n.+ extra factor))) $iteration)
+ ($_ /.then
+ (/.set (list $iteration) (/.+ (/.int +1)
+ $iteration))
+ (/.if (/.> (/.int (.int factor)) $iteration)
+ /.break
+ (/.set (list $output) (/.+ (/.int (.int base))
+ $output))))
+ {.#None}))))
+ (:as Nat)
+ (n.= expected)))
)))
(def: test|statement
@@ -721,6 +770,13 @@
(/.set (list $output) (/.apply/* (list) $def)))))
(:as Frac)
(f.= expected/0)))
+ (_.cover [/.exec]
+ (|> (..statement
+ (function (_ $output)
+ (/.exec {.#Some /.globals/0}
+ (/.string (/.code (/.set (list $output) (/.float expected/0)))))))
+ (:as Frac)
+ (f.= expected/0)))
..test|exception
(_.for [/.Location]
..test|location)