(.module: lux (lux [io #+ IO] (control [monad #+ do] pipe) (data ["e" error] [maybe] [bool "bool/" Eq] [text "text/" Eq] text/format (coll [array] [list "list/" Functor])) ["r" math/random "r/" Monad] [macro] (macro [code]) [host] test) (luxc [lang] (lang [".L" host] [synthesis #+ Synthesis])) (test/luxc common)) (host.import java/lang/Integer) (def: (tuples-spec run) (-> Runner Test) (do r.Monad [size (|> r.nat (:: @ map (|>> (n/% +10) (n/max +2)))) tuple-in (r.list size r.int)] (test "Can translate tuple." (|> (run (code.tuple (list/map code.int tuple-in))) (case> (#e.Success tuple-out) (let [tuple-out (:! (Array Any) tuple-out)] (and (n/= size (array.size tuple-out)) (list.every? (function (_ [left right]) (i/= left (:! Int right))) (list.zip2 tuple-in (array.to-list tuple-out))))) (#e.Error error) (exec (log! error) false)))))) (def: (variants-spec run) (-> Runner Test) (do r.Monad [num-tags (|> r.nat (:: @ map (|>> (n/% +10) (n/max +2)))) tag-in (|> r.nat (:: @ map (n/% num-tags))) #let [last?-in (n/= (n/dec num-tags) tag-in)] value-in r.int] (test "Can translate variant." (|> (run (` ((~ (code.nat tag-in)) (~ (code.bool last?-in)) (~ (code.int value-in))))) (case> (#e.Success valueT) (let [valueT (:! (Array Any) valueT)] (and (n/= +3 (array.size valueT)) (let [tag-out (:! Integer (maybe.assume (array.read +0 valueT))) last?-out (array.read +1 valueT) value-out (:! Any (maybe.assume (array.read +2 valueT))) same-tag? (n/= tag-in (|> tag-out host.int-to-long (:! Nat))) same-flag? (case last?-out (#.Some last?-out') (and last?-in (text/= "" (:! Text last?-out'))) #.None (not last?-in)) same-value? (i/= value-in (:! Int value-out))] (and same-tag? same-flag? same-value?)))) (#e.Error error) (exec (log! error) false)))))) (def: (structure-spec run) (-> Runner Test) ($_ seq (tuples-spec run) (variants-spec run))) (context: "[JVM] Structures." (<| (times +100) (structure-spec run-jvm))) ## (context: "[JS] Structures." ## (<| (times +100) ## (structure-spec run-js))) ## (context: "[Lua] Structures." ## (<| (times +100) ## (structure-spec run-lua))) ## (context: "[Ruby] Structures." ## (<| (times +100) ## (structure-spec run-ruby))) ## (context: "[Python] Structures." ## (<| (times +100) ## (structure-spec run-python))) ## (context: "[R] Structures." ## (<| (times +100) ## (structure-spec run-r))) ## (context: "[Scheme] Structures." ## (<| (times +100) ## (structure-spec run-scheme))) ## (context: "[Common Lisp] Structures." ## (<| (times +100) ## (structure-spec run-common-lisp))) ## (context: "[PHP] Structures." ## (<| (times +100) ## (structure-spec run-php)))