From 8ddeafb14fdb4511f2d0632801f18699cfcaf3ea Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 31 Jul 2017 20:33:00 -0400 Subject: - Extended duration and date with Order and Codec implementations. --- stdlib/test/test/lux/time/date.lux | 45 +++++++++++++++++++++++++++++++--- stdlib/test/test/lux/time/duration.lux | 18 +++++++++++++- 2 files changed, 59 insertions(+), 4 deletions(-) (limited to 'stdlib/test') diff --git a/stdlib/test/test/lux/time/date.lux b/stdlib/test/test/lux/time/date.lux index e5b5fefc5..2a56fb71a 100644 --- a/stdlib/test/test/lux/time/date.lux +++ b/stdlib/test/test/lux/time/date.lux @@ -1,10 +1,14 @@ (;module: lux (lux [io] - (control [monad #+ do Monad]) + (control [monad #+ do Monad] + [pipe]) + (data ["R" result]) (math ["r" random "r/" Monad]) - (time ["@" date])) - lux/test) + (time ["@;" instant] + ["@" date])) + lux/test + (test (lux (time ["_;" instant])))) (def: month (r;Random @;Month) @@ -84,3 +88,38 @@ sample)) (|> sample @/succ @/pred (@/= sample)) (|> sample @/pred @/succ (@/= sample))))) + +(def: date + (r;Random @;Date) + (|> _instant;instant (:: r;Monad map @instant;date))) + +(context: "(Date) Eq." + [sample date + #let [(^open "@/") @;Eq]] + (test "Every value equals itself." + (@/= sample sample))) + +(context: "(Date) Order." + [reference date + sample date + #let [(^open "@/") @;Order]] + (test "Valid Order." + (and (or (@/< reference sample) + (@/>= reference sample)) + (or (@/> reference sample) + (@/<= reference sample))))) + +(context: "(Date) Codec" + #seed +1501531301120 + [sample date + #let [(^open "@/") @;Eq + (^open "@/") @;Codec]] + (test "Can encode/decode dates." + (|> sample + @/encode + @/decode + (pipe;case> (#R;Success decoded) + (@/= sample decoded) + + (#R;Error error) + false)))) diff --git a/stdlib/test/test/lux/time/duration.lux b/stdlib/test/test/lux/time/duration.lux index 18ec46090..565010a07 100644 --- a/stdlib/test/test/lux/time/duration.lux +++ b/stdlib/test/test/lux/time/duration.lux @@ -1,7 +1,9 @@ (;module: lux (lux [io] - (control [monad #+ do Monad]) + (control [monad #+ do Monad] + [pipe]) + (data ["R" result]) (math ["r" random]) (time ["@" duration])) lux/test) @@ -55,3 +57,17 @@ (@;scale -1 frame) frame)))))) )) + +(context: "Codec" + [sample duration + #let [(^open "@/") @;Eq + (^open "@/") @;Codec]] + (test "Can encode/decode durations." + (|> sample + @/encode + @/decode + (pipe;case> (#R;Success decoded) + (@/= sample decoded) + + (#R;Error error) + false)))) -- cgit v1.2.3