From f7880ce83ba82ada2d04a0c587448446e677d458 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 6 Jul 2022 17:11:35 -0400 Subject: Moved "lux/time" to "lux/world/time". --- .../test/aedifex/artifact/snapshot/stamp.lux | 5 +- stdlib/source/test/aedifex/artifact/time.lux | 5 +- stdlib/source/test/aedifex/command/auto.lux | 6 +- stdlib/source/test/aedifex/metadata/artifact.lux | 14 +- stdlib/source/test/aedifex/metadata/snapshot.lux | 14 +- stdlib/source/test/lux.lux | 2 - .../source/test/lux/control/concurrency/async.lux | 7 +- .../source/test/lux/control/concurrency/thread.lux | 9 +- stdlib/source/test/lux/control/function/memo.lux | 7 +- stdlib/source/test/lux/control/remember.lux | 9 +- stdlib/source/test/lux/data/format/json.lux | 13 +- stdlib/source/test/lux/data/format/tar.lux | 7 +- stdlib/source/test/lux/data/text.lux | 13 +- stdlib/source/test/lux/debug.lux | 13 +- stdlib/source/test/lux/time.lux | 157 --------------------- stdlib/source/test/lux/time/date.lux | 95 ------------- stdlib/source/test/lux/time/day.lux | 89 ------------ stdlib/source/test/lux/time/duration.lux | 100 ------------- stdlib/source/test/lux/time/instant.lux | 106 -------------- stdlib/source/test/lux/time/month.lux | 101 ------------- stdlib/source/test/lux/time/year.lux | 97 ------------- stdlib/source/test/lux/world.lux | 4 +- stdlib/source/test/lux/world/file.lux | 5 +- stdlib/source/test/lux/world/time.lux | 157 +++++++++++++++++++++ stdlib/source/test/lux/world/time/date.lux | 95 +++++++++++++ stdlib/source/test/lux/world/time/day.lux | 89 ++++++++++++ stdlib/source/test/lux/world/time/duration.lux | 100 +++++++++++++ stdlib/source/test/lux/world/time/instant.lux | 106 ++++++++++++++ stdlib/source/test/lux/world/time/month.lux | 101 +++++++++++++ stdlib/source/test/lux/world/time/year.lux | 97 +++++++++++++ 30 files changed, 817 insertions(+), 806 deletions(-) delete mode 100644 stdlib/source/test/lux/time.lux delete mode 100644 stdlib/source/test/lux/time/date.lux delete mode 100644 stdlib/source/test/lux/time/day.lux delete mode 100644 stdlib/source/test/lux/time/duration.lux delete mode 100644 stdlib/source/test/lux/time/instant.lux delete mode 100644 stdlib/source/test/lux/time/month.lux delete mode 100644 stdlib/source/test/lux/time/year.lux create mode 100644 stdlib/source/test/lux/world/time.lux create mode 100644 stdlib/source/test/lux/world/time/date.lux create mode 100644 stdlib/source/test/lux/world/time/day.lux create mode 100644 stdlib/source/test/lux/world/time/duration.lux create mode 100644 stdlib/source/test/lux/world/time/instant.lux create mode 100644 stdlib/source/test/lux/world/time/month.lux create mode 100644 stdlib/source/test/lux/world/time/year.lux (limited to 'stdlib/source/test') diff --git a/stdlib/source/test/aedifex/artifact/snapshot/stamp.lux b/stdlib/source/test/aedifex/artifact/snapshot/stamp.lux index da8755d6f..2b4265932 100644 --- a/stdlib/source/test/aedifex/artifact/snapshot/stamp.lux +++ b/stdlib/source/test/aedifex/artifact/snapshot/stamp.lux @@ -14,8 +14,9 @@ ["<[1]>" \\parser]]]] [math ["[0]" random (.only Random)]] - [time - ["[0]" instant]]]] + [world + [time + ["[0]" instant]]]]] [\\program ["[0]" /]] ["$[0]" // diff --git a/stdlib/source/test/aedifex/artifact/time.lux b/stdlib/source/test/aedifex/artifact/time.lux index c81dffa89..2c7d29269 100644 --- a/stdlib/source/test/aedifex/artifact/time.lux +++ b/stdlib/source/test/aedifex/artifact/time.lux @@ -15,8 +15,9 @@ ["[0]" random (.only Random)] [number ["i" int]]] - [time - ["[0]" instant (.use "[1]#[0]" equivalence)]]]] + [world + [time + ["[0]" instant (.use "[1]#[0]" equivalence)]]]]] [\\program ["[0]" /]] ["[0]" / diff --git a/stdlib/source/test/aedifex/command/auto.lux b/stdlib/source/test/aedifex/command/auto.lux index 564cf6ab0..8cc8177a1 100644 --- a/stdlib/source/test/aedifex/command/auto.lux +++ b/stdlib/source/test/aedifex/command/auto.lux @@ -24,14 +24,14 @@ ["[0]" random] [number ["n" nat]]] - [time - ["[0]" instant]] [world [console (.only Console)] ["[0]" shell (.only Exit Shell)] ["[0]" program (.only Program)] ["[0]" file - ["[0]" watch]]]]] + ["[0]" watch]] + [time + ["[0]" instant]]]]] ["[0]" // ["$[0]" version] ["$[0]" build]] diff --git a/stdlib/source/test/aedifex/metadata/artifact.lux b/stdlib/source/test/aedifex/metadata/artifact.lux index 17770c575..ed5b95b3b 100644 --- a/stdlib/source/test/aedifex/metadata/artifact.lux +++ b/stdlib/source/test/aedifex/metadata/artifact.lux @@ -26,15 +26,15 @@ ["n" nat]]] [meta ["[0]" code]] - ["[0]" time (.only) - ["[0]" date] - ["[0]" year] - ["[0]" month] - ["[0]" instant] - ["[0]" duration]] [world ["[0]" file] - ["[0]" program]]]] + ["[0]" program] + ["[0]" time (.only) + ["[0]" date] + ["[0]" year] + ["[0]" month] + ["[0]" instant] + ["[0]" duration]]]]] [\\program ["[0]" / (.only) ["/[1]" // (.only) diff --git a/stdlib/source/test/aedifex/metadata/snapshot.lux b/stdlib/source/test/aedifex/metadata/snapshot.lux index 46e368dbf..773dd262b 100644 --- a/stdlib/source/test/aedifex/metadata/snapshot.lux +++ b/stdlib/source/test/aedifex/metadata/snapshot.lux @@ -26,15 +26,15 @@ ["n" nat]]] [meta ["[0]" code]] - ["[0]" time (.only) - ["[0]" date] - ["[0]" year] - ["[0]" month] - ["[0]" instant (.only Instant)] - ["[0]" duration]] [world ["[0]" file] - ["[0]" program]]]] + ["[0]" program] + ["[0]" time (.only) + ["[0]" date] + ["[0]" year] + ["[0]" month] + ["[0]" instant (.only Instant)] + ["[0]" duration]]]]] ["$[0]" /// ["[1][0]" artifact ["[1]/[0]" type] diff --git a/stdlib/source/test/lux.lux b/stdlib/source/test/lux.lux index d9e4bbc29..7212f5fb4 100644 --- a/stdlib/source/test/lux.lux +++ b/stdlib/source/test/lux.lux @@ -55,7 +55,6 @@ ["[1][0]" static] ["[1][0]" test] - ["[1][0]" time] ["[1][0]" world] ["[1][0]" ffi] @@ -1213,7 +1212,6 @@ /static.test /test.test - /time.test /world.test /ffi.test diff --git a/stdlib/source/test/lux/control/concurrency/async.lux b/stdlib/source/test/lux/control/concurrency/async.lux index e5d175486..42d938ddd 100644 --- a/stdlib/source/test/lux/control/concurrency/async.lux +++ b/stdlib/source/test/lux/control/concurrency/async.lux @@ -18,9 +18,10 @@ ["[0]" i64]]] [meta ["@" target]] - [time - ["[0]" instant] - ["[0]" duration]]]] + [world + [time + ["[0]" instant] + ["[0]" duration]]]]] [\\library ["[0]" / (.only) [// diff --git a/stdlib/source/test/lux/control/concurrency/thread.lux b/stdlib/source/test/lux/control/concurrency/thread.lux index 87ba8859a..da2a9ea37 100644 --- a/stdlib/source/test/lux/control/concurrency/thread.lux +++ b/stdlib/source/test/lux/control/concurrency/thread.lux @@ -6,14 +6,15 @@ [monad (.only do)]] [control ["[0]" io]] - [time - ["[0]" instant (.only Instant)] - ["[0]" duration]] [math ["[0]" random] [number ["n" nat] - ["i" int]]]]] + ["i" int]]] + [world + [time + ["[0]" instant (.only Instant)] + ["[0]" duration]]]]] [\\library ["[0]" / (.only) [// diff --git a/stdlib/source/test/lux/control/function/memo.lux b/stdlib/source/test/lux/control/function/memo.lux index 1a310744f..1abe7f7f9 100644 --- a/stdlib/source/test/lux/control/function/memo.lux +++ b/stdlib/source/test/lux/control/function/memo.lux @@ -20,9 +20,10 @@ [meta [macro ["^" pattern]]] - [time - ["[0]" instant] - ["[0]" duration (.only Duration)]]]] + [world + [time + ["[0]" instant] + ["[0]" duration (.only Duration)]]]]] [\\library ["[0]" / (.only) ["/[1]" // diff --git a/stdlib/source/test/lux/control/remember.lux b/stdlib/source/test/lux/control/remember.lux index 83dc740e8..5f4fae4ac 100644 --- a/stdlib/source/test/lux/control/remember.lux +++ b/stdlib/source/test/lux/control/remember.lux @@ -20,10 +20,11 @@ ["<[1]>" \\parser]] ["[0]" macro (.only) ["[0]" syntax (.only syntax)]]] - [time - ["[0]" date (.only Date)] - ["[0]" instant] - ["[0]" duration]]]] + [world + [time + ["[0]" date (.only Date)] + ["[0]" instant] + ["[0]" duration]]]]] [\\library ["[0]" /]]) diff --git a/stdlib/source/test/lux/data/format/json.lux b/stdlib/source/test/lux/data/format/json.lux index bda5d1aba..e057efcfe 100644 --- a/stdlib/source/test/lux/data/format/json.lux +++ b/stdlib/source/test/lux/data/format/json.lux @@ -39,12 +39,13 @@ ["[0]" syntax (.only syntax)]] [type ["[0]" unit]]] - [time - ["[0]" date] - ["[0]" instant - ["[0]/[1]" \\test]] - ["[0]" duration - ["[0]/[1]" \\test]]]]] + [world + [time + ["[0]" date] + ["[0]" instant + ["[0]/[1]" \\test]] + ["[0]" duration + ["[0]/[1]" \\test]]]]]] ["[0]" \\polytypic] ["[0]" \\parser] [\\library diff --git a/stdlib/source/test/lux/data/format/tar.lux b/stdlib/source/test/lux/data/format/tar.lux index 7f695042d..5665efaec 100644 --- a/stdlib/source/test/lux/data/format/tar.lux +++ b/stdlib/source/test/lux/data/format/tar.lux @@ -29,9 +29,10 @@ [number ["n" nat] ["i" int]]] - [time - ["[0]" instant (.only Instant)] - ["[0]" duration]]]] + [world + [time + ["[0]" instant (.only Instant)] + ["[0]" duration]]]]] [\\library ["[0]" /]]) diff --git a/stdlib/source/test/lux/data/text.lux b/stdlib/source/test/lux/data/text.lux index 82d998311..8aead4f9b 100644 --- a/stdlib/source/test/lux/data/text.lux +++ b/stdlib/source/test/lux/data/text.lux @@ -51,12 +51,13 @@ ["<[1]>" \\parser]] [macro ["^" pattern]]] - ["[0]" time (.only) - ["[0]" day] - ["[0]" month] - ["[0]" instant] - ["[0]" duration] - ["[0]" date]]]] + [world + ["[0]" time (.only) + ["[0]" day] + ["[0]" month] + ["[0]" instant] + ["[0]" duration] + ["[0]" date]]]]] ["$[0]" // [format ["[1][0]" xml] diff --git a/stdlib/source/test/lux/debug.lux b/stdlib/source/test/lux/debug.lux index ccf72208a..8dae4a18e 100644 --- a/stdlib/source/test/lux/debug.lux +++ b/stdlib/source/test/lux/debug.lux @@ -25,12 +25,13 @@ ["<[1]>" \\parser]] ["[0]" macro (.only) [syntax (.only syntax)]]] - [time (.only Time) - [instant (.only Instant)] - [date (.only Date)] - [duration (.only Duration)] - [month (.only Month)] - [day (.only Day)]]]] + [world + [time (.only Time) + [instant (.only Instant)] + [date (.only Date)] + [duration (.only Duration)] + [month (.only Month)] + [day (.only Day)]]]]] [\\library ["[0]" /]] ["$[0]" // diff --git a/stdlib/source/test/lux/time.lux b/stdlib/source/test/lux/time.lux deleted file mode 100644 index 62c3ec43c..000000000 --- a/stdlib/source/test/lux/time.lux +++ /dev/null @@ -1,157 +0,0 @@ -(.require - [library - [lux (.except) - ["_" test (.only Test)] - [abstract - [monad (.only do)] - [\\specification - ["$[0]" equivalence] - ["$[0]" order] - ["$[0]" enum] - ["$[0]" codec]]] - [control - ["[0]" pipe] - ["[0]" try (.use "[1]#[0]" functor)] - ["[0]" exception]] - [data - ["[0]" text (.only) - ["%" \\format (.only format)] - ["<[1]>" \\parser]]] - [math - ["[0]" random] - [number - ["n" nat]]]]] - ["[0]" / - ["[1][0]" date] - ["[1][0]" day] - ["[1][0]" duration] - ["[1][0]" instant] - ["[1][0]" month] - ["[1][0]" year]] - [\\library - ["[0]" / (.only) - ["[0]" duration]]]) - -(def for_implementation - Test - (all _.and - (_.for [/.equivalence] - ($equivalence.spec /.equivalence random.time)) - (_.for [/.order] - ($order.spec /.order random.time)) - (_.for [/.enum] - ($enum.spec /.enum random.time)) - (_.for [/.codec] - ($codec.spec /.equivalence /.codec random.time)))) - -(def for_clock - Test - (do [! random.monad] - [expected random.time] - (_.coverage [/.clock /.time] - (|> expected - /.clock - /.time - (try#each (at /.equivalence = expected)) - (try.else false))))) - -(def for_ranges - Test - (do [! random.monad] - [valid_hour (at ! each (|>> (n.% /.hours) (n.max 10)) random.nat) - valid_minute (at ! each (|>> (n.% /.minutes) (n.max 10)) random.nat) - valid_second (at ! each (|>> (n.% /.seconds) (n.max 10)) random.nat) - valid_milli_second (at ! each (n.% /.milli_seconds) random.nat) - - .let [invalid_hour (|> valid_hour (n.+ /.hours)) - invalid_minute (|> valid_minute (n.+ /.minutes) (n.min 99)) - invalid_second (|> valid_second (n.+ /.seconds) (n.min 99))]] - (`` (all _.and - (,, (with_template [ ] - [(_.coverage [ ] - (let [valid! - (|> - %.nat - (text.prefix ) - (text.suffix ) - (at /.codec decoded) - (pipe.case - {try.#Success _} true - {try.#Failure error} false)) - - invalid! - (|> - %.nat - (text.prefix ) - (text.suffix ) - (at /.codec decoded) - (pipe.case - {try.#Success _} - false - - {try.#Failure error} - (exception.match? error)))] - (and valid! - invalid!)))] - - [/.hours /.invalid_hour "" ":00:00.000" valid_hour invalid_hour] - [/.minutes /.invalid_minute "00:" ":00.000" valid_minute invalid_minute] - [/.seconds /.invalid_second "00:00:" ".000" valid_second invalid_second] - )) - (_.coverage [/.milli_seconds] - (|> valid_milli_second - %.nat - (format "00:00:00.") - (at /.codec decoded) - (pipe.case - {try.#Success _} true - {try.#Failure error} false))) - )))) - -(def .public test - Test - (<| (_.covering /._) - (_.for [/.Time]) - (do [! random.monad] - [.let [day (.nat (duration.millis duration.day))] - expected random.time - - out_of_bounds (at ! each (|>> /.millis (n.+ day)) - random.time)] - (`` (all _.and - ..for_implementation - - (_.coverage [/.millis /.of_millis] - (|> expected - /.millis - /.of_millis - (try#each (at /.equivalence = expected)) - (try.else false))) - (_.coverage [/.time_exceeds_a_day] - (case (/.of_millis out_of_bounds) - {try.#Success _} - false - - {try.#Failure error} - (exception.match? /.time_exceeds_a_day error))) - (_.coverage [/.midnight] - (|> /.midnight - /.millis - (n.= 0))) - (_.coverage [/.parser] - (|> expected - (at /.codec encoded) - (.result /.parser) - (try#each (at /.equivalence = expected)) - (try.else false))) - ..for_ranges - (_.for [/.Clock] - ..for_clock) - - /date.test - /day.test - /duration.test - /instant.test - /month.test - /year.test - ))))) diff --git a/stdlib/source/test/lux/time/date.lux b/stdlib/source/test/lux/time/date.lux deleted file mode 100644 index c97fd626e..000000000 --- a/stdlib/source/test/lux/time/date.lux +++ /dev/null @@ -1,95 +0,0 @@ -(.require - [library - [lux (.except) - ["_" test (.only Test)] - [abstract - [monad (.only do)] - [\\specification - ["$[0]" equivalence] - ["$[0]" order] - ["$[0]" enum] - ["$[0]" codec]]] - [control - ["[0]" try (.use "[1]#[0]" functor)] - ["[0]" exception]] - [data - ["[0]" text - ["%" \\format (.only format)] - ["<[1]>" \\parser]]] - [math - ["[0]" random (.only Random)] - [number - ["n" nat] - ["i" int]]]]] - [\\library - ["[0]" /]]) - -(def .public test - Test - (<| (_.covering /._) - (_.for [/.Date]) - (all _.and - (_.for [/.equivalence] - ($equivalence.spec /.equivalence random.date)) - (_.for [/.order] - ($order.spec /.order random.date)) - (_.for [/.enum] - ($enum.spec /.enum random.date)) - (_.for [/.codec] - ($codec.spec /.equivalence /.codec random.date)) - - (do random.monad - [expected random.date] - (_.coverage [/.date /.year /.month /.day_of_month] - (|> (/.date (/.year expected) - (/.month expected) - (/.day_of_month expected)) - (try#each (at /.equivalence = expected)) - (try.else false)))) - (do random.monad - [expected random.date] - (_.coverage [/.invalid_day] - (case (/.date (/.year expected) - (/.month expected) - (n.+ 31 (/.day_of_month expected))) - {try.#Failure error} - (exception.match? /.invalid_day error) - - {try.#Success _} - false))) - (do random.monad - [expected random.date] - (_.coverage [/.days /.of_days] - (|> expected - /.days - /.of_days - (at /.equivalence = expected)))) - (_.coverage [/.epoch] - (|> /.epoch - /.days - (i.= +0))) - (do random.monad - [expected random.date] - (_.coverage [/.parser] - (|> (at /.codec encoded expected) - (.result /.parser) - (try#each (at /.equivalence = expected)) - (try.else false)))) - (do [! random.monad] - [year (at ! each (|>> (n.% 10,000) ++) - random.nat) - month (at ! each (|>> (n.% 10) (n.+ 13)) - random.nat) - day (at ! each (|>> (n.% 10) (n.+ 10)) - random.nat) - .let [input (format (%.nat year) - "-" (%.nat month) - "-" (%.nat day))]] - (_.coverage [/.invalid_month] - (case (.result /.parser input) - {try.#Failure error} - (exception.match? /.invalid_month error) - - {try.#Success _} - false))) - ))) diff --git a/stdlib/source/test/lux/time/day.lux b/stdlib/source/test/lux/time/day.lux deleted file mode 100644 index eecc8a0fb..000000000 --- a/stdlib/source/test/lux/time/day.lux +++ /dev/null @@ -1,89 +0,0 @@ -(.require - [library - [lux (.except) - ["_" test (.only Test)] - [abstract - [monad (.only do)] - [\\specification - ["$[0]" equivalence] - ["$[0]" hash] - ["$[0]" order] - ["$[0]" enum] - ["$[0]" codec]]] - [control - ["[0]" try (.use "[1]#[0]" functor)] - ["[0]" exception] - [function - ["[0]" predicate]]] - [data - [collection - ["[0]" list] - ["[0]" set]]] - [math - ["[0]" random (.only Random) (.use "[1]#[0]" monad)] - [number - ["n" nat]]]]] - [\\library - ["[0]" /]]) - -(def .public random - (Random /.Day) - (random.either (random.either (random.either (random#in {/.#Sunday}) - (random#in {/.#Monday})) - (random.either (random#in {/.#Tuesday}) - (random#in {/.#Wednesday}))) - (random.either (random.either (random#in {/.#Thursday}) - (random#in {/.#Friday})) - (random#in {/.#Saturday})))) - -(def .public test - Test - (<| (_.covering /._) - (_.for [/.Day]) - (do random.monad - [expected ..random - invalid (random.only (predicate.or (n.< (/.number {/.#Sunday})) - (n.> (/.number {/.#Saturday}))) - random.nat)] - (all _.and - (_.for [/.equivalence] - ($equivalence.spec /.equivalence ..random)) - (_.for [/.hash] - ($hash.spec /.hash ..random)) - (_.for [/.order] - ($order.spec /.order ..random)) - (_.for [/.enum] - ($enum.spec /.enum ..random)) - (_.for [/.codec] - ($codec.spec /.equivalence /.codec ..random)) - - (do random.monad - [not_a_day (random.upper_case 1)] - (_.coverage [/.not_a_day_of_the_week] - (case (at /.codec decoded not_a_day) - {try.#Failure error} - (exception.match? /.not_a_day_of_the_week error) - - {try.#Success _} - false))) - (_.coverage [/.number /.by_number] - (|> expected - /.number - /.by_number - (try#each (at /.equivalence = expected)) - (try.else false))) - (_.coverage [/.invalid_day] - (case (/.by_number invalid) - {try.#Failure error} - (exception.match? /.invalid_day error) - - {try.#Success _} - false)) - (_.coverage [/.week] - (let [all (list.size /.week) - uniques (set.size (set.of_list /.hash /.week))] - (and (n.= (/.number {/.#Saturday}) - all) - (n.= all - uniques)))) - )))) diff --git a/stdlib/source/test/lux/time/duration.lux b/stdlib/source/test/lux/time/duration.lux deleted file mode 100644 index e73108548..000000000 --- a/stdlib/source/test/lux/time/duration.lux +++ /dev/null @@ -1,100 +0,0 @@ -(.require - [library - [lux (.except) - ["_" test (.only Test)] - [abstract - [monad (.only do)] - [\\specification - ["$[0]" equivalence] - ["$[0]" order] - ["$[0]" enum] - ["$[0]" monoid] - ["$[0]" codec]]] - [data - ["[0]" bit (.use "[1]#[0]" equivalence)]] - [math - ["[0]" random (.only Random)] - [number - ["n" nat] - ["i" int]]]]] - [\\library - ["[0]" /]]) - -(def .public test - Test - (<| (_.covering /._) - (_.for [/.Duration]) - (all _.and - (_.for [/.equivalence] - ($equivalence.spec /.equivalence random.duration)) - (_.for [/.order] - ($order.spec /.order random.duration)) - (_.for [/.enum] - ($enum.spec /.enum random.duration)) - (_.for [/.monoid] - ($monoid.spec /.equivalence /.monoid random.duration)) - (_.for [/.codec] - ($codec.spec /.equivalence /.codec random.duration)) - - (do random.monad - [duration random.duration] - (_.coverage [/.of_millis /.millis] - (|> duration /.millis /.of_millis (at /.equivalence = duration)))) - (do random.monad - [.let [(open "#[0]") /.equivalence] - expected random.duration - parameter random.duration] - (all _.and - (_.coverage [/.composite /.difference] - (|> expected (/.composite parameter) (/.difference parameter) (#= expected))) - (_.coverage [/.empty] - (|> expected (/.composite /.empty) (#= expected))) - (_.coverage [/.inverse] - (and (|> expected /.inverse /.inverse (#= expected)) - (|> expected (/.composite (/.inverse expected)) (#= /.empty)))) - (_.coverage [/.positive? /.negative? /.neutral?] - (or (bit#= (/.positive? expected) - (/.negative? (/.inverse expected))) - (bit#= (/.neutral? expected) - (/.neutral? (/.inverse expected))))) - )) - (do random.monad - [.let [(open "#[0]") /.equivalence] - factor random.nat] - (_.coverage [/.up /.down] - (|> /.milli_second (/.up factor) (/.down factor) (#= /.milli_second)))) - (do [! random.monad] - [.let [(open "#[0]") /.order - positive (|> random.duration - (random.only (|>> (#= /.empty) not)) - (at ! each (function (_ duration) - (if (/.positive? duration) - duration - (/.inverse duration)))))] - sample positive - frame positive] - (`` (all _.and - (_.coverage [/.framed] - (let [sample' (/.framed frame sample)] - (and (#< frame sample') - (bit#= (#< frame sample) - (#= sample sample'))))) - (_.coverage [/.ticks] - (i.= +1 (/.ticks sample sample))) - (_.coverage [/.milli_second] - (#= /.empty (at /.enum pred /.milli_second))) - (,, (with_template [ ] - [(_.coverage [] - (|> (/.ticks ) (i.= )))] - - [+1,000 /.second /.milli_second] - [+60 /.minute /.second] - [+60 /.hour /.minute] - [+24 /.day /.hour] - - [+7 /.week /.day] - [+365 /.normal_year /.day] - [+366 /.leap_year /.day] - )) - ))) - ))) diff --git a/stdlib/source/test/lux/time/instant.lux b/stdlib/source/test/lux/time/instant.lux deleted file mode 100644 index 3899c04b9..000000000 --- a/stdlib/source/test/lux/time/instant.lux +++ /dev/null @@ -1,106 +0,0 @@ -(.require - [library - [lux (.except) - ["_" test (.only Test)] - [abstract - [monad (.only do)] - [\\specification - ["$[0]" equivalence] - ["$[0]" order] - ["$[0]" enum] - ["$[0]" codec]]] - [control - ["[0]" function] - ["[0]" try] - ["[0]" io]] - [data - [collection - ["[0]" list (.use "[1]#[0]" mix)]]] - [math - ["[0]" random]] - [time - ["[0]" duration (.only Duration)] - ["[0]" day (.only Day) (.use "[1]#[0]" enum)]]]] - [\\library - ["[0]" /]]) - -(def .public test - Test - (<| (_.covering /._) - (_.for [/.Instant]) - (all _.and - (_.for [/.equivalence] - ($equivalence.spec /.equivalence random.instant)) - (_.for [/.order] - ($order.spec /.order random.instant)) - (_.for [/.enum] - ($enum.spec /.enum random.instant)) - (_.for [/.codec] - ($codec.spec /.equivalence /.codec random.instant)) - - (do random.monad - [.let [(open "#[0]") /.equivalence] - expected random.instant] - (all _.and - (_.coverage [/.millis /.of_millis] - (|> expected /.millis /.of_millis (#= expected))) - (_.coverage [/.relative /.absolute] - (|> expected /.relative /.absolute (#= expected))) - (_.coverage [/.date /.time /.of_date_time] - (#= expected - (/.of_date_time (/.date expected) - (/.time expected)))) - )) - (do random.monad - [.let [(open "#[0]") /.equivalence - (open "duration#[0]") duration.equivalence] - from random.instant - to random.instant] - (all _.and - (_.coverage [/.span] - (|> from (/.span from) (duration#= duration.empty))) - (_.coverage [/.after] - (|> from (/.after (/.span from to)) (#= to))) - (_.coverage [/.epoch] - (duration#= (/.relative to) - (/.span /.epoch to))) - )) - (do random.monad - [instant random.instant - .let [d0 (/.day_of_week instant)]] - (_.coverage [/.day_of_week] - (let [apply (is (-> (-> Duration Duration) (-> Day Day) Nat Bit) - (function (_ polarity move steps) - (let [day_shift (list#mix (function.constant move) - d0 - (list.repeated steps [])) - instant_shift (|> instant - (/.after (polarity (duration.up steps duration.day))) - /.day_of_week)] - (day#= day_shift - instant_shift))))] - (and (apply function.identity day#succ 0) - (apply function.identity day#succ 1) - (apply function.identity day#succ 2) - (apply function.identity day#succ 3) - (apply function.identity day#succ 4) - (apply function.identity day#succ 5) - (apply function.identity day#succ 6) - (apply function.identity day#succ 7) - - (apply duration.inverse day#pred 0) - (apply duration.inverse day#pred 1) - (apply duration.inverse day#pred 2) - (apply duration.inverse day#pred 3) - (apply duration.inverse day#pred 4) - (apply duration.inverse day#pred 5) - (apply duration.inverse day#pred 6) - (apply duration.inverse day#pred 7))))) - (_.coverage [/.now] - (case (try (io.run! /.now)) - {try.#Success _} - true - - {try.#Failure _} - false)) - ))) diff --git a/stdlib/source/test/lux/time/month.lux b/stdlib/source/test/lux/time/month.lux deleted file mode 100644 index c87a956cd..000000000 --- a/stdlib/source/test/lux/time/month.lux +++ /dev/null @@ -1,101 +0,0 @@ -(.require - [library - [lux (.except) - ["_" test (.only Test)] - [abstract - [monad (.only do)] - [\\specification - ["$[0]" equivalence] - ["$[0]" hash] - ["$[0]" order] - ["$[0]" enum] - ["$[0]" codec]]] - [control - ["[0]" try (.use "[1]#[0]" functor)] - ["[0]" exception] - [function - ["[0]" predicate]]] - [data - [collection - ["[0]" set] - ["[0]" list (.use "[1]#[0]" functor mix)]]] - [math - ["[0]" random (.only Random)] - [number - ["n" nat]]]]] - [\\library - ["[0]" / (.only) - [// - ["[0]" duration]]]]) - -(def .public random - (Random /.Month) - (let [december (/.number {/.#December})] - (|> random.nat - (at random.monad each (|>> (n.% december) ++)) - (random.one (|>> /.by_number try.maybe))))) - -(def .public test - Test - (<| (_.covering /._) - (_.for [/.Month]) - (all _.and - (_.for [/.equivalence] - ($equivalence.spec /.equivalence ..random)) - (_.for [/.hash] - ($hash.spec /.hash ..random)) - (_.for [/.order] - ($order.spec /.order ..random)) - (_.for [/.enum] - ($enum.spec /.enum ..random)) - (_.for [/.codec] - ($codec.spec /.equivalence /.codec ..random)) - - (do random.monad - [expected ..random - invalid (random.only (predicate.or (n.< (/.number {/.#January})) - (n.> (/.number {/.#December}))) - random.nat)] - (all _.and - (_.coverage [/.number /.by_number] - (|> expected - /.number - /.by_number - (try#each (at /.equivalence = expected)) - (try.else false))) - (_.coverage [/.invalid_month] - (case (/.by_number invalid) - {try.#Failure error} - (exception.match? /.invalid_month error) - - {try.#Success _} - false)) - (_.coverage [/.year] - (let [all (list.size /.year) - uniques (set.size (set.of_list /.hash /.year))] - (and (n.= (/.number {/.#December}) - all) - (n.= all - uniques)))) - (_.coverage [/.days] - (let [expected (.nat (duration.ticks duration.day duration.normal_year))] - (|> /.year - (list#each /.days) - (list#mix n.+ 0) - (n.= expected)))) - (_.coverage [/.leap_year_days] - (let [expected (.nat (duration.ticks duration.day duration.leap_year))] - (|> /.year - (list#each /.leap_year_days) - (list#mix n.+ 0) - (n.= expected)))) - (do random.monad - [not_a_month (random.upper_case 1)] - (_.coverage [/.not_a_month_of_the_year] - (case (at /.codec decoded not_a_month) - {try.#Failure error} - (exception.match? /.not_a_month_of_the_year error) - - {try.#Success _} - false))) - ))))) diff --git a/stdlib/source/test/lux/time/year.lux b/stdlib/source/test/lux/time/year.lux deleted file mode 100644 index 0e0dee518..000000000 --- a/stdlib/source/test/lux/time/year.lux +++ /dev/null @@ -1,97 +0,0 @@ -(.require - [library - [lux (.except) - ["_" test (.only Test)] - [abstract - [monad (.only do)] - [\\specification - ["$[0]" equivalence] - ["$[0]" order] - ["$[0]" codec]]] - [control - ["[0]" try] - ["[0]" exception]] - [data - ["[0]" bit (.use "[1]#[0]" equivalence)] - [text - ["%" \\format (.only format)]]] - [math - ["[0]" random (.only Random)] - [number - ["n" nat] - ["i" int]]]]] - [\\library - ["[0]" / (.only) - ["/[1]" // (.only) - ["[1][0]" duration] - ["[1][0]" instant] - ["[1][0]" date]]]]) - -(def .public random - (Random /.Year) - (random.one (|>> /.year try.maybe) random.int)) - -(def .public test - Test - (<| (_.covering /._) - (_.for [/.Year]) - (all _.and - (_.for [/.equivalence] - ($equivalence.spec /.equivalence ..random)) - (_.for [/.order] - ($order.spec /.order ..random)) - (_.for [/.codec /.parser] - ($codec.spec /.equivalence /.codec ..random)) - - (do random.monad - [expected random.int] - (all _.and - (_.coverage [/.year] - (bit#= (i.= +0 expected) - (case (/.year expected) - {try.#Success _} - false - - {try.#Failure _} - true))) - (_.coverage [/.value] - (case (/.year expected) - {try.#Success year} - (i.= expected (/.value year)) - - {try.#Failure _} - (i.= +0 expected))) - )) - (_.coverage [/.there_is_no_year_0] - (case (/.year +0) - {try.#Success _} - false - - {try.#Failure error} - (exception.match? /.there_is_no_year_0 error))) - (_.coverage [/.days] - (n.= (.nat (//duration.ticks //duration.day //duration.normal_year)) - /.days)) - (_.coverage [/.epoch] - (at /.equivalence = - (//date.year (//instant.date //instant.epoch)) - /.epoch)) - (_.for [/.Period] - (_.coverage [/.leap /.century /.era] - (n.= /.leap (n./ /.century /.era)))) - (let [leap (try.trusted (/.year (.int /.leap))) - century (try.trusted (/.year (.int /.century))) - era (try.trusted (/.year (.int /.era)))] - (all _.and - (_.coverage [/.leap?] - (and (/.leap? leap) - (not (/.leap? century)) - (/.leap? era))) - (_.coverage [/.leaps] - (and (i.= +1 (/.leaps leap)) - (i.= (.int (n./ /.leap /.century)) - (/.leaps century)) - (i.= (++ (i.* +4 (-- (/.leaps century)))) - (/.leaps era)))) - )) - ))) diff --git a/stdlib/source/test/lux/world.lux b/stdlib/source/test/lux/world.lux index 37b9d2892..e0018ab8b 100644 --- a/stdlib/source/test/lux/world.lux +++ b/stdlib/source/test/lux/world.lux @@ -15,7 +15,8 @@ ["[1][0]" net ["[1]/[0]" http ["[1]/[0]" client] - ["[1]/[0]" status]]]]) + ["[1]/[0]" status]]] + ["[1][0]" time]]) (def .public test Test @@ -28,4 +29,5 @@ /output/video/resolution.test /net/http/client.test /net/http/status.test + /time.test )) diff --git a/stdlib/source/test/lux/world/file.lux b/stdlib/source/test/lux/world/file.lux index 5133e9c39..faebedb1f 100644 --- a/stdlib/source/test/lux/world/file.lux +++ b/stdlib/source/test/lux/world/file.lux @@ -22,8 +22,9 @@ [meta [macro ["^" pattern]]] - [time - ["[0]" instant (.only Instant)]]]] + [world + [time + ["[0]" instant (.only Instant)]]]]] ["[0]" / ["[1][0]" watch]] [\\library diff --git a/stdlib/source/test/lux/world/time.lux b/stdlib/source/test/lux/world/time.lux new file mode 100644 index 000000000..62c3ec43c --- /dev/null +++ b/stdlib/source/test/lux/world/time.lux @@ -0,0 +1,157 @@ +(.require + [library + [lux (.except) + ["_" test (.only Test)] + [abstract + [monad (.only do)] + [\\specification + ["$[0]" equivalence] + ["$[0]" order] + ["$[0]" enum] + ["$[0]" codec]]] + [control + ["[0]" pipe] + ["[0]" try (.use "[1]#[0]" functor)] + ["[0]" exception]] + [data + ["[0]" text (.only) + ["%" \\format (.only format)] + ["<[1]>" \\parser]]] + [math + ["[0]" random] + [number + ["n" nat]]]]] + ["[0]" / + ["[1][0]" date] + ["[1][0]" day] + ["[1][0]" duration] + ["[1][0]" instant] + ["[1][0]" month] + ["[1][0]" year]] + [\\library + ["[0]" / (.only) + ["[0]" duration]]]) + +(def for_implementation + Test + (all _.and + (_.for [/.equivalence] + ($equivalence.spec /.equivalence random.time)) + (_.for [/.order] + ($order.spec /.order random.time)) + (_.for [/.enum] + ($enum.spec /.enum random.time)) + (_.for [/.codec] + ($codec.spec /.equivalence /.codec random.time)))) + +(def for_clock + Test + (do [! random.monad] + [expected random.time] + (_.coverage [/.clock /.time] + (|> expected + /.clock + /.time + (try#each (at /.equivalence = expected)) + (try.else false))))) + +(def for_ranges + Test + (do [! random.monad] + [valid_hour (at ! each (|>> (n.% /.hours) (n.max 10)) random.nat) + valid_minute (at ! each (|>> (n.% /.minutes) (n.max 10)) random.nat) + valid_second (at ! each (|>> (n.% /.seconds) (n.max 10)) random.nat) + valid_milli_second (at ! each (n.% /.milli_seconds) random.nat) + + .let [invalid_hour (|> valid_hour (n.+ /.hours)) + invalid_minute (|> valid_minute (n.+ /.minutes) (n.min 99)) + invalid_second (|> valid_second (n.+ /.seconds) (n.min 99))]] + (`` (all _.and + (,, (with_template [ ] + [(_.coverage [ ] + (let [valid! + (|> + %.nat + (text.prefix ) + (text.suffix ) + (at /.codec decoded) + (pipe.case + {try.#Success _} true + {try.#Failure error} false)) + + invalid! + (|> + %.nat + (text.prefix ) + (text.suffix ) + (at /.codec decoded) + (pipe.case + {try.#Success _} + false + + {try.#Failure error} + (exception.match? error)))] + (and valid! + invalid!)))] + + [/.hours /.invalid_hour "" ":00:00.000" valid_hour invalid_hour] + [/.minutes /.invalid_minute "00:" ":00.000" valid_minute invalid_minute] + [/.seconds /.invalid_second "00:00:" ".000" valid_second invalid_second] + )) + (_.coverage [/.milli_seconds] + (|> valid_milli_second + %.nat + (format "00:00:00.") + (at /.codec decoded) + (pipe.case + {try.#Success _} true + {try.#Failure error} false))) + )))) + +(def .public test + Test + (<| (_.covering /._) + (_.for [/.Time]) + (do [! random.monad] + [.let [day (.nat (duration.millis duration.day))] + expected random.time + + out_of_bounds (at ! each (|>> /.millis (n.+ day)) + random.time)] + (`` (all _.and + ..for_implementation + + (_.coverage [/.millis /.of_millis] + (|> expected + /.millis + /.of_millis + (try#each (at /.equivalence = expected)) + (try.else false))) + (_.coverage [/.time_exceeds_a_day] + (case (/.of_millis out_of_bounds) + {try.#Success _} + false + + {try.#Failure error} + (exception.match? /.time_exceeds_a_day error))) + (_.coverage [/.midnight] + (|> /.midnight + /.millis + (n.= 0))) + (_.coverage [/.parser] + (|> expected + (at /.codec encoded) + (.result /.parser) + (try#each (at /.equivalence = expected)) + (try.else false))) + ..for_ranges + (_.for [/.Clock] + ..for_clock) + + /date.test + /day.test + /duration.test + /instant.test + /month.test + /year.test + ))))) diff --git a/stdlib/source/test/lux/world/time/date.lux b/stdlib/source/test/lux/world/time/date.lux new file mode 100644 index 000000000..c97fd626e --- /dev/null +++ b/stdlib/source/test/lux/world/time/date.lux @@ -0,0 +1,95 @@ +(.require + [library + [lux (.except) + ["_" test (.only Test)] + [abstract + [monad (.only do)] + [\\specification + ["$[0]" equivalence] + ["$[0]" order] + ["$[0]" enum] + ["$[0]" codec]]] + [control + ["[0]" try (.use "[1]#[0]" functor)] + ["[0]" exception]] + [data + ["[0]" text + ["%" \\format (.only format)] + ["<[1]>" \\parser]]] + [math + ["[0]" random (.only Random)] + [number + ["n" nat] + ["i" int]]]]] + [\\library + ["[0]" /]]) + +(def .public test + Test + (<| (_.covering /._) + (_.for [/.Date]) + (all _.and + (_.for [/.equivalence] + ($equivalence.spec /.equivalence random.date)) + (_.for [/.order] + ($order.spec /.order random.date)) + (_.for [/.enum] + ($enum.spec /.enum random.date)) + (_.for [/.codec] + ($codec.spec /.equivalence /.codec random.date)) + + (do random.monad + [expected random.date] + (_.coverage [/.date /.year /.month /.day_of_month] + (|> (/.date (/.year expected) + (/.month expected) + (/.day_of_month expected)) + (try#each (at /.equivalence = expected)) + (try.else false)))) + (do random.monad + [expected random.date] + (_.coverage [/.invalid_day] + (case (/.date (/.year expected) + (/.month expected) + (n.+ 31 (/.day_of_month expected))) + {try.#Failure error} + (exception.match? /.invalid_day error) + + {try.#Success _} + false))) + (do random.monad + [expected random.date] + (_.coverage [/.days /.of_days] + (|> expected + /.days + /.of_days + (at /.equivalence = expected)))) + (_.coverage [/.epoch] + (|> /.epoch + /.days + (i.= +0))) + (do random.monad + [expected random.date] + (_.coverage [/.parser] + (|> (at /.codec encoded expected) + (.result /.parser) + (try#each (at /.equivalence = expected)) + (try.else false)))) + (do [! random.monad] + [year (at ! each (|>> (n.% 10,000) ++) + random.nat) + month (at ! each (|>> (n.% 10) (n.+ 13)) + random.nat) + day (at ! each (|>> (n.% 10) (n.+ 10)) + random.nat) + .let [input (format (%.nat year) + "-" (%.nat month) + "-" (%.nat day))]] + (_.coverage [/.invalid_month] + (case (.result /.parser input) + {try.#Failure error} + (exception.match? /.invalid_month error) + + {try.#Success _} + false))) + ))) diff --git a/stdlib/source/test/lux/world/time/day.lux b/stdlib/source/test/lux/world/time/day.lux new file mode 100644 index 000000000..eecc8a0fb --- /dev/null +++ b/stdlib/source/test/lux/world/time/day.lux @@ -0,0 +1,89 @@ +(.require + [library + [lux (.except) + ["_" test (.only Test)] + [abstract + [monad (.only do)] + [\\specification + ["$[0]" equivalence] + ["$[0]" hash] + ["$[0]" order] + ["$[0]" enum] + ["$[0]" codec]]] + [control + ["[0]" try (.use "[1]#[0]" functor)] + ["[0]" exception] + [function + ["[0]" predicate]]] + [data + [collection + ["[0]" list] + ["[0]" set]]] + [math + ["[0]" random (.only Random) (.use "[1]#[0]" monad)] + [number + ["n" nat]]]]] + [\\library + ["[0]" /]]) + +(def .public random + (Random /.Day) + (random.either (random.either (random.either (random#in {/.#Sunday}) + (random#in {/.#Monday})) + (random.either (random#in {/.#Tuesday}) + (random#in {/.#Wednesday}))) + (random.either (random.either (random#in {/.#Thursday}) + (random#in {/.#Friday})) + (random#in {/.#Saturday})))) + +(def .public test + Test + (<| (_.covering /._) + (_.for [/.Day]) + (do random.monad + [expected ..random + invalid (random.only (predicate.or (n.< (/.number {/.#Sunday})) + (n.> (/.number {/.#Saturday}))) + random.nat)] + (all _.and + (_.for [/.equivalence] + ($equivalence.spec /.equivalence ..random)) + (_.for [/.hash] + ($hash.spec /.hash ..random)) + (_.for [/.order] + ($order.spec /.order ..random)) + (_.for [/.enum] + ($enum.spec /.enum ..random)) + (_.for [/.codec] + ($codec.spec /.equivalence /.codec ..random)) + + (do random.monad + [not_a_day (random.upper_case 1)] + (_.coverage [/.not_a_day_of_the_week] + (case (at /.codec decoded not_a_day) + {try.#Failure error} + (exception.match? /.not_a_day_of_the_week error) + + {try.#Success _} + false))) + (_.coverage [/.number /.by_number] + (|> expected + /.number + /.by_number + (try#each (at /.equivalence = expected)) + (try.else false))) + (_.coverage [/.invalid_day] + (case (/.by_number invalid) + {try.#Failure error} + (exception.match? /.invalid_day error) + + {try.#Success _} + false)) + (_.coverage [/.week] + (let [all (list.size /.week) + uniques (set.size (set.of_list /.hash /.week))] + (and (n.= (/.number {/.#Saturday}) + all) + (n.= all + uniques)))) + )))) diff --git a/stdlib/source/test/lux/world/time/duration.lux b/stdlib/source/test/lux/world/time/duration.lux new file mode 100644 index 000000000..e73108548 --- /dev/null +++ b/stdlib/source/test/lux/world/time/duration.lux @@ -0,0 +1,100 @@ +(.require + [library + [lux (.except) + ["_" test (.only Test)] + [abstract + [monad (.only do)] + [\\specification + ["$[0]" equivalence] + ["$[0]" order] + ["$[0]" enum] + ["$[0]" monoid] + ["$[0]" codec]]] + [data + ["[0]" bit (.use "[1]#[0]" equivalence)]] + [math + ["[0]" random (.only Random)] + [number + ["n" nat] + ["i" int]]]]] + [\\library + ["[0]" /]]) + +(def .public test + Test + (<| (_.covering /._) + (_.for [/.Duration]) + (all _.and + (_.for [/.equivalence] + ($equivalence.spec /.equivalence random.duration)) + (_.for [/.order] + ($order.spec /.order random.duration)) + (_.for [/.enum] + ($enum.spec /.enum random.duration)) + (_.for [/.monoid] + ($monoid.spec /.equivalence /.monoid random.duration)) + (_.for [/.codec] + ($codec.spec /.equivalence /.codec random.duration)) + + (do random.monad + [duration random.duration] + (_.coverage [/.of_millis /.millis] + (|> duration /.millis /.of_millis (at /.equivalence = duration)))) + (do random.monad + [.let [(open "#[0]") /.equivalence] + expected random.duration + parameter random.duration] + (all _.and + (_.coverage [/.composite /.difference] + (|> expected (/.composite parameter) (/.difference parameter) (#= expected))) + (_.coverage [/.empty] + (|> expected (/.composite /.empty) (#= expected))) + (_.coverage [/.inverse] + (and (|> expected /.inverse /.inverse (#= expected)) + (|> expected (/.composite (/.inverse expected)) (#= /.empty)))) + (_.coverage [/.positive? /.negative? /.neutral?] + (or (bit#= (/.positive? expected) + (/.negative? (/.inverse expected))) + (bit#= (/.neutral? expected) + (/.neutral? (/.inverse expected))))) + )) + (do random.monad + [.let [(open "#[0]") /.equivalence] + factor random.nat] + (_.coverage [/.up /.down] + (|> /.milli_second (/.up factor) (/.down factor) (#= /.milli_second)))) + (do [! random.monad] + [.let [(open "#[0]") /.order + positive (|> random.duration + (random.only (|>> (#= /.empty) not)) + (at ! each (function (_ duration) + (if (/.positive? duration) + duration + (/.inverse duration)))))] + sample positive + frame positive] + (`` (all _.and + (_.coverage [/.framed] + (let [sample' (/.framed frame sample)] + (and (#< frame sample') + (bit#= (#< frame sample) + (#= sample sample'))))) + (_.coverage [/.ticks] + (i.= +1 (/.ticks sample sample))) + (_.coverage [/.milli_second] + (#= /.empty (at /.enum pred /.milli_second))) + (,, (with_template [ ] + [(_.coverage [] + (|> (/.ticks ) (i.= )))] + + [+1,000 /.second /.milli_second] + [+60 /.minute /.second] + [+60 /.hour /.minute] + [+24 /.day /.hour] + + [+7 /.week /.day] + [+365 /.normal_year /.day] + [+366 /.leap_year /.day] + )) + ))) + ))) diff --git a/stdlib/source/test/lux/world/time/instant.lux b/stdlib/source/test/lux/world/time/instant.lux new file mode 100644 index 000000000..56a4749ec --- /dev/null +++ b/stdlib/source/test/lux/world/time/instant.lux @@ -0,0 +1,106 @@ +(.require + [library + [lux (.except) + ["_" test (.only Test)] + [abstract + [monad (.only do)] + [\\specification + ["$[0]" equivalence] + ["$[0]" order] + ["$[0]" enum] + ["$[0]" codec]]] + [control + ["[0]" function] + ["[0]" try] + ["[0]" io]] + [data + [collection + ["[0]" list (.use "[1]#[0]" mix)]]] + [math + ["[0]" random]]]] + [\\library + ["[0]" / (.only) + [// + ["[0]" duration (.only Duration)] + ["[0]" day (.only Day) (.use "[1]#[0]" enum)]]]]) + +(def .public test + Test + (<| (_.covering /._) + (_.for [/.Instant]) + (all _.and + (_.for [/.equivalence] + ($equivalence.spec /.equivalence random.instant)) + (_.for [/.order] + ($order.spec /.order random.instant)) + (_.for [/.enum] + ($enum.spec /.enum random.instant)) + (_.for [/.codec] + ($codec.spec /.equivalence /.codec random.instant)) + + (do random.monad + [.let [(open "#[0]") /.equivalence] + expected random.instant] + (all _.and + (_.coverage [/.millis /.of_millis] + (|> expected /.millis /.of_millis (#= expected))) + (_.coverage [/.relative /.absolute] + (|> expected /.relative /.absolute (#= expected))) + (_.coverage [/.date /.time /.of_date_time] + (#= expected + (/.of_date_time (/.date expected) + (/.time expected)))) + )) + (do random.monad + [.let [(open "#[0]") /.equivalence + (open "duration#[0]") duration.equivalence] + from random.instant + to random.instant] + (all _.and + (_.coverage [/.span] + (|> from (/.span from) (duration#= duration.empty))) + (_.coverage [/.after] + (|> from (/.after (/.span from to)) (#= to))) + (_.coverage [/.epoch] + (duration#= (/.relative to) + (/.span /.epoch to))) + )) + (do random.monad + [instant random.instant + .let [d0 (/.day_of_week instant)]] + (_.coverage [/.day_of_week] + (let [apply (is (-> (-> Duration Duration) (-> Day Day) Nat Bit) + (function (_ polarity move steps) + (let [day_shift (list#mix (function.constant move) + d0 + (list.repeated steps [])) + instant_shift (|> instant + (/.after (polarity (duration.up steps duration.day))) + /.day_of_week)] + (day#= day_shift + instant_shift))))] + (and (apply function.identity day#succ 0) + (apply function.identity day#succ 1) + (apply function.identity day#succ 2) + (apply function.identity day#succ 3) + (apply function.identity day#succ 4) + (apply function.identity day#succ 5) + (apply function.identity day#succ 6) + (apply function.identity day#succ 7) + + (apply duration.inverse day#pred 0) + (apply duration.inverse day#pred 1) + (apply duration.inverse day#pred 2) + (apply duration.inverse day#pred 3) + (apply duration.inverse day#pred 4) + (apply duration.inverse day#pred 5) + (apply duration.inverse day#pred 6) + (apply duration.inverse day#pred 7))))) + (_.coverage [/.now] + (case (try (io.run! /.now)) + {try.#Success _} + true + + {try.#Failure _} + false)) + ))) diff --git a/stdlib/source/test/lux/world/time/month.lux b/stdlib/source/test/lux/world/time/month.lux new file mode 100644 index 000000000..c87a956cd --- /dev/null +++ b/stdlib/source/test/lux/world/time/month.lux @@ -0,0 +1,101 @@ +(.require + [library + [lux (.except) + ["_" test (.only Test)] + [abstract + [monad (.only do)] + [\\specification + ["$[0]" equivalence] + ["$[0]" hash] + ["$[0]" order] + ["$[0]" enum] + ["$[0]" codec]]] + [control + ["[0]" try (.use "[1]#[0]" functor)] + ["[0]" exception] + [function + ["[0]" predicate]]] + [data + [collection + ["[0]" set] + ["[0]" list (.use "[1]#[0]" functor mix)]]] + [math + ["[0]" random (.only Random)] + [number + ["n" nat]]]]] + [\\library + ["[0]" / (.only) + [// + ["[0]" duration]]]]) + +(def .public random + (Random /.Month) + (let [december (/.number {/.#December})] + (|> random.nat + (at random.monad each (|>> (n.% december) ++)) + (random.one (|>> /.by_number try.maybe))))) + +(def .public test + Test + (<| (_.covering /._) + (_.for [/.Month]) + (all _.and + (_.for [/.equivalence] + ($equivalence.spec /.equivalence ..random)) + (_.for [/.hash] + ($hash.spec /.hash ..random)) + (_.for [/.order] + ($order.spec /.order ..random)) + (_.for [/.enum] + ($enum.spec /.enum ..random)) + (_.for [/.codec] + ($codec.spec /.equivalence /.codec ..random)) + + (do random.monad + [expected ..random + invalid (random.only (predicate.or (n.< (/.number {/.#January})) + (n.> (/.number {/.#December}))) + random.nat)] + (all _.and + (_.coverage [/.number /.by_number] + (|> expected + /.number + /.by_number + (try#each (at /.equivalence = expected)) + (try.else false))) + (_.coverage [/.invalid_month] + (case (/.by_number invalid) + {try.#Failure error} + (exception.match? /.invalid_month error) + + {try.#Success _} + false)) + (_.coverage [/.year] + (let [all (list.size /.year) + uniques (set.size (set.of_list /.hash /.year))] + (and (n.= (/.number {/.#December}) + all) + (n.= all + uniques)))) + (_.coverage [/.days] + (let [expected (.nat (duration.ticks duration.day duration.normal_year))] + (|> /.year + (list#each /.days) + (list#mix n.+ 0) + (n.= expected)))) + (_.coverage [/.leap_year_days] + (let [expected (.nat (duration.ticks duration.day duration.leap_year))] + (|> /.year + (list#each /.leap_year_days) + (list#mix n.+ 0) + (n.= expected)))) + (do random.monad + [not_a_month (random.upper_case 1)] + (_.coverage [/.not_a_month_of_the_year] + (case (at /.codec decoded not_a_month) + {try.#Failure error} + (exception.match? /.not_a_month_of_the_year error) + + {try.#Success _} + false))) + ))))) diff --git a/stdlib/source/test/lux/world/time/year.lux b/stdlib/source/test/lux/world/time/year.lux new file mode 100644 index 000000000..0e0dee518 --- /dev/null +++ b/stdlib/source/test/lux/world/time/year.lux @@ -0,0 +1,97 @@ +(.require + [library + [lux (.except) + ["_" test (.only Test)] + [abstract + [monad (.only do)] + [\\specification + ["$[0]" equivalence] + ["$[0]" order] + ["$[0]" codec]]] + [control + ["[0]" try] + ["[0]" exception]] + [data + ["[0]" bit (.use "[1]#[0]" equivalence)] + [text + ["%" \\format (.only format)]]] + [math + ["[0]" random (.only Random)] + [number + ["n" nat] + ["i" int]]]]] + [\\library + ["[0]" / (.only) + ["/[1]" // (.only) + ["[1][0]" duration] + ["[1][0]" instant] + ["[1][0]" date]]]]) + +(def .public random + (Random /.Year) + (random.one (|>> /.year try.maybe) random.int)) + +(def .public test + Test + (<| (_.covering /._) + (_.for [/.Year]) + (all _.and + (_.for [/.equivalence] + ($equivalence.spec /.equivalence ..random)) + (_.for [/.order] + ($order.spec /.order ..random)) + (_.for [/.codec /.parser] + ($codec.spec /.equivalence /.codec ..random)) + + (do random.monad + [expected random.int] + (all _.and + (_.coverage [/.year] + (bit#= (i.= +0 expected) + (case (/.year expected) + {try.#Success _} + false + + {try.#Failure _} + true))) + (_.coverage [/.value] + (case (/.year expected) + {try.#Success year} + (i.= expected (/.value year)) + + {try.#Failure _} + (i.= +0 expected))) + )) + (_.coverage [/.there_is_no_year_0] + (case (/.year +0) + {try.#Success _} + false + + {try.#Failure error} + (exception.match? /.there_is_no_year_0 error))) + (_.coverage [/.days] + (n.= (.nat (//duration.ticks //duration.day //duration.normal_year)) + /.days)) + (_.coverage [/.epoch] + (at /.equivalence = + (//date.year (//instant.date //instant.epoch)) + /.epoch)) + (_.for [/.Period] + (_.coverage [/.leap /.century /.era] + (n.= /.leap (n./ /.century /.era)))) + (let [leap (try.trusted (/.year (.int /.leap))) + century (try.trusted (/.year (.int /.century))) + era (try.trusted (/.year (.int /.era)))] + (all _.and + (_.coverage [/.leap?] + (and (/.leap? leap) + (not (/.leap? century)) + (/.leap? era))) + (_.coverage [/.leaps] + (and (i.= +1 (/.leaps leap)) + (i.= (.int (n./ /.leap /.century)) + (/.leaps century)) + (i.= (++ (i.* +4 (-- (/.leaps century)))) + (/.leaps era)))) + )) + ))) -- cgit v1.2.3