aboutsummaryrefslogtreecommitdiff
path: root/stdlib/test
diff options
context:
space:
mode:
authorEduardo Julian2018-12-09 23:15:13 -0400
committerEduardo Julian2018-12-09 23:15:13 -0400
commit65a62b15fa7747302cebd3962bc26c07f5d90bec (patch)
tree7483a8af1bfc2cbb0cffe82ecf87262eea81ac27 /stdlib/test
parent0c77e8ddf20ea95197f31596216ddf702d3898d2 (diff)
Improved test for recursion in complex sessions.
Diffstat (limited to 'stdlib/test')
-rw-r--r--stdlib/test/test/lux/concurrency/session.lux65
1 files changed, 38 insertions, 27 deletions
diff --git a/stdlib/test/test/lux/concurrency/session.lux b/stdlib/test/test/lux/concurrency/session.lux
index ea27bf4b9..192421f02 100644
--- a/stdlib/test/test/lux/concurrency/session.lux
+++ b/stdlib/test/test/lux/concurrency/session.lux
@@ -86,6 +86,8 @@
(<| $.send $.receive recur)
$.end))))
+(def: negate (i/* -1))
+
(context: "Complex session."
(do @
[#let [[$me $you] (lazy.thaw calculation)]
@@ -94,35 +96,44 @@
#let [expectation (i/+ param subject)]]
($_ seq
(wrap (do promise.Monad<Promise>
- [$me ($me (#.Left id))
+ [## Add
+ $me ($me (#.Left id))
$me ($me param)
$me ($me subject)
- [output $end] ($me [])]
- (assert "Client [#Add]"
- (i/= expectation output))))
- (wrap (do promise.Monad<Promise>
- [add|<negate|quit> ($you [])]
- (case add|<negate|quit>
- (#.Left $add)
- (do @
- [[param-input $add] ($add [])
- [subject-input $add] ($add [])
- $recur ($add (i/+ param-input subject-input))]
- (assert "Server [#Add]"
- true))
+ [output $me] ($me [])
+ ## Negate
+ $me ($me (#.Right id))
+ $me ($me (#.Left id))
+ $me ($me output)
+ [-output $me] ($me [])
+ ## Quit
+ $me ($me (#.Right id))
+ $me ($me (#.Right id))]
+ (assert "Client [Add & Negate & Quit]"
+ (and (i/= expectation output)
+ (i/= (..negate expectation) -output)))))
+ (wrap (loop [$add|<negate|quit> $you]
+ (do promise.Monad<Promise>
+ [add|<negate|quit> ($add|<negate|quit> [])]
+ (case add|<negate|quit>
+ (#.Left $add)
+ (do @
+ [[param-input $add] ($add [])
+ [subject-input $add] ($add [])
+ $recur ($add (i/+ param-input subject-input))]
+ (recur $recur))
- (#.Right $negate|quit)
- (do @
- [negate|quit ($negate|quit [])]
- (case negate|quit
- (#.Left $negate)
- (do @
- [[subject $negate] ($negate [])
- $recur ($negate (i/* -1 subject))]
- (assert "Server [#Negate]"
- true))
+ (#.Right $negate|quit)
+ (do @
+ [negate|quit ($negate|quit [])]
+ (case negate|quit
+ (#.Left $negate)
+ (do @
+ [[subject $negate] ($negate [])
+ $recur ($negate (..negate subject))]
+ (recur $recur))
- (#.Right $quit)
- (assert "Server [#Quit]"
- true))))))
+ (#.Right $quit)
+ (assert "Server [Quit]"
+ true)))))))
)))