From 92dca9f487c625d27f6c291784ef709b0cc13a72 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 26 Dec 2020 04:34:11 -0400 Subject: Some renamings. --- stdlib/source/test/aedifex/cache.lux | 12 +- stdlib/source/test/aedifex/command/deps.lux | 9 +- .../source/test/aedifex/dependency/resolution.lux | 9 +- stdlib/source/test/aedifex/repository.lux | 3 + stdlib/source/test/aedifex/repository/identity.lux | 3 - stdlib/source/test/aedifex/repository/origin.lux | 27 +++ stdlib/source/test/lux.lux | 84 ++++---- stdlib/source/test/lux/control/concurrency/frp.lux | 78 ++++---- .../test/lux/control/concurrency/promise.lux | 2 +- stdlib/source/test/lux/control/remember.lux | 4 +- stdlib/source/test/lux/data/number/int.lux | 16 ++ stdlib/source/test/lux/data/number/nat.lux | 3 + stdlib/source/test/lux/math/modular.lux | 214 +++++++++------------ stdlib/source/test/lux/math/modulus.lux | 9 +- stdlib/source/test/lux/time/duration.lux | 4 +- 15 files changed, 258 insertions(+), 219 deletions(-) create mode 100644 stdlib/source/test/aedifex/repository/origin.lux (limited to 'stdlib/source/test') diff --git a/stdlib/source/test/aedifex/cache.lux b/stdlib/source/test/aedifex/cache.lux index c4c2d044f..bc436733b 100644 --- a/stdlib/source/test/aedifex/cache.lux +++ b/stdlib/source/test/aedifex/cache.lux @@ -40,7 +40,9 @@ ["#." dependency (#+ Dependency) ["#/." resolution (#+ Resolution)]] ["#." artifact (#+ Artifact) - ["#/." type (#+ Type)]]]]}) + ["#/." type (#+ Type)]] + ["#." repository #_ + ["#/." origin]]]]}) (def: type (Random Type) @@ -72,7 +74,7 @@ content ..content] (wrap [{#//dependency.artifact identity #//dependency.type type} - (set@ #//package.origin #//package.Remote (//package.local pom content))]))) + (set@ #//package.origin (#//repository/origin.Remote "") (//package.local pom content))]))) (def: resolution (Random Resolution) @@ -92,7 +94,7 @@ ..profile) content ..content] (wrap [dependency - (set@ #//package.origin #//package.Remote (//package.local pom content))])))))] + (set@ #//package.origin (#//repository/origin.Remote "") (//package.local pom content))])))))] (wrap (dictionary.from_list //dependency.hash (list& [main_dependency main_package] dependencies))))) (def: singular @@ -113,7 +115,7 @@ [_ wrote! actual_package read!] (wrap (\ //package.equivalence = - (set@ #//package.origin #//package.Local expected_package) + (set@ #//package.origin (#//repository/origin.Local "") expected_package) actual_package))))))))) (def: plural @@ -135,7 +137,7 @@ actual read!] (wrap (\ //dependency/resolution.equivalence = (\ dictionary.functor map - (set@ #//package.origin #//package.Local) + (set@ #//package.origin (#//repository/origin.Local "")) expected) actual))))))))) diff --git a/stdlib/source/test/aedifex/command/deps.lux b/stdlib/source/test/aedifex/command/deps.lux index 7002238e7..08345a0cb 100644 --- a/stdlib/source/test/aedifex/command/deps.lux +++ b/stdlib/source/test/aedifex/command/deps.lux @@ -40,12 +40,13 @@ ["#." pom] ["#." package] ["#." cache] - ["#." repository] ["#." artifact ["#/." type]] ["#." dependency ["#/." resolution] - ["#/." status]]]]]}) + ["#/." status]] + ["#." repository + ["#/." origin]]]]]}) (def: #export test Test @@ -78,10 +79,10 @@ try.assume) dependee_package (|> dependee_package - (set@ #///package.origin #///package.Remote) + (set@ #///package.origin (#///repository/origin.Remote "")) (set@ #///package.pom [dependee_pom #///dependency/status.Unverified])) depender_package (|> depender_package - (set@ #///package.origin #///package.Remote) + (set@ #///package.origin (#///repository/origin.Remote "")) (set@ #///package.pom [depender_pom #///dependency/status.Unverified])) fs (file.mock (\ file.default separator)) diff --git a/stdlib/source/test/aedifex/dependency/resolution.lux b/stdlib/source/test/aedifex/dependency/resolution.lux index 5f262bce4..4404cb32f 100644 --- a/stdlib/source/test/aedifex/dependency/resolution.lux +++ b/stdlib/source/test/aedifex/dependency/resolution.lux @@ -38,13 +38,14 @@ ["#" profile] ["#." package (#+ Package)] ["#." hash] - ["#." repository (#+ Simulation)] ["#." dependency ["#/." status]] ["#." pom] ["#." artifact (#+ Artifact) ["#/." type] - ["#/." extension]]]]}) + ["#/." extension]] + ["#." repository (#+ Simulation) + ["#/." origin]]]]}) (def: random (Random /.Resolution) @@ -178,7 +179,7 @@ (case actual_package (#try.Success actual_package) (\ ///package.equivalence = - (set@ #///package.origin #///package.Remote expected_package) + (set@ #///package.origin (#///repository/origin.Remote "") expected_package) actual_package) (#try.Failure _) @@ -291,7 +292,7 @@ (case actual_package (#try.Success actual_package) (\ ///package.equivalence = - (set@ #///package.origin #///package.Remote expected_package) + (set@ #///package.origin (#///repository/origin.Remote "") expected_package) actual_package) (#try.Failure _) diff --git a/stdlib/source/test/aedifex/repository.lux b/stdlib/source/test/aedifex/repository.lux index 7b99d080f..df8db3e88 100644 --- a/stdlib/source/test/aedifex/repository.lux +++ b/stdlib/source/test/aedifex/repository.lux @@ -23,6 +23,7 @@ ["." uri (#+ URI)]]]] ["." / #_ ["#." identity] + ["#." origin] [// ["@." artifact]]] {#spec @@ -69,5 +70,7 @@ ($/.spec (..artifact "1.2.3-YES") (..artifact "4.5.6-NO") (/.mock ..simulation ..empty))) + /identity.test + /origin.test ))) diff --git a/stdlib/source/test/aedifex/repository/identity.lux b/stdlib/source/test/aedifex/repository/identity.lux index 98d798cf7..d2a7ce185 100644 --- a/stdlib/source/test/aedifex/repository/identity.lux +++ b/stdlib/source/test/aedifex/repository/identity.lux @@ -5,9 +5,6 @@ {[0 #spec] [/ ["$." equivalence]]}] - [data - ["." product] - ["." text]] [math ["." random (#+ Random)]]] {#program diff --git a/stdlib/source/test/aedifex/repository/origin.lux b/stdlib/source/test/aedifex/repository/origin.lux new file mode 100644 index 000000000..4242a318a --- /dev/null +++ b/stdlib/source/test/aedifex/repository/origin.lux @@ -0,0 +1,27 @@ +(.module: + [lux #* + ["_" test (#+ Test)] + [abstract + {[0 #spec] + [/ + ["$." equivalence]]}] + [math + ["." random (#+ Random)]]] + {#program + ["." /]}) + +(def: #export random + (Random /.Origin) + ($_ random.or + (random.ascii/alpha 10) + (random.ascii/alpha 10) + )) + +(def: #export test + Test + (<| (_.covering /._) + (_.for [/.Origin] + ($_ _.and + (_.for [/.equivalence] + ($equivalence.spec /.equivalence ..random)) + )))) diff --git a/stdlib/source/test/lux.lux b/stdlib/source/test/lux.lux index c00ef0964..60fc409ad 100644 --- a/stdlib/source/test/lux.lux +++ b/stdlib/source/test/lux.lux @@ -232,50 +232,50 @@ (def: test (<| (_.context (name.module (name_of /._))) - (_.in_parallel - (list (!bundle ($_ _.and - (<| (_.context "Identity.") - ..identity) - (<| (_.context "Increment & decrement.") - ..increment_and_decrement) - (<| (_.context "Even or odd.") - ($_ _.and - (<| (_.context "Natural numbers.") - (..even_or_odd random.nat n.even? n.odd?)) - (<| (_.context "Integers.") - (..even_or_odd random.int i.even? i.odd?)))) - (<| (_.context "Minimum and maximum.") - (`` ($_ _.and - (~~ (template [<=> ] - [(<| (_.context ) - (..minimum_and_maximum <=> [ ] [ ]))] + ($_ _.and + (<| (_.context "Identity.") + ..identity) + (<| (_.context "Increment & decrement.") + ..increment_and_decrement) + (<| (_.context "Even or odd.") + ($_ _.and + (<| (_.context "Natural numbers.") + (..even_or_odd random.nat n.even? n.odd?)) + (<| (_.context "Integers.") + (..even_or_odd random.int i.even? i.odd?)))) + (<| (_.context "Minimum and maximum.") + (`` ($_ _.and + (~~ (template [<=> ] + [(<| (_.context ) + (..minimum_and_maximum <=> [ ] [ ]))] - [i.= i.< i.min i.> i.max random.int "Integers."] - [n.= n.< n.min n.> n.max random.nat "Natural numbers."] - [r.= r.< r.min r.> r.max random.rev "Revolutions."] - [f.= f.< f.min f.> f.max random.safe_frac "Fractions."] - ))))) - (<| (_.context "Conversion.") - (`` ($_ _.and - (~~ (template [<=> ] - [(<| (_.context (format (%.name (name_of )) - " " (%.name (name_of )))) - (..conversion <=>))] + [i.= i.< i.min i.> i.max random.int "Integers."] + [n.= n.< n.min n.> n.max random.nat "Natural numbers."] + [r.= r.< r.min r.> r.max random.rev "Revolutions."] + [f.= f.< f.min f.> f.max random.safe_frac "Fractions."] + ))))) + (<| (_.context "Conversion.") + (`` ($_ _.and + (~~ (template [<=> ] + [(<| (_.context (format (%.name (name_of )) + " " (%.name (name_of )))) + (..conversion <=>))] - [i.= .nat .int (random\map (i.% +1,000,000) random.int)] - [n.= .int .nat (random\map (n.% 1,000,000) random.nat)] - [i.= i.frac f.int (random\map (i.% +1,000,000) random.int)] - [f.= f.int i.frac (random\map (|>> (i.% +1,000,000) i.frac) random.int)] - [r.= r.frac f.rev frac_rev] - ))))) - (<| (_.context "Prelude macros.") - ..prelude_macros) - (<| (_.context "Templates.") - ..templates) - (<| (_.context "Cross-platform support.") - ..cross_platform_support))) - ..sub_tests - )))) + [i.= .nat .int (random\map (i.% +1,000,000) random.int)] + [n.= .int .nat (random\map (n.% 1,000,000) random.nat)] + [i.= i.frac f.int (random\map (i.% +1,000,000) random.int)] + [f.= f.int i.frac (random\map (|>> (i.% +1,000,000) i.frac) random.int)] + [r.= r.frac f.rev frac_rev] + ))))) + (<| (_.context "Prelude macros.") + ..prelude_macros) + (<| (_.context "Templates.") + ..templates) + (<| (_.context "Cross-platform support.") + ..cross_platform_support) + + ..sub_tests + ))) (program: args (<| io diff --git a/stdlib/source/test/lux/control/concurrency/frp.lux b/stdlib/source/test/lux/control/concurrency/frp.lux index 2652be103..d48e1b1ae 100644 --- a/stdlib/source/test/lux/control/concurrency/frp.lux +++ b/stdlib/source/test/lux/control/concurrency/frp.lux @@ -16,8 +16,7 @@ [text ["%" format (#+ format)]] [number - ["n" nat] - ["." i64]] + ["n" nat]] [collection ["." list ("#\." fold monoid)] ["." row (#+ Row)]]] @@ -26,7 +25,7 @@ {1 ["." / [// - ["." promise ("#\." monad)] + ["." promise (#+ Promise) ("#\." monad)] ["." atom (#+ Atom atom)]]]}) (def: injection @@ -49,11 +48,27 @@ _ false)))))) +(def: (take_amount amount_of_polls [channel sink]) + (All [a] (-> Nat [(/.Channel a) (/.Sink a)] (Promise (List a)))) + (case amount_of_polls + 0 (do promise.monad + [_ (promise.future (\ sink close))] + (wrap #.Nil)) + _ (do {! promise.monad} + [event channel] + (case event + #.None + (wrap #.Nil) + + (#.Some [head tail]) + (\ ! map (|>> (#.Cons head)) + (take_amount (dec amount_of_polls) [channel sink])))))) + (def: #export test Test (<| (_.covering /._) (let [(^open "list\.") (list.equivalence n.equivalence)] - (do random.monad + (do {! random.monad} [inputs (random.list 5 random.nat) sample random.nat distint/0 random.nat @@ -69,7 +84,7 @@ ($apply.spec ..injection ..comparison /.apply)) (_.for [/.monad] ($monad.spec ..injection ..comparison /.monad)) - + (_.cover [/.Channel /.Sink /.channel] (case (io.run (do (try.with io.monad) @@ -125,19 +140,22 @@ (list\= (list.filter n.even? inputs) output)))) (wrap (do {! promise.monad} - [#let [sink (: (Atom (Row Nat)) - (atom.atom row.empty)) - channel (/.sequential 0 (list\compose inputs inputs))] + [#let [[?signal !signal] (: [(promise.Promise Any) (promise.Resolver Any)] + (promise.promise [])) + sink (: (Atom (Row Nat)) + (atom.atom row.empty))] _ (promise.future (/.subscribe (function (_ value) (do {! io.monad} [current (atom.read sink) _ (atom.update (row.add value) sink)] - (wrap (if (n.< (list.size inputs) - (inc (row.size current))) - (#.Some []) - #.None)))) - channel)) - _ (/.consume channel) + (if (n.< (list.size inputs) + (inc (row.size current))) + (wrap (#.Some [])) + (do ! + [_ (!signal [])] + (wrap #.None))))) + (/.sequential 0 (list\compose inputs inputs)))) + _ ?signal listened (|> sink atom.read promise.future @@ -172,36 +190,24 @@ (_.cover' [/.distinct] (list\= (list distint/0 distint/1 distint/2) actual)))) - (let [polling_delay 1 - amount_of_polls 5 - wiggle_room ($_ n.* - (i64.left_shift 6 1) - amount_of_polls - polling_delay) - total_delay (|> polling_delay - (n.* amount_of_polls) - (n.+ wiggle_room))] + (do ! + [polling_delay (\ ! map (|>> (n.% 10) inc) random.nat) + amount_of_polls (\ ! map (|>> (n.% 10) inc) random.nat)] ($_ _.and - (wrap (do promise.monad - [#let [[channel sink] (/.poll polling_delay (: (IO Nat) (io.io sample)))] - _ (promise.delay total_delay []) - _ (promise.future (\ sink close)) - actual (/.consume channel) + (wrap (do {! promise.monad} + [actual (..take_amount amount_of_polls (/.poll polling_delay (: (IO Nat) (io.io sample)))) #let [correct_values! (list.every? (n.= sample) actual) - + enough_polls! - (n.>= amount_of_polls (list.size actual))]] + (n.= amount_of_polls (list.size actual))]] (_.cover' [/.poll] (and correct_values! enough_polls!)))) - (wrap (do promise.monad - [#let [[channel sink] (/.periodic polling_delay)] - _ (promise.delay total_delay []) - _ (promise.future (\ sink close)) - actual (/.consume channel)] + (wrap (do {! promise.monad} + [actual (..take_amount amount_of_polls (/.periodic polling_delay))] (_.cover' [/.periodic] - (n.>= amount_of_polls (list.size actual))))))) + (n.= amount_of_polls (list.size actual))))))) (wrap (do promise.monad [#let [max_iterations 10] actual (|> [0 sample] diff --git a/stdlib/source/test/lux/control/concurrency/promise.lux b/stdlib/source/test/lux/control/concurrency/promise.lux index 21633f293..18b040acf 100644 --- a/stdlib/source/test/lux/control/concurrency/promise.lux +++ b/stdlib/source/test/lux/control/concurrency/promise.lux @@ -48,7 +48,7 @@ Test (<| (_.covering /._) (do {! random.monad} - [to_wait (|> random.nat (\ ! map (|>> (n.% 100) (n.max 10)))) + [to_wait (|> random.nat (\ ! map (|>> (n.% 10) (n.+ 10)))) expected random.nat dummy random.nat #let [not_dummy (|> random.nat (random.filter (|>> (n.= dummy) not)))] diff --git a/stdlib/source/test/lux/control/remember.lux b/stdlib/source/test/lux/control/remember.lux index 19c8f44f9..6f1e53122 100644 --- a/stdlib/source/test/lux/control/remember.lux +++ b/stdlib/source/test/lux/control/remember.lux @@ -10,6 +10,7 @@ [parser ["" code]]] [data + [number (#+ hex)] ["." product] ["." text ["%" format (#+ format)]]] @@ -65,7 +66,8 @@ today (instant.date now) yesterday (instant.date (instant.shift (duration.inverse duration.week) now)) tomorrow (instant.date (instant.shift duration.week now)) - prng (random.pcg_32 [123 (instant.to_millis now)]) + prng (random.pcg32 [(hex "0123456789ABCDEF") + (instant.to_millis now)]) message (product.right (random.run prng ..message)) expected (product.right (random.run prng ..focus))] (do meta.monad diff --git a/stdlib/source/test/lux/data/number/int.lux b/stdlib/source/test/lux/data/number/int.lux index 33b2927e4..24155602b 100644 --- a/stdlib/source/test/lux/data/number/int.lux +++ b/stdlib/source/test/lux/data/number/int.lux @@ -143,6 +143,22 @@ (let [gcd (/.gcd left right)] (and (/.= +0 (/.% gcd left)) (/.= +0 (/.% gcd right))))) + (_.cover [/.extended_gcd] + (let [[[left_k right_k] gcd] (/.extended_gcd left right) + + same_gcd! + (/.= gcd + (/.gcd left right)) + + bezout_identity! + (/.= gcd + (/.+ (/.* left_k left) + (/.* right_k right)))] + (and same_gcd! + bezout_identity!))) + (_.cover [/.co-prime?] + (bit\= (/.= +1 (/.gcd left right)) + (/.co-prime? left right))) (_.cover [/.lcm] (let [lcm (/.lcm left right)] (and (/.= +0 (/.% left lcm)) diff --git a/stdlib/source/test/lux/data/number/nat.lux b/stdlib/source/test/lux/data/number/nat.lux index 97f93dc53..a2d0fd655 100644 --- a/stdlib/source/test/lux/data/number/nat.lux +++ b/stdlib/source/test/lux/data/number/nat.lux @@ -112,6 +112,9 @@ (let [gcd (/.gcd left right)] (and (/.= 0 (/.% gcd left)) (/.= 0 (/.% gcd right))))) + (_.cover [/.co-prime?] + (bit\= (/.= 1 (/.gcd left right)) + (/.co-prime? left right))) (_.cover [/.lcm] (let [lcm (/.lcm left right)] (and (/.= 0 (/.% left lcm)) diff --git a/stdlib/source/test/lux/math/modular.lux b/stdlib/source/test/lux/math/modular.lux index 66eb047fc..849159da2 100644 --- a/stdlib/source/test/lux/math/modular.lux +++ b/stdlib/source/test/lux/math/modular.lux @@ -3,7 +3,13 @@ ["_" test (#+ Test)] ["." type ("#\." equivalence)] [abstract - [monad (#+ do)]] + [monad (#+ do)] + {[0 #spec] + [/ + ["$." equivalence] + ["$." order] + ["$." monoid] + ["$." codec]]}] [control ["." try] ["." exception]] @@ -14,133 +20,103 @@ ["i" int]]] [math ["." random (#+ Random)]]] + ["$." // #_ + ["#" modulus]] {1 ["." / ["/#" // #_ ["#" modulus]]]}) -(def: %3 (//.literal +3)) -(`` (type: Mod3 (~~ (:of %3)))) - -(def: modulusR - (Random Int) - (|> random.int - (\ random.monad map (i.% +1000)) - (random.filter (|>> (i.= +0) not)))) - -(def: valueR - (Random Int) - (|> random.int (\ random.monad map (i.% +1000)))) - -(def: (modR modulus) - (All [m] (-> (//.Modulus m) (Random [Int (/.Mod m)]))) - (do random.monad - [raw valueR] - (wrap [raw (/.modular modulus raw)]))) - -(def: value - (All [m] (-> (/.Mod m) Int)) - (|>> /.un_modular product.right)) - -(def: (comparison m/? i/?) - (All [m] - (-> (-> (/.Mod m) (/.Mod m) Bit) - (-> Int Int Bit) - (-> (/.Mod m) (/.Mod m) Bit))) - (function (_ param subject) - (bit\= (m/? param subject) - (i/? (value param) - (value subject))))) - -(def: (arithmetic modulus m/! i/!) - (All [m] - (-> (//.Modulus m) - (-> (/.Mod m) (/.Mod m) (/.Mod m)) - (-> Int Int Int) - (-> (/.Mod m) (/.Mod m) Bit))) - (function (_ param subject) - (|> (i/! (value param) - (value subject)) - (/.modular modulus) - (/.= (m/! param subject))))) +(def: #export (random modulus) + (All [%] (-> (//.Modulus %) (Random (/.Mod %)))) + (\ random.monad map + (/.modular modulus) + random.int)) (def: #export test Test (<| (_.covering /._) + (_.for [/.Mod]) (do random.monad - [_normalM modulusR - _alternativeM (|> modulusR (random.filter (|>> (i.= _normalM) not))) - #let [normalM (|> _normalM //.modulus try.assume) - alternativeM (|> _alternativeM //.modulus try.assume)] - [_param param] (modR normalM) - [_subject subject] (modR normalM) - #let [copyM (|> normalM //.divisor //.modulus try.assume)]] - ($_ _.and - (_.test "Every modulus has a unique type, even if the numeric value is the same as another." - (and (type\= (:of normalM) - (:of normalM)) - (not (type\= (:of normalM) - (:of alternativeM))) - (not (type\= (:of normalM) - (:of copyM))))) - ## (_.test "Can extract the original integer from the modulus." - ## (i.= _normalM - ## (//.divisor normalM))) - ## (_.test "Can compare mod'ed values." - ## (and (/.= subject subject) - ## ((comparison /.= i.=) param subject) - ## ((comparison /.< i.<) param subject) - ## ((comparison /.<= i.<=) param subject) - ## ((comparison /.> i.>) param subject) - ## ((comparison /.>= i.>=) param subject))) - ## (_.test "Mod'ed values are ordered." - ## (and (bit\= (/.< param subject) - ## (not (/.>= param subject))) - ## (bit\= (/.> param subject) - ## (not (/.<= param subject))) - ## (bit\= (/.= param subject) - ## (not (or (/.< param subject) - ## (/.> param subject)))))) - ## (_.test "Can do arithmetic." - ## (and ((arithmetic normalM /.+ i.+) param subject) - ## ((arithmetic normalM /.- i.-) param subject) - ## ((arithmetic normalM /.* i.*) param subject))) - ## (_.test "Can sometimes find multiplicative inverse." - ## (case (/.inverse subject) - ## (#.Some subject^-1) - ## (|> subject - ## (/.* subject^-1) - ## (/.= (/.modular normalM +1))) - - ## #.None - ## true)) - ## (_.test "Can encode/decode to text." - ## (let [(^open "mod/.") (/.codec normalM)] - ## (case (|> subject mod/encode mod/decode) - ## (#try.Success output) - ## (/.= subject output) - - ## (#try.Failure error) - ## false))) - ## (_.test "Can equalize 2 moduli if they are equal." - ## (case (/.equalize (/.modular normalM _subject) - ## (/.modular copyM _param)) - ## (#try.Success paramC) - ## (/.= param paramC) + [param\\% ($//.random +1,000,000) + param (..random param\\%) - ## (#try.Failure error) - ## false)) - ## (_.test "Cannot equalize 2 moduli if they are the different." - ## (case (/.equalize (/.modular normalM _subject) - ## (/.modular alternativeM _param)) - ## (#try.Success paramA) - ## false + subject\\% (random.filter (|>> (//.= param\\%) not) + ($//.random +1,000,000)) + subject (..random subject\\%) + another (..random subject\\%)] + (`` ($_ _.and + (_.for [/.equivalence /.=] + ($equivalence.spec /.equivalence (..random subject\\%))) + (_.for [/.order /.<] + ($order.spec /.order (..random subject\\%))) + (~~ (template [ ] + [(_.for [ ] + ($monoid.spec /.equivalence ( subject\\%) (..random subject\\%)))] + + [/.+ /.addition] + [/.* /.multiplication] + )) + (_.for [/.codec] + ($codec.spec /.equivalence (/.codec subject\\%) (..random subject\\%))) - ## (#try.Failure error) - ## true)) - ## (_.test "All numbers are congruent to themselves." - ## (//.congruent? normalM _subject _subject)) - ## (_.test "If 2 numbers are congruent under a modulus, then they must also be equal under the same modulus." - ## (bit\= (//.congruent? normalM _param _subject) - ## (/.= param subject))) - )))) + (_.cover [/.incorrect_modulus] + (case (|> param + (\ (/.codec param\\%) encode) + (\ (/.codec subject\\%) decode)) + (#try.Failure error) + (exception.match? /.incorrect_modulus error) + + (#try.Success _) + false)) + (_.cover [/.modulus] + (and (type\= (:of (/.modulus subject)) + (:of (/.modulus subject))) + (not (type\= (:of (/.modulus subject)) + (:of (/.modulus param)))))) + (_.cover [/.modular /.value] + (/.= subject + (/.modular (/.modulus subject) (/.value subject)))) + (_.cover [/.>] + (bit\= (/.> another subject) + (/.< subject another))) + (_.cover [/.<= /.>=] + (bit\= (/.<= another subject) + (/.>= subject another))) + (_.cover [/.-] + (let [zero (/.modular (/.modulus subject) +0)] + (and (/.= zero + (/.- subject subject)) + (/.= subject + (/.- zero subject))))) + (_.cover [/.inverse] + (let [one (/.modular (/.modulus subject) +1) + co-prime? (i.co-prime? (//.divisor (/.modulus subject)) + (/.value subject))] + (case (/.inverse subject) + (#.Some subject^-1) + (and co-prime? + (|> subject + (/.* subject^-1) + (/.= one))) + + #.None + (not co-prime?)))) + (_.cover [/.adapter] + (<| (try.default false) + (do try.monad + [copy\\% (//.modulus (//.divisor subject\\%)) + adapt (/.adapter subject\\% copy\\%)] + (wrap (|> subject + /.value + (/.modular copy\\%) + adapt + (/.= subject)))))) + (_.cover [/.moduli_are_not_equal] + (case (/.adapter subject\\% param\\%) + (#try.Failure error) + (exception.match? /.moduli_are_not_equal error) + + (#try.Success _) + false)) + ))))) diff --git a/stdlib/source/test/lux/math/modulus.lux b/stdlib/source/test/lux/math/modulus.lux index 58d16666f..7fec2db0d 100644 --- a/stdlib/source/test/lux/math/modulus.lux +++ b/stdlib/source/test/lux/math/modulus.lux @@ -25,14 +25,19 @@ 0 +1 _ (.int divisor))))))) +(def: #export (random range) + (Ex [%] (-> Int (Random (/.Modulus %)))) + (|> random.int + (\ random.monad map (i.% range)) + (random.one (|>> /.modulus try.to_maybe)))) + (def: #export test Test (<| (_.covering /._) (_.for [/.Modulus]) (do random.monad [divisor random.int - modulus (random.one (|>> /.modulus try.to_maybe) - random.int) + modulus (..random +1,000,000) dividend random.int] ($_ _.and (_.cover [/.modulus /.divisor] diff --git a/stdlib/source/test/lux/time/duration.lux b/stdlib/source/test/lux/time/duration.lux index 89d9a4db7..272532324 100644 --- a/stdlib/source/test/lux/time/duration.lux +++ b/stdlib/source/test/lux/time/duration.lux @@ -43,9 +43,9 @@ #let [(^open "/\.") /.order]] ($_ _.and (_.test "Can scale a duration." - (|> sample (/.scale_up factor) (/.query sample) (i.= (.int factor)))) + (|> sample (/.up factor) (/.query sample) (i.= (.int factor)))) (_.test "Scaling a duration by one does not change it." - (|> sample (/.scale_up 1) (/\= sample))) + (|> sample (/.up 1) (/\= sample))) (_.test "Merging a duration with it's opposite yields an empty duration." (|> sample (/.merge (/.inverse sample)) (/\= /.empty))))) ))) -- cgit v1.2.3