aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source
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
parentf28169f3ab674651fceff0c4c9989f5cc62b616b (diff)
Ported tests for time-related modules.
Diffstat (limited to 'stdlib/source')
-rw-r--r--stdlib/source/lux/type/unit.lux4
-rw-r--r--stdlib/source/test/lux.lux24
-rw-r--r--stdlib/source/test/lux/time.lux19
-rw-r--r--stdlib/source/test/lux/time/date.lux158
-rw-r--r--stdlib/source/test/lux/time/day.lux32
-rw-r--r--stdlib/source/test/lux/time/duration.lux87
-rw-r--r--stdlib/source/test/lux/time/instant.lux122
-rw-r--r--stdlib/source/test/lux/time/month.lux37
8 files changed, 201 insertions, 282 deletions
diff --git a/stdlib/source/lux/type/unit.lux b/stdlib/source/lux/type/unit.lux
index 49ee2709b..ab971a4d7 100644
--- a/stdlib/source/lux/type/unit.lux
+++ b/stdlib/source/lux/type/unit.lux
@@ -143,7 +143,9 @@
(def: #export (re-scale from to quantity)
(All [si so u] (-> (Scale si) (Scale so) (Qty (si u)) (Qty (so u))))
- (let [[numerator denominator] (|> (:: to ratio) (r./ (:: from ratio)))]
+ (let [[numerator denominator] (:: r.number /
+ (:: from ratio)
+ (:: to ratio))]
(|> quantity
out
(i/* (.int numerator))
diff --git a/stdlib/source/test/lux.lux b/stdlib/source/test/lux.lux
index c61891996..3855f350f 100644
--- a/stdlib/source/test/lux.lux
+++ b/stdlib/source/test/lux.lux
@@ -20,7 +20,7 @@
["." i64]]]
["." function]
["." math
- ["r" random (#+ Random) ("#;." functor)]]
+ ["r" random (#+ Random) ("#@." functor)]]
["_" test (#+ Test)]
## These modules do not need to be tested.
[type
@@ -113,6 +113,7 @@
["#." io]
["#." control]
["#." data]
+ ["#." time]
["#." host
["#/." jvm]]]
## [control
@@ -120,9 +121,6 @@
## ## [semaphore (#+)]
## ]]
## [data
- ## [format
- ## ## [json (#+)]
- ## [xml (#+)]]
## ## [collection
## ## [array (#+)]
## ## [bits (#+)]
@@ -157,10 +155,6 @@
## ## [implicit (#+)] ## TODO: FIX Specially troublesome...
## ## [resource (#+)]
## [dynamic (#+)]]
- ## [time
- ## [instant (#+)]
- ## [duration (#+)]
- ## [date (#+)]]
## [compiler
## [default
## ["_default/." syntax]
@@ -280,8 +274,8 @@
Test
($_ _.and
(do r.monad
- [factor (r;map (|>> (n/% 10) (n/max 1)) r.nat)
- iterations (r;map (n/% 100) r.nat)
+ [factor (r@map (|>> (n/% 10) (n/max 1)) r.nat)
+ iterations (r@map (n/% 100) r.nat)
#let [expected (n/* factor iterations)]]
(_.test "Can write loops."
(n/= expected
@@ -381,13 +375,13 @@
(..conversion <gen> <forward> <backward> <=>))]
["Int -> Nat"
- i/= .nat .int (r;map (i/% +1,000,000) r.int)]
+ i/= .nat .int (r@map (i/% +1,000,000) r.int)]
["Nat -> Int"
- n/= .int .nat (r;map (n/% 1,000,000) r.nat)]
+ n/= .int .nat (r@map (n/% 1,000,000) r.nat)]
["Int -> Frac"
- i/= int-to-frac frac-to-int (r;map (i/% +1,000,000) r.int)]
+ i/= int-to-frac frac-to-int (r@map (i/% +1,000,000) r.int)]
["Frac -> Int"
- f/= frac-to-int int-to-frac (r;map math.floor r.frac)]
+ f/= frac-to-int int-to-frac (r@map math.floor r.frac)]
["Rev -> Frac"
r/= rev-to-frac frac-to-rev frac-rev]
)))))
@@ -405,6 +399,8 @@
/control.test)
(<| (_.context "/data")
/data.test)
+ (<| (_.context "/time")
+ /time.test)
(<| (_.context "/host Host-platform interoperation")
($_ _.and
/host.test
diff --git a/stdlib/source/test/lux/time.lux b/stdlib/source/test/lux/time.lux
new file mode 100644
index 000000000..5fd13dbe9
--- /dev/null
+++ b/stdlib/source/test/lux/time.lux
@@ -0,0 +1,19 @@
+(.module:
+ [lux #*
+ ["_" test (#+ Test)]]
+ ["." / #_
+ ["#." duration]
+ ["#." instant]
+ ["#." day]
+ ["#." month]
+ ["#." date]])
+
+(def: #export test
+ Test
+ ($_ _.and
+ /duration.test
+ /instant.test
+ /day.test
+ /month.test
+ /date.test
+ ))
diff --git a/stdlib/source/test/lux/time/date.lux b/stdlib/source/test/lux/time/date.lux
index f9a90cb48..935e59c51 100644
--- a/stdlib/source/test/lux/time/date.lux
+++ b/stdlib/source/test/lux/time/date.lux
@@ -1,147 +1,31 @@
(.module:
[lux #*
+ data/text/format
+ ["_" test (#+ Test)]
[control
- [monad (#+ Monad do)]
- pipe]
- [data
- ["." error]]
+ {[0 #test]
+ [/
+ ["$." equivalence]
+ ["$." order]
+ ["$." codec]]}]
[math
- ["r" random ("#;." monad)]]
+ ["r" random (#+ Random)]]
[time
- ["@." instant]
- ["@" date]]]
- lux/test
+ ["@." instant]]]
[//
- ["_." instant]])
-
-(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) Equivalence."
- (<| (times 100)
- (do @
- [sample month
- #let [(^open "@/.") @.equivalence]]
- (test "Every value equals itself."
- (@/= sample sample)))))
-
-(context: "(Month) Order."
- (<| (times 100)
- (do @
- [reference month
- sample month
- #let [(^open "@/.") @.order]]
- (test "Valid Order."
- (and (or (@/< reference sample)
- (@/>= reference sample))
- (or (@/> reference sample)
- (@/<= reference sample)))))))
-
-(context: "(Month) Enum."
- (<| (times 100)
- (do @
- [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) Equivalence."
- (<| (times 100)
- (do @
- [sample day
- #let [(^open "@/.") @.equivalence]]
- (test "Every value equals itself."
- (@/= sample sample)))))
-
-(context: "(Day) Order."
- (<| (times 100)
- (do @
- [reference day
- sample day
- #let [(^open "@/.") @.order]]
- (test "Valid Order."
- (and (or (@/< reference sample)
- (@/>= reference sample))
- (or (@/> reference sample)
- (@/<= reference sample)))))))
-
-(context: "(Day) Enum."
- (<| (times 100)
- (do @
- [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)))))))
+ ["_." instant]]
+ {1
+ ["." / (#+ Date)]})
(def: #export date
- (r.Random @.Date)
+ (Random Date)
(|> _instant.instant (:: r.monad map @instant.date)))
-(context: "(Date) Equivalence."
- (<| (times 100)
- (do @
- [sample date
- #let [(^open "@/.") @.equivalence]]
- (test "Every value equals itself."
- (@/= sample sample)))))
-
-(context: "(Date) Order."
- (<| (times 100)
- (do @
- [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 6623983470548808292)
- ## (times 100)
- (do @
- [sample date
- #let [(^open "@/.") @.equivalence
- (^open "@/.") @.codec]]
- (test "Can encode/decode dates."
- (|> sample
- @/encode
- @/decode
- (case> (#error.Success decoded)
- (@/= sample decoded)
-
- (#error.Failure error)
- #0))))))
+(def: #export test
+ Test
+ ($_ _.and
+ ($equivalence.spec /.equivalence ..date)
+ ($order.spec /.order ..date)
+ (<| (_.seed 6623983470548808292)
+ ($codec.spec /.equivalence /.codec ..date))
+ ))
diff --git a/stdlib/source/test/lux/time/day.lux b/stdlib/source/test/lux/time/day.lux
new file mode 100644
index 000000000..e0142d1b4
--- /dev/null
+++ b/stdlib/source/test/lux/time/day.lux
@@ -0,0 +1,32 @@
+(.module:
+ [lux #*
+ data/text/format
+ ["_" test (#+ Test)]
+ [control
+ {[0 #test]
+ [/
+ ["$." equivalence]
+ ["$." order]
+ ["$." enum]]}]
+ [math
+ ["r" random (#+ Random) ("#@." monad)]]]
+ {1
+ ["." / (#+ Day)]})
+
+(def: #export day
+ (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))))
+
+(def: #export test
+ Test
+ ($_ _.and
+ ($equivalence.spec /.equivalence ..day)
+ ($order.spec /.order ..day)
+ ($enum.spec /.enum ..day)
+ ))
diff --git a/stdlib/source/test/lux/time/duration.lux b/stdlib/source/test/lux/time/duration.lux
index 3aba23203..ba0e35cf1 100644
--- a/stdlib/source/test/lux/time/duration.lux
+++ b/stdlib/source/test/lux/time/duration.lux
@@ -1,60 +1,49 @@
(.module:
[lux #*
- [io]
+ data/text/format
+ ["_" test (#+ Test)]
[control
- [monad (#+ do Monad)]]
+ [monad (#+ do)]
+ {[0 #test]
+ [/
+ ["$." equivalence]
+ ["$." order]
+ ["$." monoid]
+ ["$." codec]]}]
[data
["E" error]]
[math
- ["r" random]]
- [time
- ["@" duration]]]
- lux/test)
+ ["r" random (#+ Random)]]]
+ {1
+ ["." / (#+ Duration)]})
(def: #export duration
- (r.Random @.Duration)
- (|> r.int (:: r.monad map @.from-millis)))
+ (Random Duration)
+ (|> r.int (:: r.monad map /.from-millis)))
-(context: "Conversion."
- (<| (times 100)
- (do @
- [millis r.int]
- (test "Can convert from/to milliseconds."
- (|> millis @.from-millis @.to-millis (i/= millis))))))
-
-(context: "Equivalence."
- (<| (times 100)
- (do @
- [sample duration
- #let [(^open "@/.") @.equivalence]]
- (test "Every duration equals itself."
- (@/= sample sample)))))
+(def: #export test
+ Test
+ ($_ _.and
+ ($equivalence.spec /.equivalence ..duration)
+ ($order.spec /.order ..duration)
+ ($monoid.spec /.equivalence /.monoid ..duration)
+ ## TODO; Uncomment ASAP
+ ## ($codec.spec /.equivalence /.codec ..duration)
-(context: "Order."
- (<| (times 100)
- (do @
- [reference duration
- sample duration
- #let [(^open "@/.") @.order]]
- (test "Can compare times."
- (and (or (@/< reference sample)
- (@/>= reference sample))
- (or (@/> reference sample)
- (@/<= reference sample)))))))
-
-(context: "Arithmetic."
- (<| (times 100)
- (do @
- [sample (|> duration (:: @ map (@.frame @.day)))
+ (do r.monad
+ [millis r.int]
+ (_.test "Can convert from/to milliseconds."
+ (|> millis /.from-millis /.to-millis (i/= millis))))
+ (do r.monad
+ [sample (|> duration (:: @ map (/.frame /.day)))
frame duration
- factor (|> r.int (:: @ map (|>> (i/% +10) (i/max +1))))
- #let [(^open "@/.") @.order]]
- ($_ seq
- (test "Can scale a duration."
- (|> sample (@.scale-up factor) (@.query sample) (i/= factor)))
- (test "Scaling a duration by one does not change it."
- (|> sample (@.scale-up +1) (@/= sample)))
- (test "Merging with the empty duration changes nothing."
- (|> sample (@.merge @.empty) (@/= sample)))
- (test "Merging a duration with it's opposite yields an empty duration."
- (|> sample (@.merge (@.scale-up -1 sample)) (@/= @.empty)))))))
+ factor (|> r.nat (:: @ map (|>> (n/% 10) (n/max 1))))
+ #let [(^open "/@.") /.order]]
+ ($_ _.and
+ (_.test "Can scale a duration."
+ (|> sample (/.scale-up factor) (/.query sample) (i/= (.int factor))))
+ (_.test "Scaling a duration by one does not change it."
+ (|> sample (/.scale-up 1) (/@= sample)))
+ (_.test "Merging a duration with it's opposite yields an empty duration."
+ (|> sample (/.merge (/.inverse sample)) (/@= /.empty)))))
+ ))
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)))))
+ ))
diff --git a/stdlib/source/test/lux/time/month.lux b/stdlib/source/test/lux/time/month.lux
new file mode 100644
index 000000000..4c9365bb6
--- /dev/null
+++ b/stdlib/source/test/lux/time/month.lux
@@ -0,0 +1,37 @@
+(.module:
+ [lux #*
+ data/text/format
+ ["_" test (#+ Test)]
+ [control
+ {[0 #test]
+ [/
+ ["$." equivalence]
+ ["$." order]
+ ["$." enum]]}]
+ [math
+ ["r" random (#+ Random) ("#@." monad)]]]
+ {1
+ ["." / (#+ Month)]})
+
+(def: #export month
+ (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))))))
+
+(def: #export test
+ Test
+ ($_ _.and
+ ($equivalence.spec /.equivalence ..month)
+ ($order.spec /.order ..month)
+ ($enum.spec /.enum ..month)
+ ))