aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/test/aedifex/command/pom.lux2
-rw-r--r--stdlib/source/test/aedifex/input.lux2
-rw-r--r--stdlib/source/test/lux/control/parser/binary.lux15
-rw-r--r--stdlib/source/test/lux/data/collection/sequence.lux184
-rw-r--r--stdlib/source/test/lux/world/file.lux30
5 files changed, 128 insertions, 105 deletions
diff --git a/stdlib/source/test/aedifex/command/pom.lux b/stdlib/source/test/aedifex/command/pom.lux
index 1bb098de0..cd0eed8e9 100644
--- a/stdlib/source/test/aedifex/command/pom.lux
+++ b/stdlib/source/test/aedifex/command/pom.lux
@@ -33,7 +33,7 @@
(<| (_.covering /._)
(do random.monad
[sample @profile.random
- #let [fs (file.mock (:: file.system separator))]]
+ #let [fs (file.mock (:: file.default separator))]]
(wrap (do {@ promise.monad}
[outcome (/.do! fs sample)]
(case outcome
diff --git a/stdlib/source/test/aedifex/input.lux b/stdlib/source/test/aedifex/input.lux
index 39a71eb81..50b99a218 100644
--- a/stdlib/source/test/aedifex/input.lux
+++ b/stdlib/source/test/aedifex/input.lux
@@ -34,7 +34,7 @@
(do {@ random.monad}
[expected (:: @ map (set@ #//.parents (list)) @profile.random)
#let [fs (: (file.System Promise)
- (file.mock (:: file.system separator)))]]
+ (file.mock (:: file.default separator)))]]
(wrap (do promise.monad
[verdict (do //action.monad
[file (: (Promise (Try (File Promise)))
diff --git a/stdlib/source/test/lux/control/parser/binary.lux b/stdlib/source/test/lux/control/parser/binary.lux
index 11875d19f..98b8bab90 100644
--- a/stdlib/source/test/lux/control/parser/binary.lux
+++ b/stdlib/source/test/lux/control/parser/binary.lux
@@ -100,7 +100,7 @@
random.nat
random.int
random.rev
- random.frac
+ random.safe-frac
..random-text
..random-name
..random-name
@@ -213,8 +213,17 @@
[/.bit format.bit random.bit bit.equivalence]
[/.nat format.nat random.nat n.equivalence]
[/.int format.int random.int int.equivalence]
- [/.rev format.rev random.rev rev.equivalence]
- [/.frac format.frac random.frac frac.equivalence]))
+ [/.rev format.rev random.rev rev.equivalence]))
+ (do {@ random.monad}
+ [expected random.frac]
+ (_.cover [/.frac]
+ (|> expected
+ (format.run format.frac)
+ (/.run /.frac)
+ (!expect (^multi (#try.Success actual)
+ (or (:: frac.equivalence = expected actual)
+ (and (frac.not-a-number? expected)
+ (frac.not-a-number? actual))))))))
(do {@ random.monad}
[expected (:: @ map (|>> (i64.and (i64.mask /.size/8))
(n.max 2))
diff --git a/stdlib/source/test/lux/data/collection/sequence.lux b/stdlib/source/test/lux/data/collection/sequence.lux
index f47629d70..3cd41c4b2 100644
--- a/stdlib/source/test/lux/data/collection/sequence.lux
+++ b/stdlib/source/test/lux/data/collection/sequence.lux
@@ -1,102 +1,116 @@
(.module:
[lux #*
- ["%" data/text/format (#+ format)]
["_" test (#+ Test)]
[abstract
- comonad
+ [comonad (#+)]
[functor (#+)]
[monad (#+ do)]
- ["." enum]]
+ [equivalence (#+ Equivalence)]
+ ["." enum]
+ {[0 #spec]
+ [/
+ ["$." functor]
+ ["$." comonad]]}]
[data
- ["." maybe]
[number
- ["n" nat ("#@." decimal)]]
- ["." text ("#@." monoid)]
+ ["n" nat]]
+ ["." text
+ ["%" format (#+ format)]]
[collection
- ["." list]]]
+ ["." list ("#@." functor)]]]
[math
- ["r" random]]]
+ ["." random]]]
{1
["." /]})
+(structure: (equivalence super)
+ (All [a] (-> (Equivalence a) (Equivalence (/.Sequence a))))
+
+ (def: (= reference subject)
+ (:: (list.equivalence super) =
+ (/.take 100 reference)
+ (/.take 100 subject))))
+
(def: #export test
Test
- (<| (_.context (%.name (name-of /.Sequence)))
- (do {@ r.monad}
- [size (|> r.nat (:: @ map (|>> (n.% 100) (n.max 2))))
- offset (|> r.nat (:: @ map (n.% 100)))
- factor (|> r.nat (:: @ map (|>> (n.% 100) (n.max 2))))
- elem r.nat
- cycle-seed (r.list size r.nat)
- cycle-sample-idx (|> r.nat (:: @ map (n.% 1000)))
- #let [(^open "list@.") (list.equivalence n.equivalence)
- sample0 (/.iterate inc 0)
- sample1 (/.iterate inc offset)]]
+ (<| (_.covering /._)
+ (_.with-cover [/.Sequence])
+ (let [(^open "list@.") (list.equivalence n.equivalence)])
+ (do {@ random.monad}
+ [repeated random.nat
+ index (:: @ map (n.% 100) random.nat)
+ size (:: @ map (|>> (n.% 10) inc) random.nat)
+ offset (:: @ map (n.% 100) random.nat)
+ cycle-start random.nat
+ cycle-next (random.list size random.nat)]
($_ _.and
- (_.test "Can move along a sequence and take slices off it."
- (and (and (list@= (enum.range n.enum 0 (dec size))
- (/.take size sample0))
- (list@= (enum.range n.enum offset (dec (n.+ offset size)))
- (/.take size (/.drop offset sample0)))
- (let [[drops takes] (/.split size sample0)]
- (and (list@= (enum.range n.enum 0 (dec size))
- drops)
- (list@= (enum.range n.enum size (dec (n.* 2 size)))
- (/.take size takes)))))
- (and (list@= (enum.range n.enum 0 (dec size))
- (/.take-while (n.< size) sample0))
- (list@= (enum.range n.enum offset (dec (n.+ offset size)))
- (/.take-while (n.< (n.+ offset size))
- (/.drop-while (n.< offset) sample0)))
- (let [[drops takes] (/.split-while (n.< size) sample0)]
- (and (list@= (enum.range n.enum 0 (dec size))
- drops)
- (list@= (enum.range n.enum size (dec (n.* 2 size)))
- (/.take-while (n.< (n.* 2 size)) takes)))))
- ))
- (_.test "Can repeat any element and infinite number of times."
- (n.= elem (/.nth offset (/.repeat elem))))
- (_.test "Can obtain the head & tail of a sequence."
- (and (n.= offset (/.head sample1))
- (list@= (enum.range n.enum (inc offset) (n.+ offset size))
- (/.take size (/.tail sample1)))))
- (_.test "Can filter sequences."
- (and (n.= (n.* 2 offset)
- (/.nth offset
- (/.filter n.even? sample0)))
- (let [[evens odds] (/.partition n.even? (/.iterate inc 0))]
- (and (n.= (n.* 2 offset)
- (/.nth offset evens))
- (n.= (inc (n.* 2 offset))
- (/.nth offset odds))))))
- (_.test "Functor goes over 'all' elements in a sequence."
- (let [(^open "/@.") /.functor
- there (/@map (n.* factor) sample0)
- back-again (/@map (n./ factor) there)]
- (and (not (list@= (/.take size sample0)
- (/.take size there)))
- (list@= (/.take size sample0)
- (/.take size back-again)))))
- (_.test "CoMonad produces a value for every element in a sequence."
- (let [(^open "/@.") /.functor]
- (list@= (/.take size (/@map (n.* factor) sample1))
- (/.take size
- (be /.comonad
- [inputs sample1]
- (n.* factor (/.head inputs)))))))
- (_.test "'unfold' generalizes 'iterate'."
- (let [(^open "/@.") /.functor
- (^open "list@.") (list.equivalence text.equivalence)]
- (list@= (/.take size
- (/@map n@encode (/.iterate inc offset)))
- (/.take size
- (/.unfold (function (_ n) [(inc n) (n@encode n)])
- offset)))))
- (_.test "Can cycle over the same elements as an infinite sequence."
- (|> (/.cycle cycle-seed)
- maybe.assume
- (/.nth cycle-sample-idx)
- (n.= (|> cycle-seed
- (list.nth (n.% size cycle-sample-idx))
- maybe.assume))))
+ (_.with-cover [/.functor]
+ ($functor.spec /.repeat ..equivalence /.functor))
+ (_.with-cover [/.comonad]
+ ($comonad.spec /.repeat ..equivalence /.comonad))
+
+ (_.cover [/.iterate /.nth]
+ (n.= (n.+ offset index)
+ (/.nth index (/.iterate inc offset))))
+ (_.cover [/.repeat]
+ (n.= repeated
+ (/.nth index (/.repeat repeated))))
+ (_.cover [/.take]
+ (list@= (enum.range n.enum offset (dec (n.+ size offset)))
+ (/.take size (/.iterate inc offset))))
+ (_.cover [/.drop]
+ (list@= (enum.range n.enum offset (dec (n.+ size offset)))
+ (/.take size (/.drop offset (/.iterate inc 0)))))
+ (_.cover [/.split]
+ (let [[drops takes] (/.split size (/.iterate inc 0))]
+ (and (list@= (enum.range n.enum 0 (dec size))
+ drops)
+ (list@= (enum.range n.enum size (dec (n.* 2 size)))
+ (/.take size takes)))))
+ (_.cover [/.take-while]
+ (list@= (enum.range n.enum 0 (dec size))
+ (/.take-while (n.< size) (/.iterate inc 0))))
+ (_.cover [/.drop-while]
+ (list@= (enum.range n.enum offset (dec (n.+ size offset)))
+ (/.take-while (n.< (n.+ size offset))
+ (/.drop-while (n.< offset) (/.iterate inc 0)))))
+ (_.cover [/.split-while]
+ (let [[drops takes] (/.split-while (n.< size) (/.iterate inc 0))]
+ (and (list@= (enum.range n.enum 0 (dec size))
+ drops)
+ (list@= (enum.range n.enum size (dec (n.* 2 size)))
+ (/.take-while (n.< (n.* 2 size)) takes)))))
+ (_.cover [/.head]
+ (n.= offset
+ (/.head (/.iterate inc offset))))
+ (_.cover [/.tail]
+ (list@= (enum.range n.enum (inc offset) (n.+ size offset))
+ (/.take size (/.tail (/.iterate inc offset)))))
+ (_.cover [/.filter]
+ (list@= (list@map (n.* 2) (enum.range n.enum 0 (dec size)))
+ (/.take size (/.filter n.even? (/.iterate inc 0)))))
+ (_.cover [/.partition]
+ (let [[evens odds] (/.partition n.even? (/.iterate inc 0))]
+ (and (n.= (n.* 2 offset)
+ (/.nth offset evens))
+ (n.= (inc (n.* 2 offset))
+ (/.nth offset odds)))))
+ (_.cover [/.unfold]
+ (let [(^open "/@.") /.functor
+ (^open "list@.") (list.equivalence text.equivalence)]
+ (list@= (/.take size
+ (/@map %.nat (/.iterate inc offset)))
+ (/.take size
+ (/.unfold (function (_ n) [(inc n) (%.nat n)])
+ offset)))))
+ (_.cover [/.cycle]
+ (let [cycle (list& cycle-start cycle-next)]
+ (list@= (list.concat (list.repeat size cycle))
+ (/.take (n.* size (list.size cycle))
+ (/.cycle [cycle-start cycle-next])))))
+ (_.cover [/.^sequence&]
+ (let [(/.^sequence& first second third next) (/.iterate inc offset)]
+ (and (n.= offset first)
+ (n.= (n.+ 1 offset) second)
+ (n.= (n.+ 2 offset) third))))
))))
diff --git a/stdlib/source/test/lux/world/file.lux b/stdlib/source/test/lux/world/file.lux
index 9dc1fb2e2..a1146fe56 100644
--- a/stdlib/source/test/lux/world/file.lux
+++ b/stdlib/source/test/lux/world/file.lux
@@ -39,9 +39,9 @@
result (promise.future
(do (try.with io.monad)
[#let [check-existence! (: (IO (Try Bit))
- (try.lift io.monad (/.exists? io.monad /.system path)))]
+ (try.lift io.monad (/.exists? io.monad /.default path)))]
pre! check-existence!
- file (!.use (:: /.system create-file) path)
+ file (!.use (:: /.default create-file) path)
post! check-existence!
_ (!.use (:: file delete) [])
remains? check-existence!]
@@ -57,7 +57,7 @@
[#let [path (format "temp_file_" (%.nat number))]
result (promise.future
(do (try.with io.monad)
- [file (!.use (:: /.system create-file) path)
+ [file (!.use (:: /.default create-file) path)
_ (!.use (:: file over-write) data)
content (!.use (:: file content) [])
_ (!.use (:: file delete) [])]
@@ -84,7 +84,7 @@
[#let [path "temp_file_2"]
result (promise.future
(do (try.with io.monad)
- [file (!.use (:: /.system create-file) path)
+ [file (!.use (:: /.default create-file) path)
_ (!.use (:: file over-write) dataL)
read-size (!.use (:: file size) [])
_ (!.use (:: file delete) [])]
@@ -95,7 +95,7 @@
[#let [path "temp_file_3"]
result (promise.future
(do (try.with io.monad)
- [file (!.use (:: /.system create-file) path)
+ [file (!.use (:: /.default create-file) path)
_ (!.use (:: file over-write) dataL)
_ (!.use (:: file append) dataR)
content (!.use (:: file content) [])
@@ -115,9 +115,9 @@
result (promise.future
(do (try.with io.monad)
[#let [check-existence! (: (IO (Try Bit))
- (try.lift io.monad (/.exists? io.monad /.system path)))]
+ (try.lift io.monad (/.exists? io.monad /.default path)))]
pre! check-existence!
- dir (!.use (:: /.system create-directory) path)
+ dir (!.use (:: /.default create-directory) path)
post! check-existence!
_ (!.use (:: dir discard) [])
remains? check-existence!]
@@ -131,8 +131,8 @@
dir-path "temp_dir_5"]
result (promise.future
(do (try.with io.monad)
- [dir (!.use (:: /.system create-directory) dir-path)
- file (!.use (:: /.system create-file) (format dir-path "/" file-path))
+ [dir (!.use (:: /.default create-directory) dir-path)
+ file (!.use (:: /.default create-file) (format dir-path "/" file-path))
_ (!.use (:: file over-write) dataL)
read-size (!.use (:: file size) [])
_ (!.use (:: file delete) [])
@@ -146,12 +146,12 @@
inner-dir-path "inner_temp_dir_6"]
result (promise.future
(do (try.with io.monad)
- [dir (!.use (:: /.system create-directory) dir-path)
+ [dir (!.use (:: /.default create-directory) dir-path)
pre-files (!.use (:: dir files) [])
pre-directories (!.use (:: dir directories) [])
- file (!.use (:: /.system create-file) (format dir-path "/" file-path))
- inner-dir (!.use (:: /.system create-directory) (format dir-path "/" inner-dir-path))
+ file (!.use (:: /.default create-file) (format dir-path "/" file-path))
+ inner-dir (!.use (:: /.default create-directory) (format dir-path "/" inner-dir-path))
post-files (!.use (:: dir files) [])
post-directories (!.use (:: dir directories) [])
@@ -168,7 +168,7 @@
[#let [path "temp_file_7"]
result (promise.future
(do (try.with io.monad)
- [file (!.use (:: /.system create-file) path)
+ [file (!.use (:: /.default create-file) path)
_ (!.use (:: file over-write) dataL)
_ (!.use (:: file modify) new-modified)
current-modified (!.use (:: file last-modified) [])
@@ -182,9 +182,9 @@
result (promise.future
(do (try.with io.monad)
[#let [check-existence! (: (-> Path (IO (Try Bit)))
- (|>> (/.exists? io.monad /.system)
+ (|>> (/.exists? io.monad /.default)
(try.lift io.monad)))]
- file0 (!.use (:: /.system create-file) path0)
+ file0 (!.use (:: /.default create-file) path0)
_ (!.use (:: file0 over-write) dataL)
pre! (check-existence! path0)
file1 (: (IO (Try (File IO))) ## TODO: Remove :