From 061fd8a209bbcaffc2bfb850ac6046752a567d50 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 27 Jul 2021 03:51:10 -0400 Subject: Re-named wrap => in && unwrap => out. --- stdlib/source/test/lux.lux | 65 +++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 29 deletions(-) (limited to 'stdlib/source/test/lux.lux') diff --git a/stdlib/source/test/lux.lux b/stdlib/source/test/lux.lux index cd77beb6f..de99ee775 100644 --- a/stdlib/source/test/lux.lux +++ b/stdlib/source/test/lux.lux @@ -58,25 +58,9 @@ (template: (!bundle body) (: Test (do random.monad - [_ (wrap [])] + [_ (in [])] body))) -(def: prelude_macros - Test - ($_ _.and - (do random.monad - [factor (random\map (|>> (n.% 10) (n.max 1)) random.nat) - iterations (random\map (n.% 10) random.nat) - #let [expected (n.* factor iterations)]] - (_.test "Can write loops." - (n.= expected - (loop [counter 0 - value 0] - (if (n.< iterations counter) - (recur (inc counter) (n.+ factor value)) - value))))) - )) - (def: sub_tests Test (with_expansions [## TODO: Update & expand tests for this @@ -421,7 +405,7 @@ )))) (/.macro: (identity_macro tokens) - (\ meta.monad wrap tokens)) + (\ meta.monad in tokens)) (def: for_macro Test @@ -621,8 +605,8 @@ (def: for_static Test (do random.monad - [sample (random.either (wrap option/0) - (wrap option/1))] + [sample (random.either (in option/0) + (in option/1))] ($_ _.and (_.cover [/.static] (case sample @@ -862,12 +846,12 @@ (do {! random.monad} [expected_nat (\ ! map (n.% 1) random.nat) expected_int (\ ! map (i.% +1) random.int) - expected_rev (random.either (wrap .5) - (wrap .25)) - expected_frac (random.either (wrap +0.5) - (wrap +1.25)) - expected_text (random.either (wrap "+0.5") - (wrap "+1.25"))] + expected_rev (random.either (in .5) + (in .25)) + expected_frac (random.either (in +0.5) + (in +1.25)) + expected_text (random.either (in "+0.5") + (in "+1.25"))] ($_ _.and (_.cover [/.case] (and (/.case expected_nat @@ -963,13 +947,35 @@ (/.is? expected_int actual_right))))) ))) +(def: for_control_flow + Test + ($_ _.and + (do random.monad + [factor (random\map (|>> (n.% 10) (n.max 1)) random.nat) + iterations (random\map (n.% 10) random.nat) + #let [expected (n.* factor iterations)]] + (_.cover [/.loop] + (n.= expected + (/.loop [counter 0 + value 0] + (if (n.< iterations counter) + (recur (inc counter) (n.+ factor value)) + value))))) + (do random.monad + [pre random.nat + post (random.only (|>> (n.= pre) not) random.nat) + #let [box (atom.atom pre)]] + (_.cover [/.exec] + (and (is? pre (io.run (atom.read box))) + (/.exec + (io.run (atom.write post box)) + (is? post (io.run (atom.read box))))))) + )) + (def: test Test (<| (_.covering /._) ($_ _.and - (<| (_.context "Prelude macros.") - ..prelude_macros) - ..for_bit ..for_try ..for_list @@ -988,6 +994,7 @@ ..for_expansion ..for_value ..for_case + ..for_control_flow ..sub_tests ))) -- cgit v1.2.3