aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test
diff options
context:
space:
mode:
authorEduardo Julian2022-06-15 20:12:02 -0400
committerEduardo Julian2022-06-15 20:12:02 -0400
commit38328f38b6904a884411835afa0066d0f9c503e7 (patch)
treeaa7fe821e9015e4646abb2340fe6bd54ae466898 /stdlib/source/test
parentbb16d7e4a3307cc9540f368cf5c354a72af8ec61 (diff)
De-sigil-ification: suffix : [Part 11]
Diffstat (limited to '')
-rw-r--r--stdlib/source/test/lux/data/format/json.lux3
-rw-r--r--stdlib/source/test/lux/type/unit.lux105
-rw-r--r--stdlib/source/test/lux/type/unit/scale.lux97
3 files changed, 111 insertions, 94 deletions
diff --git a/stdlib/source/test/lux/data/format/json.lux b/stdlib/source/test/lux/data/format/json.lux
index 2133f51f1..613767144 100644
--- a/stdlib/source/test/lux/data/format/json.lux
+++ b/stdlib/source/test/lux/data/format/json.lux
@@ -3,7 +3,6 @@
[lux (.except Variant Record)
["_" test (.only Test)]
["@" target]
- ["[0]" debug]
["[0]" meta]
[abstract
[codec (.except)]
@@ -87,7 +86,7 @@
(def: qty
(All (_ unit) (Random (unit.Qty unit)))
- (at random.monad each (debug.private unit.in') random.int))
+ (at random.monad each unit.quantity random.int))
(def: gen_record
(Random Record)
diff --git a/stdlib/source/test/lux/type/unit.lux b/stdlib/source/test/lux/type/unit.lux
index b4662133e..a4198429c 100644
--- a/stdlib/source/test/lux/type/unit.lux
+++ b/stdlib/source/test/lux/type/unit.lux
@@ -2,8 +2,6 @@
[library
[lux (.except)
["_" test (.only Test)]
- ["[0]" debug]
- ["[0]" meta]
[abstract
[monad (.only do)]
[equivalence (.only Equivalence)]
@@ -11,20 +9,18 @@
["$[0]" equivalence]
["$[0]" order]
["$[0]" enum]]]
- [macro
- [syntax (.only syntax)]
- ["[0]" code]]
[math
["[0]" random (.only Random)]
[number
- ["i" int]
- ["[0]" ratio (.open: "[1]#[0]" equivalence)]]]]]
+ ["i" int]]]]]
[\\library
- ["[0]" /]])
+ ["[0]" /]]
+ ["[0]" /
+ ["[1][0]" scale]])
(with_template [<name> <type> <unit>]
[(def: (<name> range)
- (-> Nat (Random (/.Qty <type>)))
+ (-> Nat (Random (/.Qty Any <type>)))
(|> random.int
(at random.monad each (i.% (.int range)))
(random.only (|>> (i.= +0) not))
@@ -66,100 +62,24 @@
[/.Litre /.litre]
[/.Second /.second]
))
- (_.coverage [/.Pure /.pure /.number]
+ (_.coverage [/.quantity /.number]
(|> expected
- /.pure
+ /.quantity
/.number
(i.= expected)))
(_.coverage [/.unit /.type]
(|> expected
(at ..what in)
- (is (/.Qty What))
+ (is (/.Qty Any What))
(at ..what out)
(i.= expected)))
)))))
-(def: natural
- (syntax (_ [])
- (at meta.monad each
- (|>> code.nat list)
- meta.seed)))
-
-(with_expansions [<from> (..natural)
- <to> (..natural)]
- (/.scale: How how
- [<from> <to>])
-
- (def: how::from <from>)
- (def: how::to <to>)
- )
-
-(def: scale
- Test
- (do [! random.monad]
- [small (|> random.int
- (at ! each (i.% +1,000))
- (at ! each (at /.meter in)))
- large (|> random.int
- (at ! each (i.% +1,000))
- (at ! each (i.* +1,000,000,000))
- (at ! each (at /.meter in)))
- .let [(open "meter#[0]") (is (Equivalence (/.Qty /.Meter))
- /.equivalence)]
- unscaled (|> random.int
- (at ! each (i.% +1,000))
- (at ! each (i.* (.int how::to)))
- (at ! each (at /.meter in)))]
- (_.for [/.Scale]
- (`` (all _.and
- (~~ (with_template [<type> <scale>]
- [(_.coverage [<type> <scale>]
- (|> large
- (at <scale> scale)
- (is (/.Qty (<type> /.Meter)))
- (at <scale> de_scale)
- (is (/.Qty /.Meter))
- (meter#= large)))]
-
- [/.Kilo /.kilo]
- [/.Mega /.mega]
- [/.Giga /.giga]
- ))
- (~~ (with_template [<type> <scale>]
- [(_.coverage [<type> <scale>]
- (|> small
- (at <scale> scale)
- (is (/.Qty (<type> /.Meter)))
- (at <scale> de_scale)
- (is (/.Qty /.Meter))
- (meter#= small)))]
-
- [/.Milli /.milli]
- [/.Micro /.micro]
- [/.Nano /.nano]
- ))
- (_.coverage [/.re_scaled]
- (|> large (is (/.Qty /.Meter))
- (at /.kilo scale) (is (/.Qty (/.Kilo /.Meter)))
- (/.re_scaled /.kilo /.milli) (is (/.Qty (/.Milli /.Meter)))
- (/.re_scaled /.milli /.kilo) (is (/.Qty (/.Kilo /.Meter)))
- (at /.kilo de_scale) (is (/.Qty /.Meter))
- (meter#= large)))
- (_.coverage [/.scale:]
- (and (|> unscaled
- (at ..how scale)
- (at ..how de_scale)
- (meter#= unscaled))
- (ratio#= [..how::from
- ..how::to]
- (at ..how ratio))))
- )))))
-
(def: arithmetic
Test
(do random.monad
[.let [zero (at /.meter in +0)
- (open "meter#[0]") (is (Equivalence (/.Qty /.Meter))
+ (open "meter#[0]") (is (Equivalence (/.Qty Any /.Meter))
/.equivalence)]
left (random.only (|>> (meter#= zero) not) (..meter 1,000))
right (..meter 1,000)
@@ -175,8 +95,8 @@
))
(_.coverage [/.*]
(let [expected (i.* (at /.meter out left) (at /.meter out right))
- actual ((debug.private /.out') (is (/.Qty [/.Meter /.Meter])
- (/.* left right)))]
+ actual (/.number (is (/.Qty Any [/.Meter /.Meter])
+ (/.* left right)))]
(i.= expected actual)))
(_.coverage [/./]
(|> right
@@ -192,6 +112,7 @@
(all _.and
..polymorphism
..unit
- ..scale
..arithmetic
+
+ /scale.test
)))
diff --git a/stdlib/source/test/lux/type/unit/scale.lux b/stdlib/source/test/lux/type/unit/scale.lux
new file mode 100644
index 000000000..569cdc0ba
--- /dev/null
+++ b/stdlib/source/test/lux/type/unit/scale.lux
@@ -0,0 +1,97 @@
+(.using
+ [library
+ [lux (.except)
+ ["_" test (.only Test)]
+ ["[0]" meta]
+ [abstract
+ [monad (.only do)]
+ [equivalence (.only Equivalence)]]
+ [macro
+ [syntax (.only syntax)]
+ ["[0]" code]]
+ [math
+ ["[0]" random (.only Random)]
+ [number
+ ["i" int]
+ ["[0]" ratio (.open: "[1]#[0]" equivalence)]]]]]
+ [\\library
+ ["[0]" / (.only)
+ ["/[1]" //]]])
+
+(def: natural
+ (syntax (_ [])
+ (at meta.monad each
+ (|>> code.nat list)
+ meta.seed)))
+
+(with_expansions [<from> (..natural)
+ <to> (..natural)]
+ (def: how (/.scale [ratio.#denominator <from> ratio.#numerator <to>]))
+ (def: How (/.type how))
+
+ (def: how::from <from>)
+ (def: how::to <to>)
+ )
+
+(def: .public test
+ Test
+ (<| (_.covering /._)
+ (_.for [/.Scale])
+ (do [! random.monad]
+ [small (|> random.int
+ (at ! each (i.% +1,000))
+ (at ! each (at //.meter in)))
+ large (|> random.int
+ (at ! each (i.% +1,000))
+ (at ! each (i.* +1,000,000,000))
+ (at ! each (at //.meter in)))
+ .let [(open "meter#[0]") (is (Equivalence (//.Qty Any //.Meter))
+ //.equivalence)]
+ unscaled (|> random.int
+ (at ! each (i.% +1,000))
+ (at ! each (i.* (.int how::to)))
+ (at ! each (at //.meter in)))]
+ (`` (all _.and
+ (~~ (with_template [<type> <scale>]
+ [(_.coverage [<type> <scale>]
+ (|> small
+ (at <scale> up)
+ (is (//.Qty <type> //.Meter))
+ (at <scale> down)
+ (is (//.Qty Any //.Meter))
+ (meter#= small)))]
+
+ [/.Kilo /.kilo]
+ [/.Mega /.mega]
+ [/.Giga /.giga]
+ ))
+ (~~ (with_template [<type> <scale>]
+ [(_.coverage [<type> <scale>]
+ (|> large
+ (at <scale> up)
+ (is (//.Qty <type> //.Meter))
+ (at <scale> down)
+ (is (//.Qty Any //.Meter))
+ (meter#= large)))]
+
+ [/.Milli /.milli]
+ [/.Micro /.micro]
+ [/.Nano /.nano]
+ ))
+ (_.coverage [/.re_scaled]
+ (|> large (is (//.Qty Any //.Meter))
+ (at /.kilo up) (is (//.Qty /.Kilo //.Meter))
+ (/.re_scaled /.kilo /.milli) (is (//.Qty /.Milli //.Meter))
+ (/.re_scaled /.milli /.kilo) (is (//.Qty /.Kilo //.Meter))
+ (at /.kilo down) (is (//.Qty Any //.Meter))
+ (meter#= large)))
+ (_.coverage [/.scale /.type]
+ (and (|> unscaled
+ (at ..how up)
+ (is (//.Qty How //.Meter))
+ (at ..how down)
+ (meter#= unscaled))
+ (ratio#= [ratio.#denominator ..how::from
+ ratio.#numerator ..how::to]
+ (at ..how ratio))))
+ )))))