From f502efa593f22c82d2ae4cee70be90b5e3c96fe8 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 29 Jul 2017 18:38:09 -0400 Subject: - Added more structures for instants and dates. --- stdlib/test/test/lux/time/date.lux | 86 +++++++++++++++++++++++++++++++++++ stdlib/test/test/lux/time/instant.lux | 11 +++++ stdlib/test/tests.lux | 3 +- 3 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 stdlib/test/test/lux/time/date.lux (limited to 'stdlib/test') diff --git a/stdlib/test/test/lux/time/date.lux b/stdlib/test/test/lux/time/date.lux new file mode 100644 index 000000000..e5b5fefc5 --- /dev/null +++ b/stdlib/test/test/lux/time/date.lux @@ -0,0 +1,86 @@ +(;module: + lux + (lux [io] + (control [monad #+ do Monad]) + (math ["r" random "r/" Monad]) + (time ["@" date])) + lux/test) + +(def: month + (r;Random @;Month) + (r;either (r;either (r;either (r/wrap #@;January) + (r;either (r/wrap #@;February) + (r/wrap #@;March))) + (r;either (r/wrap #@;April) + (r;either (r/wrap #@;May) + (r/wrap #@;June)))) + (r;either (r;either (r/wrap #@;July) + (r;either (r/wrap #@;August) + (r/wrap #@;September))) + (r;either (r/wrap #@;October) + (r;either (r/wrap #@;November) + (r/wrap #@;December)))))) + +(context: "(Month) Eq." + [sample month + #let [(^open "@/") @;Eq]] + (test "Every value equals itself." + (@/= sample sample))) + +(context: "(Month) Order." + [reference month + sample month + #let [(^open "@/") @;Order]] + (test "Valid Order." + (and (or (@/< reference sample) + (@/>= reference sample)) + (or (@/> reference sample) + (@/<= reference sample))))) + +(context: "(Month) Enum." + [sample month + #let [(^open "@/") @;Enum]] + (test "Valid Enum." + (and (not (@/= (@/succ sample) + sample)) + (not (@/= (@/pred sample) + sample)) + (|> sample @/succ @/pred (@/= sample)) + (|> sample @/pred @/succ (@/= sample))))) + +(def: day + (r;Random @;Day) + (r;either (r;either (r;either (r/wrap #@;Sunday) + (r/wrap #@;Monday)) + (r;either (r/wrap #@;Tuesday) + (r/wrap #@;Wednesday))) + (r;either (r;either (r/wrap #@;Thursday) + (r/wrap #@;Friday)) + (r/wrap #@;Saturday)))) + +(context: "(Day) Eq." + [sample day + #let [(^open "@/") @;Eq]] + (test "Every value equals itself." + (@/= sample sample))) + +(context: "(Day) Order." + [reference day + sample day + #let [(^open "@/") @;Order]] + (test "Valid Order." + (and (or (@/< reference sample) + (@/>= reference sample)) + (or (@/> reference sample) + (@/<= reference sample))))) + +(context: "(Day) Enum." + [sample day + #let [(^open "@/") @;Enum]] + (test "Valid Enum." + (and (not (@/= (@/succ sample) + sample)) + (not (@/= (@/pred sample) + sample)) + (|> sample @/succ @/pred (@/= sample)) + (|> sample @/pred @/succ (@/= sample))))) diff --git a/stdlib/test/test/lux/time/instant.lux b/stdlib/test/test/lux/time/instant.lux index 2baeff7a7..40ab587d7 100644 --- a/stdlib/test/test/lux/time/instant.lux +++ b/stdlib/test/test/lux/time/instant.lux @@ -44,6 +44,17 @@ (or (@/> reference sample) (@/<= reference sample))))) +(context: "Enum" + [sample instant + #let [(^open "@/") @;Enum]] + (test "Valid Enum." + (and (not (@/= (@/succ sample) + sample)) + (not (@/= (@/pred sample) + sample)) + (|> sample @/succ @/pred (@/= sample)) + (|> sample @/pred @/succ (@/= sample))))) + (context: "Arithmetic" [sample instant span duration diff --git a/stdlib/test/tests.lux b/stdlib/test/tests.lux index 6f593abff..b6dbdfcd2 100644 --- a/stdlib/test/tests.lux +++ b/stdlib/test/tests.lux @@ -10,7 +10,8 @@ ["_;" host] ["_;" io] (time ["_;" instant] - ["_;" duration]) + ["_;" duration] + ["_;" date]) (concurrency ["_;" actor] ["_;" atom] ["_;" frp] -- cgit v1.2.3