From 65a62b15fa7747302cebd3962bc26c07f5d90bec Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sun, 9 Dec 2018 23:15:13 -0400 Subject: Improved test for recursion in complex sessions. --- stdlib/test/test/lux/concurrency/session.lux | 65 ++++++++++++++++------------ 1 file 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 - [$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 - [add| ($you [])] - (case add| - (#.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| $you] + (do promise.Monad + [add| ($add| [])] + (case add| + (#.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))))))) ))) -- cgit v1.2.3