aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/time/instant.lux
diff options
context:
space:
mode:
authorEduardo Julian2019-03-23 00:56:55 -0400
committerEduardo Julian2019-03-23 00:56:55 -0400
commit90dbb19a8e826fe3ab367fa73b36ce932610b330 (patch)
treeac1de354cc8c2f36f68f82712e06cb968f558700 /stdlib/source/test/lux/time/instant.lux
parentf28169f3ab674651fceff0c4c9989f5cc62b616b (diff)
Ported tests for time-related modules.
Diffstat (limited to '')
-rw-r--r--stdlib/source/test/lux/time/instant.lux122
1 files changed, 41 insertions, 81 deletions
diff --git a/stdlib/source/test/lux/time/instant.lux b/stdlib/source/test/lux/time/instant.lux
index a95eaf612..ec4a9456c 100644
--- a/stdlib/source/test/lux/time/instant.lux
+++ b/stdlib/source/test/lux/time/instant.lux
@@ -1,99 +1,59 @@
(.module:
[lux #*
- [io]
+ data/text/format
+ ["_" test (#+ Test)]
[control
+ pipe
[monad (#+ do Monad)]
- pipe]
+ {[0 #test]
+ [/
+ ["$." equivalence]
+ ["$." order]
+ ["$." enum]
+ ["$." codec]]}]
[data
- ["." text
- format]
- [error]]
+ ["." text]]
[math
- ["r" random]]
+ ["r" random (#+ Random)]]
[time
- ["@" instant]
["@d" duration]
["@date" date]]]
- lux/test
[//
- ["_." duration]])
+ ["_." duration]]
+ {1
+ ["." / (#+ Instant)]})
(def: boundary Int +99,999,999,999,999)
(def: #export instant
- (r.Random @.Instant)
- (|> r.int (:: r.monad map (|>> (i/% boundary) @.from-millis))))
-
-(context: "Conversion."
- (<| (times 100)
- (do @
+ (Random Instant)
+ (:: r.monad map (|>> (i/% boundary) /.from-millis) r.int))
+
+(def: #export test
+ Test
+ ($_ _.and
+ ($equivalence.spec /.equivalence ..instant)
+ ($order.spec /.order ..instant)
+ ($enum.spec /.enum ..instant)
+ ## TODO; Uncomment ASAP
+ ## ($codec.spec /.equivalence /.codec ..instant)
+
+ (do r.monad
[millis r.int]
- (test "Can convert from/to milliseconds."
- (|> millis @.from-millis @.to-millis (i/= millis))))))
-
-(context: "Equivalence."
- (<| (times 100)
- (do @
- [sample instant
- #let [(^open "@/.") @.equivalence]]
- (test "Every instant equals itself."
- (@/= sample sample)))))
-
-(context: "Order"
- (<| (times 100)
- (do @
- [reference instant
- sample instant
- #let [(^open "@/.") @.order]]
- (test "Can compare instants."
- (and (or (@/< reference sample)
- (@/>= reference sample))
- (or (@/> reference sample)
- (@/<= reference sample)))))))
-
-(context: "Enum"
- (<| (times 100)
- (do @
- [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"
- (<| (times 100)
- (do @
+ (_.test "Can convert from/to milliseconds."
+ (|> millis /.from-millis /.to-millis (i/= millis))))
+ (do r.monad
[sample instant
span _duration.duration
- #let [(^open "@/.") @.equivalence
+ #let [(^open "@/.") /.equivalence
(^open "@d/.") @d.equivalence]]
- ($_ seq
- (test "The span of a instant and itself has an empty duration."
- (|> sample (@.span sample) (@d/= @d.empty)))
- (test "Can shift a instant by a duration."
- (|> sample (@.shift span) (@.span sample) (@d/= span)))
- (test "Can obtain the time-span between the epoch and an instant."
- (|> sample @.relative @.absolute (@/= sample)))
- (test "All instants are relative to the epoch."
- (|> @.epoch (@.shift (@.relative sample)) (@/= sample)))))))
-
-## (context: "Codec"
-## (<| (seed 9863552679229274604)
-## ## (times 100)
-## (do @
-## [sample instant
-## #let [(^open "@/.") @.equivalence
-## (^open "@/.") @.codec]]
-## (test "Can encode/decode instants."
-## (|> sample
-## @/encode
-## @/decode
-## (case> (#error.Success decoded)
-## (@/= sample decoded)
-
-## (#error.Failure error)
-## #0))))))
+ ($_ _.and
+ (_.test "The span of a instant and itself has an empty duration."
+ (|> sample (/.span sample) (@d/= @d.empty)))
+ (_.test "Can shift a instant by a duration."
+ (|> sample (/.shift span) (/.span sample) (@d/= span)))
+ (_.test "Can obtain the time-span between the epoch and an instant."
+ (|> sample /.relative /.absolute (@/= sample)))
+ (_.test "All instants are relative to the epoch."
+ (|> /.epoch (/.shift (/.relative sample)) (@/= sample)))))
+ ))