diff options
author | Eduardo Julian | 2022-08-18 21:34:21 -0400 |
---|---|---|
committer | Eduardo Julian | 2022-08-18 21:34:21 -0400 |
commit | 81b6e0d7038a99c66456033c8285f740a3b0c719 (patch) | |
tree | 4d09e45791f19bd40170260502ebc958b07ee1af /stdlib/source/test/lux/control/concurrency/cps.lux | |
parent | ecda0d219cf7dc25bd9b0b76815a8880e20232c2 (diff) |
Added support for Communicating Sequential Processes (CSP).
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/test/lux/control/concurrency/cps.lux | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/stdlib/source/test/lux/control/concurrency/cps.lux b/stdlib/source/test/lux/control/concurrency/cps.lux new file mode 100644 index 000000000..5bf53cb96 --- /dev/null +++ b/stdlib/source/test/lux/control/concurrency/cps.lux @@ -0,0 +1,92 @@ +(.require + [library + [lux (.except) + [abstract + [monad (.only do)] + [\\specification + ["$[0]" functor (.only Injection Comparison)] + ["$[0]" monad]]] + [control + ["[0]" io] + ["[0]" try] + ["[0]" exception]] + [math + ["[0]" random]] + [test + ["_" property (.only Test)] + ["[0]" unit]]]] + [\\library + ["[0]" / (.only) + [// + ["[0]" async]]]]) + +(def injection + (Injection /.Process) + (at /.monad in)) + +(def comparison + (Comparison /.Process) + (function (_ == left right) + (io.run! + (do io.monad + [?left (async.value left) + ?right (async.value right)] + (in (when [?left ?right] + [{.#Some {try.#Success left}} + {.#Some {try.#Success right}}] + (== left right) + + _ + false)))))) + +(def .public test + Test + (<| (_.covering /._) + (do [! random.monad] + [expected random.nat] + (all _.and + (_.for [/.Process] + (all _.and + (_.for [/.functor] + ($functor.spec ..injection ..comparison /.functor)) + (_.for [/.monad] + ($monad.spec ..injection ..comparison /.monad)) + )) + (_.coverage [/.Channel /.Channel' /.Sink /.channel] + ... This is already been tested for the FRP module. + true) + (in (do async.monad + [it (do /.monad + [.let [[channel sink] (/.channel [])] + _ (/.write expected sink) + [actual channel] (/.read channel)] + (in (same? expected actual)))] + (unit.coverage [/.read /.write] + (try.else false it)))) + (in (do async.monad + [it (do /.monad + [.let [[channel sink] (/.channel [])] + _ (/.close sink) + it (/.try (/.write expected sink))] + (in (when it + {try.#Failure _} + true + + _ + false)))] + (unit.coverage [/.close /.try] + (try.else false it)))) + (in (do async.monad + [it (do /.monad + [.let [[channel sink] (/.channel [])] + _ (/.close sink) + it (/.try (/.read channel))] + (in (when it + {try.#Failure error} + (exception.match? /.channel_has_been_closed error) + + _ + false)))] + (unit.coverage [/.channel_has_been_closed] + (try.else false it)))) + )))) |