From 41f2e0c5dc17e939a73686ea3f54a251b6362141 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sun, 23 Jul 2017 01:27:35 -0400 Subject: - Added module for time (Codec has currently been tested only for time after epoch). --- stdlib/test/test/lux/time.lux | 86 +++++++++++++++++++++++++++++++++++++++++++ stdlib/test/tests.lux | 1 + 2 files changed, 87 insertions(+) create mode 100644 stdlib/test/test/lux/time.lux (limited to 'stdlib/test') diff --git a/stdlib/test/test/lux/time.lux b/stdlib/test/test/lux/time.lux new file mode 100644 index 000000000..becdfc068 --- /dev/null +++ b/stdlib/test/test/lux/time.lux @@ -0,0 +1,86 @@ +(;module: + lux + (lux [io] + (control [monad #+ do Monad] + pipe) + (data [text] + text/format + ["R" result] + [number "Int/" Number]) + (math ["r" random]) + ["@" time]) + lux/test) + +(def: (limited-int size) + (-> Nat (r;Random Int)) + (do r;Monad + [sample r;int] + (wrap (|> sample + Int/abs + (i.% (nat-to-int size)) + (i.* (Int/signum sample)))))) + +(def: (pow exp base) + (-> Nat Int Int) + (case exp + +0 1 + _ (loop [exp exp + result base] + (case exp + +1 result + _ (recur (n.dec exp) + (i.* base result)))))) +(def: boundary Int (|> 2 (pow +31) (i.* @;second))) + +(def: time (r;Random @;Time) + (|> r;int + (r;filter (i.>= 0)) + ## (:: r;Monad map (i.% boundary)) + )) + +(context: "Equality" + [sample time + #let [(^open) @;Eq