From cb792cb800790e89b371832e46cfe958b7c683d0 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 10 Apr 2017 23:38:07 -0400 Subject: - Move the modules under lux/function/* to be under lux/control/*. --- stdlib/test/test/lux/control/cont.lux | 75 +++++++++++++++++++++++++++++++ stdlib/test/test/lux/control/reader.lux | 37 +++++++++++++++ stdlib/test/test/lux/control/state.lux | 49 ++++++++++++++++++++ stdlib/test/test/lux/control/thunk.lux | 23 ++++++++++ stdlib/test/test/lux/data/coll/stream.lux | 4 +- stdlib/test/test/lux/function/cont.lux | 75 ------------------------------- stdlib/test/test/lux/function/reader.lux | 37 --------------- stdlib/test/test/lux/function/state.lux | 49 -------------------- stdlib/test/test/lux/function/thunk.lux | 23 ---------- stdlib/test/tests.lux | 10 ++--- 10 files changed, 191 insertions(+), 191 deletions(-) create mode 100644 stdlib/test/test/lux/control/cont.lux create mode 100644 stdlib/test/test/lux/control/reader.lux create mode 100644 stdlib/test/test/lux/control/state.lux create mode 100644 stdlib/test/test/lux/control/thunk.lux delete mode 100644 stdlib/test/test/lux/function/cont.lux delete mode 100644 stdlib/test/test/lux/function/reader.lux delete mode 100644 stdlib/test/test/lux/function/state.lux delete mode 100644 stdlib/test/test/lux/function/thunk.lux (limited to 'stdlib/test') diff --git a/stdlib/test/test/lux/control/cont.lux b/stdlib/test/test/lux/control/cont.lux new file mode 100644 index 000000000..133629e45 --- /dev/null +++ b/stdlib/test/test/lux/control/cont.lux @@ -0,0 +1,75 @@ +(;module: + lux + (lux [io] + (control monad + ["&" cont]) + (data [text "Text/" Monoid] + text/format + [number] + [product] + (coll [list])) + ["R" math/random]) + lux/test) + +(test: "Continuations" + [sample R;nat + #let [(^open "&/") &;Monad] + elems (R;list +3 R;nat)] + ($_ seq + (assert "Can run continuations to compute their values." + (n.= sample (&;run (&/wrap sample)))) + + (assert "Can use functor." + (n.= (n.inc sample) (&;run (&/map n.inc (&/wrap sample))))) + + (assert "Can use applicative." + (n.= (n.inc sample) (&;run (&/apply (&/wrap n.inc) (&/wrap sample))))) + + (assert "Can use monad." + (n.= (n.inc sample) (&;run (do &;Monad + [func (wrap n.inc) + arg (wrap sample)] + (wrap (func arg)))))) + + (assert "Can use the current-continuation as a escape hatch." + (n.= (n.* +2 sample) + (&;run (do &;Monad + [value (&;call/cc + (function [k] + (do @ + [temp (k sample)] + ## If this code where to run, + ## the output would be + ## (n.* +4 sample) + (k temp))))] + (wrap (n.* +2 value)))))) + + (assert "Can use the current-continuation to build a time machine." + (n.= (n.+ +100 sample) + (&;run (do &;Monad + [[restart [output idx]] (&;portal [sample +0])] + (if (n.< +10 idx) + (restart [(n.+ +10 output) (n.inc idx)]) + (wrap output)))))) + + (assert "Can use delimited continuations with shifting." + (let [(^open "&/") &;Monad + (^open "L/") (list;Eq number;Eq) + visit (: (-> (List Nat) + (&;Cont (List Nat) (List Nat))) + (function visit [xs] + (case xs + #;Nil + (&/wrap #;Nil) + + (#;Cons x xs') + (do &;Monad + [output (&;shift (function [k] + (do @ + [tail (k xs')] + (wrap (#;Cons x tail)))))] + (visit output)))))] + (L/= elems + (&;run (&;reset (visit elems)))) + )) + )) diff --git a/stdlib/test/test/lux/control/reader.lux b/stdlib/test/test/lux/control/reader.lux new file mode 100644 index 000000000..85b5edf8b --- /dev/null +++ b/stdlib/test/test/lux/control/reader.lux @@ -0,0 +1,37 @@ +(;module: + lux + (lux [io] + (control monad + pipe + ["&" reader]) + (data [text "Text/" Monoid] + text/format + [number])) + lux/test) + +(test: "Readers" + ($_ seq + (assert "" (i.= 123 (&;run 123 &;ask))) + (assert "" (i.= 246 (&;run 123 (&;local (i.* 2) &;ask)))) + (assert "" (i.= 134 (&;run 123 (:: &;Functor map i.inc (i.+ 10))))) + (assert "" (i.= 10 (&;run 123 (:: &;Applicative wrap 10)))) + (assert "" (i.= 30 (&;run 123 (let [(^open "&/") &;Applicative] + (&/apply (&/wrap (i.+ 10)) (&/wrap 20)))))) + (assert "" (i.= 30 (&;run 123 (do &;Monad + [f (wrap i.+) + x (wrap 10) + y (wrap 20)] + (wrap (f x y)))))))) + +(test: "Monad transformer" + (let [(^open "io/") io;Monad] + (assert "Can add reader functionality to any monad." + (|> (do (&;ReaderT io;Monad) + [a (&;lift-reader (io/wrap 123)) + b (wrap 456)] + (wrap (i.+ a b))) + (&;run "") + io;run + (case> 579 true + _ false))) + )) diff --git a/stdlib/test/test/lux/control/state.lux b/stdlib/test/test/lux/control/state.lux new file mode 100644 index 000000000..e02dfdf55 --- /dev/null +++ b/stdlib/test/test/lux/control/state.lux @@ -0,0 +1,49 @@ +(;module: + lux + (lux [io] + (control monad + pipe + ["&" state]) + (data [text "Text/" Monoid] + text/format + [number] + [product])) + lux/test) + +(test: "State" + ($_ seq + (assert "" (i.= 123 (product;right (&;run 123 &;get)))) + (assert "" (i.= 321 (product;right (&;run 123 (do &;Monad + [_ (&;put 321)] + &;get))))) + (assert "" (i.= 369 (product;right (&;run 123 (do &;Monad + [_ (&;update (i.* 3))] + &;get))))) + (assert "" (i.= 124 (product;right (&;run 123 (&;use i.inc))))) + (assert "" (i.= 246 (product;right (&;run 123 (&;local (i.* 2) &;get))))) + (assert "" (i.= 124 (product;right (&;run 123 (:: &;Functor map i.inc &;get))))) + (assert "" (i.= 10 (product;right (&;run 123 (:: &;Applicative wrap 10))))) + (assert "" (i.= 30 (product;right (&;run 123 (let [(^open "&/") &;Applicative] + (&/apply (&/wrap (i.+ 10)) (&/wrap 20))))))) + (assert "" (i.= 30 (product;right (&;run 123 (: (&;State Int Int) + (do &;Monad + [f (wrap i.+) + x (wrap 10) + y (wrap 20)] + (wrap (f x y)))))))) + )) + +(test: "Monad transformer" + (let [lift (&;lift-state io;Monad) + (^open "io/") io;Monad] + (assert "Can add state functionality to any monad." + (|> (: (&;State' io;IO Text Int) + (do (&;StateT io;Monad) + [a (lift (io/wrap 123)) + b (wrap 456)] + (wrap (i.+ a b)))) + (&;run' "") + io;run + (case> ["" 579] true + _ false))) + )) diff --git a/stdlib/test/test/lux/control/thunk.lux b/stdlib/test/test/lux/control/thunk.lux new file mode 100644 index 000000000..cc8ca653d --- /dev/null +++ b/stdlib/test/test/lux/control/thunk.lux @@ -0,0 +1,23 @@ +(;module: + lux + (lux [io] + (control monad + ["&" thunk]) + ["R" math/random]) + lux/test) + +(test: "Thunks" + [left R;nat + right R;nat + #let [thunk (&;freeze (n.* left right)) + expected (n.* left right)]] + ($_ seq + (assert "Thunking does not alter the expected value." + (n.= expected + (&;thaw thunk))) + (assert "Thunks only evaluate once." + (and (not (is expected + (&;thaw thunk))) + (is (&;thaw thunk) + (&;thaw thunk)))) + )) diff --git a/stdlib/test/test/lux/data/coll/stream.lux b/stdlib/test/test/lux/data/coll/stream.lux index edc7d52dc..f68ae60f3 100644 --- a/stdlib/test/test/lux/data/coll/stream.lux +++ b/stdlib/test/test/lux/data/coll/stream.lux @@ -2,13 +2,13 @@ lux (lux [io] (control monad - comonad) + comonad + [cont]) (data [text "Text/" Monoid] text/format (coll [list] ["&" stream]) [number "Nat/" Codec]) - (function [cont]) ["R" math/random]) lux/test) diff --git a/stdlib/test/test/lux/function/cont.lux b/stdlib/test/test/lux/function/cont.lux deleted file mode 100644 index 4362f5a75..000000000 --- a/stdlib/test/test/lux/function/cont.lux +++ /dev/null @@ -1,75 +0,0 @@ -(;module: - lux - (lux [io] - (control monad) - (data [text "Text/" Monoid] - text/format - [number] - [product] - (coll [list])) - (function ["&" cont]) - ["R" math/random]) - lux/test) - -(test: "Continuations" - [sample R;nat - #let [(^open "&/") &;Monad] - elems (R;list +3 R;nat)] - ($_ seq - (assert "Can run continuations to compute their values." - (n.= sample (&;run (&/wrap sample)))) - - (assert "Can use functor." - (n.= (n.inc sample) (&;run (&/map n.inc (&/wrap sample))))) - - (assert "Can use applicative." - (n.= (n.inc sample) (&;run (&/apply (&/wrap n.inc) (&/wrap sample))))) - - (assert "Can use monad." - (n.= (n.inc sample) (&;run (do &;Monad - [func (wrap n.inc) - arg (wrap sample)] - (wrap (func arg)))))) - - (assert "Can use the current-continuation as a escape hatch." - (n.= (n.* +2 sample) - (&;run (do &;Monad - [value (&;call/cc - (function [k] - (do @ - [temp (k sample)] - ## If this code where to run, - ## the output would be - ## (n.* +4 sample) - (k temp))))] - (wrap (n.* +2 value)))))) - - (assert "Can use the current-continuation to build a time machine." - (n.= (n.+ +100 sample) - (&;run (do &;Monad - [[restart [output idx]] (&;portal [sample +0])] - (if (n.< +10 idx) - (restart [(n.+ +10 output) (n.inc idx)]) - (wrap output)))))) - - (assert "Can use delimited continuations with shifting." - (let [(^open "&/") &;Monad - (^open "L/") (list;Eq number;Eq) - visit (: (-> (List Nat) - (&;Cont (List Nat) (List Nat))) - (function visit [xs] - (case xs - #;Nil - (&/wrap #;Nil) - - (#;Cons x xs') - (do &;Monad - [output (&;shift (function [k] - (do @ - [tail (k xs')] - (wrap (#;Cons x tail)))))] - (visit output)))))] - (L/= elems - (&;run (&;reset (visit elems)))) - )) - )) diff --git a/stdlib/test/test/lux/function/reader.lux b/stdlib/test/test/lux/function/reader.lux deleted file mode 100644 index 602efc603..000000000 --- a/stdlib/test/test/lux/function/reader.lux +++ /dev/null @@ -1,37 +0,0 @@ -(;module: - lux - (lux [io] - (control monad - pipe) - (data [text "Text/" Monoid] - text/format - [number]) - (function ["&" reader])) - lux/test) - -(test: "Readers" - ($_ seq - (assert "" (i.= 123 (&;run 123 &;ask))) - (assert "" (i.= 246 (&;run 123 (&;local (i.* 2) &;ask)))) - (assert "" (i.= 134 (&;run 123 (:: &;Functor map i.inc (i.+ 10))))) - (assert "" (i.= 10 (&;run 123 (:: &;Applicative wrap 10)))) - (assert "" (i.= 30 (&;run 123 (let [(^open "&/") &;Applicative] - (&/apply (&/wrap (i.+ 10)) (&/wrap 20)))))) - (assert "" (i.= 30 (&;run 123 (do &;Monad - [f (wrap i.+) - x (wrap 10) - y (wrap 20)] - (wrap (f x y)))))))) - -(test: "Monad transformer" - (let [(^open "io/") io;Monad] - (assert "Can add reader functionality to any monad." - (|> (do (&;ReaderT io;Monad) - [a (&;lift-reader (io/wrap 123)) - b (wrap 456)] - (wrap (i.+ a b))) - (&;run "") - io;run - (case> 579 true - _ false))) - )) diff --git a/stdlib/test/test/lux/function/state.lux b/stdlib/test/test/lux/function/state.lux deleted file mode 100644 index 9ef61e4d3..000000000 --- a/stdlib/test/test/lux/function/state.lux +++ /dev/null @@ -1,49 +0,0 @@ -(;module: - lux - (lux [io] - (control monad - pipe) - (data [text "Text/" Monoid] - text/format - [number] - [product]) - (function ["&" state])) - lux/test) - -(test: "State" - ($_ seq - (assert "" (i.= 123 (product;right (&;run 123 &;get)))) - (assert "" (i.= 321 (product;right (&;run 123 (do &;Monad - [_ (&;put 321)] - &;get))))) - (assert "" (i.= 369 (product;right (&;run 123 (do &;Monad - [_ (&;update (i.* 3))] - &;get))))) - (assert "" (i.= 124 (product;right (&;run 123 (&;use i.inc))))) - (assert "" (i.= 246 (product;right (&;run 123 (&;local (i.* 2) &;get))))) - (assert "" (i.= 124 (product;right (&;run 123 (:: &;Functor map i.inc &;get))))) - (assert "" (i.= 10 (product;right (&;run 123 (:: &;Applicative wrap 10))))) - (assert "" (i.= 30 (product;right (&;run 123 (let [(^open "&/") &;Applicative] - (&/apply (&/wrap (i.+ 10)) (&/wrap 20))))))) - (assert "" (i.= 30 (product;right (&;run 123 (: (&;State Int Int) - (do &;Monad - [f (wrap i.+) - x (wrap 10) - y (wrap 20)] - (wrap (f x y)))))))) - )) - -(test: "Monad transformer" - (let [lift (&;lift-state io;Monad) - (^open "io/") io;Monad] - (assert "Can add state functionality to any monad." - (|> (: (&;State' io;IO Text Int) - (do (&;StateT io;Monad) - [a (lift (io/wrap 123)) - b (wrap 456)] - (wrap (i.+ a b)))) - (&;run' "") - io;run - (case> ["" 579] true - _ false))) - )) diff --git a/stdlib/test/test/lux/function/thunk.lux b/stdlib/test/test/lux/function/thunk.lux deleted file mode 100644 index 753398f77..000000000 --- a/stdlib/test/test/lux/function/thunk.lux +++ /dev/null @@ -1,23 +0,0 @@ -(;module: - lux - (lux [io] - (control monad) - (function ["&" thunk]) - ["R" math/random]) - lux/test) - -(test: "Thunks" - [left R;nat - right R;nat - #let [thunk (&;freeze (n.* left right)) - expected (n.* left right)]] - ($_ seq - (assert "Thunking does not alter the expected value." - (n.= expected - (&;thaw thunk))) - (assert "Thunks only evaluate once." - (and (not (is expected - (&;thaw thunk))) - (is (&;thaw thunk) - (&;thaw thunk)))) - )) diff --git a/stdlib/test/tests.lux b/stdlib/test/tests.lux index 931a89e28..4cb00c4a7 100644 --- a/stdlib/test/tests.lux +++ b/stdlib/test/tests.lux @@ -9,10 +9,6 @@ (lux ["_;" cli] ["_;" host] ["_;" io] - (function ["_;" cont] - ["_;" reader] - ["_;" state] - ["_;" thunk]) (concurrency ["_;" actor] ["_;" atom] ["_;" frp] @@ -20,7 +16,11 @@ ["_;" stm]) (control ["_;" effect] ["_;" interval] - ["_;" pipe]) + ["_;" pipe] + ["_;" cont] + ["_;" reader] + ["_;" state] + ["_;" thunk]) (data ["_;" bit] ["_;" bool] ["_;" char] -- cgit v1.2.3