aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/data/collection/dictionary.lux4
-rw-r--r--stdlib/source/lux/data/collection/dictionary/ordered.lux6
-rw-r--r--stdlib/source/lux/data/collection/set.lux4
-rw-r--r--stdlib/source/lux/data/collection/set/ordered.lux2
-rw-r--r--stdlib/source/lux/data/number/i16.lux7
-rw-r--r--stdlib/source/lux/data/number/i32.lux7
-rw-r--r--stdlib/source/lux/data/number/i64.lux40
-rw-r--r--stdlib/source/lux/data/number/i8.lux7
-rw-r--r--stdlib/source/lux/target/jvm/loader.lux2
-rw-r--r--stdlib/source/lux/tool/compiler/version.lux47
-rw-r--r--stdlib/source/lux/world/file/watch.lux3
-rw-r--r--stdlib/source/program/aedifex.lux5
-rw-r--r--stdlib/source/program/aedifex/cli.lux4
-rw-r--r--stdlib/source/program/aedifex/command/version.lux16
-rw-r--r--stdlib/source/test/aedifex.lux2
-rw-r--r--stdlib/source/test/aedifex/cli.lux3
-rw-r--r--stdlib/source/test/aedifex/command/deps.lux4
-rw-r--r--stdlib/source/test/aedifex/command/version.lux27
-rw-r--r--stdlib/source/test/aedifex/dependency/resolution.lux6
-rw-r--r--stdlib/source/test/lux/data/collection/dictionary.lux43
-rw-r--r--stdlib/source/test/lux/data/collection/dictionary/ordered.lux13
-rw-r--r--stdlib/source/test/lux/data/number/frac.lux40
-rw-r--r--stdlib/source/test/lux/data/number/i16.lux39
-rw-r--r--stdlib/source/test/lux/data/number/i32.lux39
-rw-r--r--stdlib/source/test/lux/data/number/i8.lux39
25 files changed, 275 insertions, 134 deletions
diff --git a/stdlib/source/lux/data/collection/dictionary.lux b/stdlib/source/lux/data/collection/dictionary.lux
index efb99a8b4..8ca61b453 100644
--- a/stdlib/source/lux/data/collection/dictionary.lux
+++ b/stdlib/source/lux/data/collection/dictionary.lux
@@ -574,8 +574,8 @@
(let [[Hash<k> node] dict]
(get' root-level (\ Hash<k> hash key) key Hash<k> node)))
-(def: #export (contains? key dict)
- (All [k v] (-> k (Dictionary k v) Bit))
+(def: #export (key? dict key)
+ (All [k v] (-> (Dictionary k v) k Bit))
(case (get key dict)
#.None #0
(#.Some _) #1))
diff --git a/stdlib/source/lux/data/collection/dictionary/ordered.lux b/stdlib/source/lux/data/collection/dictionary/ordered.lux
index b924a2e5d..c558a7669 100644
--- a/stdlib/source/lux/data/collection/dictionary/ordered.lux
+++ b/stdlib/source/lux/data/collection/dictionary/ordered.lux
@@ -75,8 +75,10 @@
(recur (get@ #right node))))
))))
-(def: #export (contains? key dict)
- (All [k v] (-> k (Dictionary k v) Bit))
+## TODO: Doing inneficient access of Order functions due to compiler bug.
+## TODO: Must improve it as soon as bug is fixed.
+(def: #export (key? dict key)
+ (All [k v] (-> (Dictionary k v) k Bit))
(let [## (^open "_\.") (get@ #&order dict)
]
(loop [node (get@ #root dict)]
diff --git a/stdlib/source/lux/data/collection/set.lux b/stdlib/source/lux/data/collection/set.lux
index 80cdf89a6..b47c5761d 100644
--- a/stdlib/source/lux/data/collection/set.lux
+++ b/stdlib/source/lux/data/collection/set.lux
@@ -35,9 +35,9 @@
(All [a] (-> a (Set a) (Set a)))
//.remove)
-(def: #export (member? set elem)
+(def: #export member?
(All [a] (-> (Set a) a Bit))
- (//.contains? elem set))
+ //.key?)
(def: #export to-list
(All [a] (-> (Set a) (List a)))
diff --git a/stdlib/source/lux/data/collection/set/ordered.lux b/stdlib/source/lux/data/collection/set/ordered.lux
index d350c1e9c..7a2584227 100644
--- a/stdlib/source/lux/data/collection/set/ordered.lux
+++ b/stdlib/source/lux/data/collection/set/ordered.lux
@@ -20,7 +20,7 @@
(def: #export (member? set elem)
(All [a] (-> (Set a) a Bit))
- (|> set :representation (/.contains? elem)))
+ (/.key? (:representation set) elem))
(template [<type> <name> <alias>]
[(def: #export <name>
diff --git a/stdlib/source/lux/data/number/i16.lux b/stdlib/source/lux/data/number/i16.lux
index 44fe0e988..4ca313730 100644
--- a/stdlib/source/lux/data/number/i16.lux
+++ b/stdlib/source/lux/data/number/i16.lux
@@ -15,6 +15,7 @@
..sub}
(I64 size)))
-(def: #export i16 (-> I64 I16) (get@ #i64.narrow ..sub))
-(def: #export i64 (-> I16 I64) (get@ #i64.wide ..sub))
-(def: #export equivalence (Equivalence I16) (get@ #i64.equivalence ..sub))
+(def: #export equivalence (Equivalence I16) (\ ..sub &equivalence))
+(def: #export width Nat (\ ..sub width))
+(def: #export i16 (-> I64 I16) (\ ..sub narrow))
+(def: #export i64 (-> I16 I64) (\ ..sub widen))
diff --git a/stdlib/source/lux/data/number/i32.lux b/stdlib/source/lux/data/number/i32.lux
index 560168f6f..35391519b 100644
--- a/stdlib/source/lux/data/number/i32.lux
+++ b/stdlib/source/lux/data/number/i32.lux
@@ -15,6 +15,7 @@
..sub}
(I64 size)))
-(def: #export i32 (-> I64 I32) (get@ #i64.narrow ..sub))
-(def: #export i64 (-> I32 I64) (get@ #i64.wide ..sub))
-(def: #export equivalence (Equivalence I32) (get@ #i64.equivalence ..sub))
+(def: #export equivalence (Equivalence I32) (\ ..sub &equivalence))
+(def: #export width Nat (\ ..sub width))
+(def: #export i32 (-> I64 I32) (\ ..sub narrow))
+(def: #export i64 (-> I32 I64) (\ ..sub widen))
diff --git a/stdlib/source/lux/data/number/i64.lux b/stdlib/source/lux/data/number/i64.lux
index 79bf7632d..249ae9046 100644
--- a/stdlib/source/lux/data/number/i64.lux
+++ b/stdlib/source/lux/data/number/i64.lux
@@ -143,25 +143,33 @@
[conjunction ..true ..and]
)
-(type: #export (Sub size)
- {#narrow (-> I64 (I64 size))
- #wide (-> (I64 size) I64)
- #equivalence (Equivalence (I64 size))})
+(signature: #export (Sub size)
+ (: (Equivalence (I64 size))
+ &equivalence)
+ (: Nat
+ width)
+ (: (-> I64 (I64 size))
+ narrow)
+ (: (-> (I64 size) I64)
+ widen))
(def: #export (sub width)
(Ex [size] (-> Nat (Maybe (Sub size))))
(if (.and (n.> 0 width)
(n.< ..width width))
- (let [top (dec width)
- shift (n.- width ..width)
- sign (..bit top)
- number (..mask (dec width))]
- (#.Some {#narrow (function (narrow value)
- (..or (|> value (..and ..sign) (..logic-right-shift shift))
- (|> value (..and number))))
- #wide (function (wide value)
- (|> (..or (|> value (..and sign) (..left-shift shift))
- (|> value (..clear top)))
- .i64))
- #equivalence ..equivalence}))
+ (let [sign-shift (n.- width ..width)
+ sign (..bit (dec width))
+ mantissa (..mask (dec width))
+ co-mantissa (..xor (.i64 -1) mantissa)]
+ (#.Some (: Sub
+ (structure
+ (def: &equivalence ..equivalence)
+ (def: width width)
+ (def: (narrow value)
+ (..or (|> value (..and ..sign) (..logic-right-shift sign-shift))
+ (|> value (..and mantissa))))
+ (def: (widen value)
+ (.i64 (case (.nat (..and sign value))
+ 0 value
+ _ (..or co-mantissa value))))))))
#.None))
diff --git a/stdlib/source/lux/data/number/i8.lux b/stdlib/source/lux/data/number/i8.lux
index a6475eb15..49b9cca95 100644
--- a/stdlib/source/lux/data/number/i8.lux
+++ b/stdlib/source/lux/data/number/i8.lux
@@ -15,6 +15,7 @@
..sub}
(I64 size)))
-(def: #export i8 (-> I64 I8) (get@ #i64.narrow ..sub))
-(def: #export i64 (-> I8 I64) (get@ #i64.wide ..sub))
-(def: #export equivalence (Equivalence I8) (get@ #i64.equivalence ..sub))
+(def: #export equivalence (Equivalence I8) (\ ..sub &equivalence))
+(def: #export width Nat (\ ..sub width))
+(def: #export i8 (-> I64 I8) (\ ..sub narrow))
+(def: #export i64 (-> I8 I64) (\ ..sub widen))
diff --git a/stdlib/source/lux/target/jvm/loader.lux b/stdlib/source/lux/target/jvm/loader.lux
index 74bfabc44..8f9f47e4f 100644
--- a/stdlib/source/lux/target/jvm/loader.lux
+++ b/stdlib/source/lux/target/jvm/loader.lux
@@ -130,7 +130,7 @@
(-> Text Binary Library (IO (Try Any)))
(do {! io.monad}
[library' (atom.read library)]
- (if (dictionary.contains? name library')
+ (if (dictionary.key? library' name)
(wrap (exception.throw ..already-stored name))
(do !
[_ (atom.update (dictionary.put name bytecode) library)]
diff --git a/stdlib/source/lux/tool/compiler/version.lux b/stdlib/source/lux/tool/compiler/version.lux
index 3965b9b28..df405e75d 100644
--- a/stdlib/source/lux/tool/compiler/version.lux
+++ b/stdlib/source/lux/tool/compiler/version.lux
@@ -1,5 +1,50 @@
(.module:
- [lux #*])
+ [lux #*
+ [data
+ [number
+ ["n" nat]]
+ [text
+ ["%" format]]]])
(type: #export Version
Nat)
+
+(def: range 100)
+
+(def: level
+ (n.% ..range))
+
+(def: current
+ (-> Nat Nat)
+ (|>>))
+
+(def: next
+ (n./ ..range))
+
+(def: #export patch
+ (-> Version Nat)
+ (|>> ..current ..level))
+
+(def: #export minor
+ (-> Version Nat)
+ (|>> ..next ..level))
+
+(def: #export major
+ (-> Version Nat)
+ (|>> ..next ..next ..level))
+
+(def: separator ".")
+
+(def: (padded value)
+ (-> Nat Text)
+ (if (n.< 10 value)
+ (%.format "0" (%.nat value))
+ (%.nat value)))
+
+(def: #export (format version)
+ (%.Format Version)
+ (%.format (..padded (..major version))
+ ..separator
+ (..padded (..minor version))
+ ..separator
+ (..padded (..patch version))))
diff --git a/stdlib/source/lux/world/file/watch.lux b/stdlib/source/lux/world/file/watch.lux
index a1bb5a6de..5d995bbd4 100644
--- a/stdlib/source/lux/world/file/watch.lux
+++ b/stdlib/source/lux/world/file/watch.lux
@@ -147,8 +147,7 @@
(do {! (try.with promise.monad)}
[current-files (..poll-files directory file-tracker)
#let [creations (if (..creation? concern)
- (list.filter (function (_ [path file last-modified])
- (not (dictionary.contains? path file-tracker)))
+ (list.filter (|>> product.left (dictionary.key? file-tracker) not)
current-files)
(list))
available (|> current-files
diff --git a/stdlib/source/program/aedifex.lux b/stdlib/source/program/aedifex.lux
index d876b5665..2478b4016 100644
--- a/stdlib/source/program/aedifex.lux
+++ b/stdlib/source/program/aedifex.lux
@@ -48,6 +48,7 @@
["#." dependency #_
["#" resolution (#+ Resolution)]]
["#." command (#+ Command)
+ ["#/." version]
["#/." clean]
["#/." pom]
["#/." install]
@@ -87,6 +88,10 @@
(case ?profile
(#try.Success profile)
(case operation
+ #/cli.Version
+ (exec (/command/version.do! profile)
+ (wrap []))
+
#/cli.Clean
(exec (/command/clean.do! (file.async file.default) profile)
(wrap []))
diff --git a/stdlib/source/program/aedifex/cli.lux b/stdlib/source/program/aedifex/cli.lux
index d52bf4df6..7af7405a9 100644
--- a/stdlib/source/program/aedifex/cli.lux
+++ b/stdlib/source/program/aedifex/cli.lux
@@ -32,6 +32,7 @@
(cli.this "test")))
(type: #export Command
+ #Version
#Clean
#POM
#Dependencies
@@ -43,6 +44,8 @@
(def: #export equivalence
(Equivalence Command)
($_ equivalence.sum
+ ## #Version
+ ..any-equivalence
## #Clean
..any-equivalence
## #POM
@@ -64,6 +67,7 @@
(def: command'
(Parser Command)
($_ <>.or
+ (cli.this "version")
(cli.this "clean")
(cli.this "pom")
(cli.this "deps")
diff --git a/stdlib/source/program/aedifex/command/version.lux b/stdlib/source/program/aedifex/command/version.lux
new file mode 100644
index 000000000..8f26a7fb7
--- /dev/null
+++ b/stdlib/source/program/aedifex/command/version.lux
@@ -0,0 +1,16 @@
+(.module:
+ [lux #*
+ [tool
+ [compiler
+ ["." version]
+ ["." language #_
+ ["#/." lux #_
+ ["#" version]]]]]]
+ ["." /// #_
+ [command (#+ Command)]
+ ["#." action]])
+
+(def: #export (do! profile)
+ (Command Any)
+ (\ ///action.monad wrap
+ (log! (version.format language/lux.version))))
diff --git a/stdlib/source/test/aedifex.lux b/stdlib/source/test/aedifex.lux
index 02d2b8ed2..9166a4367 100644
--- a/stdlib/source/test/aedifex.lux
+++ b/stdlib/source/test/aedifex.lux
@@ -9,6 +9,7 @@
["#." artifact]
["#." input]
["#." command #_
+ ["#/." version]
["#/." clean]
["#/." pom]
["#/." install]
@@ -36,6 +37,7 @@
($_ _.and
/artifact.test
/input.test
+ /command/version.test
/command/clean.test
/command/pom.test
/command/install.test
diff --git a/stdlib/source/test/aedifex/cli.lux b/stdlib/source/test/aedifex/cli.lux
index 805ccee03..c4c76f32f 100644
--- a/stdlib/source/test/aedifex/cli.lux
+++ b/stdlib/source/test/aedifex/cli.lux
@@ -29,6 +29,8 @@
(def: command
(Random /.Command)
($_ random.or
+ ## #Version
+ (random\wrap [])
## #Clean
(random\wrap [])
## #POM
@@ -56,6 +58,7 @@
(def: (format value)
(-> /.Command (List Text))
(case value
+ #/.Version (list "version")
#/.Clean (list "clean")
#/.POM (list "pom")
#/.Dependencies (list "deps")
diff --git a/stdlib/source/test/aedifex/command/deps.lux b/stdlib/source/test/aedifex/command/deps.lux
index 42739a5ff..2f221a7ce 100644
--- a/stdlib/source/test/aedifex/command/deps.lux
+++ b/stdlib/source/test/aedifex/command/deps.lux
@@ -82,7 +82,7 @@
(/.do! fs (list (///repository.mock ($///dependency/resolution.single depender-artifact depender-package) []))))]
(wrap (and (and (set.member? pre dependee-artifact)
(not (set.member? pre depender-artifact)))
- (and (dictionary.contains? dependee post)
- (dictionary.contains? depender post)))))]
+ (and (dictionary.key? post dependee)
+ (dictionary.key? post depender)))))]
(_.cover' [/.do!]
(try.default false verdict)))))))
diff --git a/stdlib/source/test/aedifex/command/version.lux b/stdlib/source/test/aedifex/command/version.lux
new file mode 100644
index 000000000..f6196556d
--- /dev/null
+++ b/stdlib/source/test/aedifex/command/version.lux
@@ -0,0 +1,27 @@
+(.module:
+ [lux #*
+ ["_" test (#+ Test)]
+ [abstract
+ [monad (#+ do)]]
+ [control
+ ["." try]
+ [concurrency
+ ["." promise]]]
+ [math
+ ["." random]]]
+ [///
+ ["@." profile]]
+ {#program
+ ["." /]})
+
+(def: #export test
+ Test
+ (<| (_.covering /._)
+ (do random.monad
+ [profile @profile.random]
+ (wrap (do promise.monad
+ [verdict (do (try.with promise.monad)
+ [_ (/.do! profile)]
+ (wrap true))]
+ (_.cover' [/.do!]
+ (try.default false verdict)))))))
diff --git a/stdlib/source/test/aedifex/dependency/resolution.lux b/stdlib/source/test/aedifex/dependency/resolution.lux
index b426a100d..0b3bf1634 100644
--- a/stdlib/source/test/aedifex/dependency/resolution.lux
+++ b/stdlib/source/test/aedifex/dependency/resolution.lux
@@ -346,9 +346,9 @@
(_.cover' [/.all]
(case resolution
(#try.Success resolution)
- (and (dictionary.contains? depender resolution)
- (dictionary.contains? dependee resolution)
- (not (dictionary.contains? ignored resolution)))
+ (and (dictionary.key? resolution depender)
+ (dictionary.key? resolution dependee)
+ (not (dictionary.key? resolution ignored)))
(#try.Failure error)
false))))
diff --git a/stdlib/source/test/lux/data/collection/dictionary.lux b/stdlib/source/test/lux/data/collection/dictionary.lux
index 718c9f0c9..b852f8dbf 100644
--- a/stdlib/source/test/lux/data/collection/dictionary.lux
+++ b/stdlib/source/test/lux/data/collection/dictionary.lux
@@ -2,6 +2,7 @@
[lux #*
["_" test (#+ Test)]
[abstract
+ [hash (#+ Hash)]
[monad (#+ do)]
["." equivalence]
{[0 #spec]
@@ -28,12 +29,14 @@
(def: for-dictionaries
Test
- (do random.monad
+ (do {! random.monad}
[#let [capped-nat (\ random.monad map (n.% 100) random.nat)]
size capped-nat
dict (random.dictionary n.hash size random.nat capped-nat)
- non-key (|> random.nat (random.filter (function (_ key) (not (/.contains? key dict)))))
- test-val (|> random.nat (random.filter (function (_ val) (not (list.member? n.equivalence (/.values dict) val)))))]
+ non-key (random.filter (|>> (/.key? dict) not)
+ random.nat)
+ test-val (random.filter (|>> (list.member? n.equivalence (/.values dict)) not)
+ random.nat)]
($_ _.and
(_.cover [/.size]
(n.= size (/.size dict)))
@@ -47,6 +50,16 @@
(let [sample (/.new n.hash)]
(and (n.= 0 (/.size sample))
(/.empty? sample))))
+
+ (do !
+ [constant random.nat
+ #let [hash (: (Hash Nat)
+ (structure
+ (def: &equivalence n.equivalence)
+ (def: (hash _)
+ constant)))]]
+ (_.cover [/.key-hash]
+ (is? hash (/.key-hash (/.new hash)))))
(_.cover [/.entries /.keys /.values]
(\ (list.equivalence (equivalence.product n.equivalence n.equivalence)) =
@@ -82,11 +95,13 @@
[#let [capped-nat (\ random.monad map (n.% 100) random.nat)]
size capped-nat
dict (random.dictionary n.hash size random.nat capped-nat)
- non-key (|> random.nat (random.filter (function (_ key) (not (/.contains? key dict)))))
- test-val (|> random.nat (random.filter (function (_ val) (not (list.member? n.equivalence (/.values dict) val)))))]
+ non-key (random.filter (|>> (/.key? dict) not)
+ random.nat)
+ test-val (random.filter (|>> (list.member? n.equivalence (/.values dict)) not)
+ random.nat)]
($_ _.and
- (_.cover [/.contains?]
- (list.every? (function (_ key) (/.contains? key dict))
+ (_.cover [/.key?]
+ (list.every? (/.key? dict)
(/.keys dict)))
(_.cover [/.get]
@@ -130,8 +145,8 @@
(_.cover [/.remove]
(and (let [base (/.put non-key test-val dict)]
- (and (/.contains? non-key base)
- (not (/.contains? non-key (/.remove non-key base)))))
+ (and (/.key? base non-key)
+ (not (/.key? (/.remove non-key base) non-key))))
(case (list.head (/.keys dict))
#.None
true
@@ -186,8 +201,8 @@
(let [first-key (|> dict /.keys list.head maybe.assume)
rebound (/.re-bind first-key non-key dict)]
(and (n.= (/.size dict) (/.size rebound))
- (/.contains? non-key rebound)
- (not (/.contains? first-key rebound))
+ (/.key? rebound non-key)
+ (not (/.key? rebound first-key))
(n.= (maybe.assume (/.get first-key dict))
(maybe.assume (/.get non-key rebound)))))))
)))
@@ -200,8 +215,10 @@
[#let [capped-nat (\ random.monad map (n.% 100) random.nat)]
size capped-nat
dict (random.dictionary n.hash size random.nat capped-nat)
- non-key (|> random.nat (random.filter (function (_ key) (not (/.contains? key dict)))))
- test-val (|> random.nat (random.filter (function (_ val) (not (list.member? n.equivalence (/.values dict) val)))))]
+ non-key (random.filter (|>> (/.key? dict) not)
+ random.nat)
+ test-val (random.filter (|>> (list.member? n.equivalence (/.values dict)) not)
+ random.nat)]
($_ _.and
(_.with-cover [/.equivalence]
($equivalence.spec (/.equivalence n.equivalence)
diff --git a/stdlib/source/test/lux/data/collection/dictionary/ordered.lux b/stdlib/source/test/lux/data/collection/dictionary/ordered.lux
index c34f3e3cf..01920fa1c 100644
--- a/stdlib/source/test/lux/data/collection/dictionary/ordered.lux
+++ b/stdlib/source/test/lux/data/collection/dictionary/ordered.lux
@@ -32,8 +32,7 @@
_
(do random.monad
[partial (dictionary order gen-key gen-value (dec size))
- key (random.filter (function (_ candidate)
- (not (/.contains? candidate partial)))
+ key (random.filter (|>> (/.key? partial) not)
gen-key)
value gen-value]
(wrap (/.put key value partial)))))
@@ -103,14 +102,14 @@
(|> sample
/.entries (/.from-list n.order)
(/\= sample)))
- (_.cover [/.contains?]
- (and (list.every? (function (_ key) (/.contains? key sample))
+ (_.cover [/.key?]
+ (and (list.every? (/.key? sample)
(/.keys sample))
- (not (/.contains? extra-key sample))))
+ (not (/.key? sample extra-key))))
(_.cover [/.put]
- (and (not (/.contains? extra-key sample))
+ (and (not (/.key? sample extra-key))
(let [sample+ (/.put extra-key extra-value sample)]
- (and (/.contains? extra-key sample+)
+ (and (/.key? sample+ extra-key)
(n.= (inc (/.size sample))
(/.size sample+))))))
(_.cover [/.get]
diff --git a/stdlib/source/test/lux/data/number/frac.lux b/stdlib/source/test/lux/data/number/frac.lux
index ca3d4d21c..b9669756d 100644
--- a/stdlib/source/test/lux/data/number/frac.lux
+++ b/stdlib/source/test/lux/data/number/frac.lux
@@ -10,7 +10,9 @@
["$." monoid]
["$." codec]]}]
[data
- ["." bit ("#\." equivalence)]]
+ ["." bit ("#\." equivalence)]
+ [text
+ ["%" format (#+ format)]]]
[math
["." random (#+ Random)]]]
{1
@@ -32,14 +34,15 @@
($equivalence.spec /.equivalence random.safe-frac))
(_.with-cover [/.order /.<]
($order.spec /.order random.safe-frac))
- (~~ (template [<monoid> <compose>]
+ (~~ (template [<compose> <monoid>]
[(_.with-cover [<monoid> <compose>]
($monoid.spec /.equivalence <monoid> ..random))]
- [/.addition /.+]
- [/.multiplication /.*]
- [/.minimum /.min]
- [/.maximum /.max]
+ [/.+ /.addition]
+ [/.* /.multiplication]
+
+ [/.min /.minimum]
+ [/.max /.maximum]
))
(~~ (template [<codec>]
[(_.with-cover [<codec>]
@@ -161,16 +164,21 @@
(/.* (/.signum sample) sample)))))
(do random.monad
[expected random.frac]
- ($_ _.and
- (_.cover [/.to-bits /.from-bits]
- (let [actual (|> expected /.to-bits /.from-bits)]
- (or (/.= expected actual)
- (and (/.not-a-number? expected)
- (/.not-a-number? actual)))))
- (_.cover [/.negate]
- (and (/.= +0.0 (/.+ (/.negate expected) expected))
- (|> expected /.negate /.negate (/.= expected))))
- ))
+ (_.cover [/.to-bits /.from-bits]
+ (let [actual (|> expected /.to-bits /.from-bits)]
+ (or (/.= expected actual)
+ (and (/.not-a-number? expected)
+ (/.not-a-number? actual))))))
+ (do random.monad
+ [expected random.safe-frac]
+ (_.cover [/.negate]
+ (let [subtraction!
+ (/.= +0.0 (/.+ (/.negate expected) expected))
+
+ inverse!
+ (|> expected /.negate /.negate (/.= expected))]
+ (and subtraction!
+ inverse!))))
..signature
..constant
diff --git a/stdlib/source/test/lux/data/number/i16.lux b/stdlib/source/test/lux/data/number/i16.lux
index f3d8030c0..038d6d7f2 100644
--- a/stdlib/source/test/lux/data/number/i16.lux
+++ b/stdlib/source/test/lux/data/number/i16.lux
@@ -1,39 +1,40 @@
(.module:
[lux #*
["_" test (#+ Test)]
- [data
- ["." name]
- ["%" text/format (#+ format)]]
[abstract
[monad (#+ do)]
{[0 #spec]
[/
["$." equivalence]]}]
+ [data
+ [number
+ ["i" int]]]
[math
- ["r" random (#+ Random)]]]
+ ["." random (#+ Random)]]]
{1
["." /
["/#" // #_
- ["#." i64 (#+ Mask)]]]})
+ ["#." i64]]]})
-(def: #export i16
+(def: #export random
(Random /.I16)
- (\ r.functor map /.i16 r.i64))
-
-(def: mask
- Mask
- (//i64.or //i64.sign
- (//i64.mask 15)))
+ (\ random.functor map /.i16 random.i64))
(def: #export test
Test
- (<| (_.context (name.module (name-of /._)))
- (do {! r.monad}
- [expected (\ ! map (|>> (//i64.and ..mask) (: I64)) r.i64)]
+ (<| (_.covering /._)
+ (_.with-cover [/.I16])
+ (do {! random.monad}
+ [#let [limit (|> (dec /.width)
+ //i64.mask
+ .int
+ inc)]
+ expected (\ ! map (i.% limit) random.int)]
($_ _.and
- ($equivalence.spec /.equivalence ..i16)
+ (_.with-cover [/.equivalence]
+ ($equivalence.spec /.equivalence ..random))
- (_.test "Can convert between I64 and I16"
- (let [actual (|> expected /.i16 /.i64)]
- (\ //i64.equivalence = expected actual)))
+ (_.cover [/.i16 /.i64 /.width]
+ (let [actual (|> expected .i64 /.i16 /.i64)]
+ (\ //i64.equivalence = expected actual)))
))))
diff --git a/stdlib/source/test/lux/data/number/i32.lux b/stdlib/source/test/lux/data/number/i32.lux
index 1bf6bfee7..11dd6f3f9 100644
--- a/stdlib/source/test/lux/data/number/i32.lux
+++ b/stdlib/source/test/lux/data/number/i32.lux
@@ -1,39 +1,40 @@
(.module:
[lux #*
["_" test (#+ Test)]
- [data
- ["." name]
- ["%" text/format (#+ format)]]
[abstract
[monad (#+ do)]
{[0 #spec]
[/
["$." equivalence]]}]
+ [data
+ [number
+ ["i" int]]]
[math
- ["r" random (#+ Random)]]]
+ ["." random (#+ Random)]]]
{1
["." /
["/#" // #_
- ["#." i64 (#+ Mask)]]]})
+ ["#." i64]]]})
-(def: #export i32
+(def: #export random
(Random /.I32)
- (\ r.functor map /.i32 r.i64))
-
-(def: mask
- Mask
- (//i64.or //i64.sign
- (//i64.mask 31)))
+ (\ random.functor map /.i32 random.i64))
(def: #export test
Test
- (<| (_.context (name.module (name-of /._)))
- (do {! r.monad}
- [expected (\ ! map (|>> (//i64.and ..mask) (: I64)) r.i64)]
+ (<| (_.covering /._)
+ (_.with-cover [/.I32])
+ (do {! random.monad}
+ [#let [limit (|> (dec /.width)
+ //i64.mask
+ .int
+ inc)]
+ expected (\ ! map (i.% limit) random.int)]
($_ _.and
- ($equivalence.spec /.equivalence ..i32)
+ (_.with-cover [/.equivalence]
+ ($equivalence.spec /.equivalence ..random))
- (_.test "Can convert between I64 and I32"
- (let [actual (|> expected /.i32 /.i64)]
- (\ //i64.equivalence = expected actual)))
+ (_.cover [/.i32 /.i64 /.width]
+ (let [actual (|> expected .i64 /.i32 /.i64)]
+ (\ //i64.equivalence = expected actual)))
))))
diff --git a/stdlib/source/test/lux/data/number/i8.lux b/stdlib/source/test/lux/data/number/i8.lux
index 88f456bca..b855ac1e0 100644
--- a/stdlib/source/test/lux/data/number/i8.lux
+++ b/stdlib/source/test/lux/data/number/i8.lux
@@ -1,39 +1,40 @@
(.module:
[lux #*
["_" test (#+ Test)]
- [data
- ["." name]
- ["%" text/format (#+ format)]]
[abstract
[monad (#+ do)]
{[0 #spec]
[/
["$." equivalence]]}]
+ [data
+ [number
+ ["i" int]]]
[math
- ["r" random (#+ Random)]]]
+ ["." random (#+ Random)]]]
{1
["." /
["/#" // #_
- ["#." i64 (#+ Mask)]]]})
+ ["#." i64]]]})
-(def: #export i8
+(def: #export random
(Random /.I8)
- (\ r.functor map /.i8 r.i64))
-
-(def: mask
- Mask
- (//i64.or //i64.sign
- (//i64.mask 7)))
+ (\ random.functor map /.i8 random.i64))
(def: #export test
Test
- (<| (_.context (name.module (name-of /._)))
- (do {! r.monad}
- [expected (\ ! map (|>> (//i64.and ..mask) (: I64)) r.i64)]
+ (<| (_.covering /._)
+ (_.with-cover [/.I8])
+ (do {! random.monad}
+ [#let [limit (|> (dec /.width)
+ //i64.mask
+ .int
+ inc)]
+ expected (\ ! map (i.% limit) random.int)]
($_ _.and
- ($equivalence.spec /.equivalence ..i8)
+ (_.with-cover [/.equivalence]
+ ($equivalence.spec /.equivalence ..random))
- (_.test "Can convert between I64 and I8"
- (let [actual (|> expected /.i8 /.i64)]
- (\ //i64.equivalence = expected actual)))
+ (_.cover [/.i8 /.i64 /.width]
+ (let [actual (|> expected .i64 /.i8 /.i64)]
+ (\ //i64.equivalence = expected actual)))
))))