diff options
Diffstat (limited to 'stdlib/source/test/lux/control/concurrency/frp.lux')
-rw-r--r-- | stdlib/source/test/lux/control/concurrency/frp.lux | 92 |
1 files changed, 49 insertions, 43 deletions
diff --git a/stdlib/source/test/lux/control/concurrency/frp.lux b/stdlib/source/test/lux/control/concurrency/frp.lux index 7c1552f41..b49a9e649 100644 --- a/stdlib/source/test/lux/control/concurrency/frp.lux +++ b/stdlib/source/test/lux/control/concurrency/frp.lux @@ -1,53 +1,59 @@ (.module: [lux #* + ["_" test (#+ Test)] ["." io (#+ IO io)] [control - ["." monad (#+ do Monad)] + ["." monad (#+ do)] [concurrency ["." promise ("#/." monad)] - ["." frp (#+ Channel)] ["." atom (#+ Atom atom)]]] [data - ["." number] + [number + ["." nat]] [collection - ["." list]]]] - lux/test) + ["." list ("#/." functor)]]] + [math + ["r" random]]] + {1 + ["." / (#+ Channel)]}) -(context: "FRP" - (let [(^open "list/.") (list.equivalence number.equivalence)] - ($_ seq - (wrap (do promise.monad - [output (|> (list +0 +1 +2 +3 +4 +5) - (frp.sequential 0) - (frp.filter i/even?) - frp.consume)] - (assert "Can filter a channel's elements." - (list/= (list +0 +2 +4) output)))) - - (wrap (do promise.monad - [output (|> (list +0 +1 +2 +3 +4 +5) - (frp.sequential 0) - (:: frp.functor map inc) - frp.consume)] - (assert "Functor goes over every element in a channel." - (list/= (list +1 +2 +3 +4 +5 +6) - output)))) - - (wrap (do promise.monad - [output (frp.consume (:: frp.apply apply - (frp.sequential 0 (list inc)) - (frp.sequential 0 (list +12345))))] - (assert "Apply works over all channel values." - (list/= (list +12346) - output)))) - - (wrap (do promise.monad - [output (frp.consume - (do frp.monad - [f (frp.from-promise (promise/wrap inc)) - a (frp.from-promise (promise/wrap +12345))] - (wrap (f a))))] - (assert "Valid monad." - (list/= (list +12346) - output)))) - ))) +(def: #export test + Test + (let [(^open "list/.") (list.equivalence nat.equivalence)] + (do r.monad + [inputs (r.list 5 r.nat) + sample r.nat] + ($_ _.and + (wrap (do promise.monad + [output (|> inputs + (/.sequential 0) + (/.filter n/even?) + /.consume)] + (_.assert "Can filter a channel's elements." + (list/= (list.filter n/even? inputs) + output)))) + (wrap (do promise.monad + [output (|> inputs + (/.sequential 0) + (:: /.functor map inc) + /.consume)] + (_.assert "Functor goes over every element in a channel." + (list/= (list/map inc inputs) + output)))) + (wrap (do promise.monad + [output (/.consume (:: /.apply apply + (/.sequential 0 (list inc)) + (/.sequential 0 (list sample))))] + (_.assert "Apply works over all channel values." + (list/= (list (inc sample)) + output)))) + (wrap (do promise.monad + [output (/.consume + (do /.monad + [f (/.from-promise (promise/wrap inc)) + a (/.from-promise (promise/wrap sample))] + (wrap (f a))))] + (_.assert "Valid monad." + (list/= (list (inc sample)) + output)))) + )))) |