aboutsummaryrefslogtreecommitdiff
path: root/stdlib/test
diff options
context:
space:
mode:
authorEduardo Julian2017-07-31 20:33:00 -0400
committerEduardo Julian2017-07-31 20:33:00 -0400
commit8ddeafb14fdb4511f2d0632801f18699cfcaf3ea (patch)
treec90a2a0ffd0874f6af7366369171a9e985bff94c /stdlib/test
parent29937554a211a602612d79b0fc58fc788d9ab919 (diff)
- Extended duration and date with Order and Codec implementations.
Diffstat (limited to 'stdlib/test')
-rw-r--r--stdlib/test/test/lux/time/date.lux45
-rw-r--r--stdlib/test/test/lux/time/duration.lux18
2 files changed, 59 insertions, 4 deletions
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<Random>])
- (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<Random> map @instant;date)))
+
+(context: "(Date) Eq."
+ [sample date
+ #let [(^open "@/") @;Eq<Date>]]
+ (test "Every value equals itself."
+ (@/= sample sample)))
+
+(context: "(Date) Order."
+ [reference date
+ sample date
+ #let [(^open "@/") @;Order<Date>]]
+ (test "Valid Order."
+ (and (or (@/< reference sample)
+ (@/>= reference sample))
+ (or (@/> reference sample)
+ (@/<= reference sample)))))
+
+(context: "(Date) Codec"
+ #seed +1501531301120
+ [sample date
+ #let [(^open "@/") @;Eq<Date>
+ (^open "@/") @;Codec<Text,Date>]]
+ (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<Duration>
+ (^open "@/") @;Codec<Text,Duration>]]
+ (test "Can encode/decode durations."
+ (|> sample
+ @/encode
+ @/decode
+ (pipe;case> (#R;Success decoded)
+ (@/= sample decoded)
+
+ (#R;Error error)
+ false))))