aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/world
diff options
context:
space:
mode:
authorEduardo Julian2022-12-12 03:47:35 -0400
committerEduardo Julian2022-12-12 03:47:35 -0400
commitfe9a58dfcd5732ef0c5e5c4b7e85370cdc0db45a (patch)
tree5ad844ea2bdf33a67cceaad437efaf82cf773a02 /stdlib/source/test/lux/world
parenteef4422b1f16be2b8c651461f2c006dc4c11f314 (diff)
Added trade session (OHLCV) abstraction.
Diffstat (limited to '')
-rw-r--r--stdlib/source/test/lux/world.lux11
-rw-r--r--stdlib/source/test/lux/world/finance/money.lux (renamed from stdlib/source/test/lux/world/money.lux)58
-rw-r--r--stdlib/source/test/lux/world/finance/money/currency.lux (renamed from stdlib/source/test/lux/world/money/currency.lux)0
-rw-r--r--stdlib/source/test/lux/world/finance/trade/session.lux89
4 files changed, 126 insertions, 32 deletions
diff --git a/stdlib/source/test/lux/world.lux b/stdlib/source/test/lux/world.lux
index e1309f5f5..bf9ff3c7f 100644
--- a/stdlib/source/test/lux/world.lux
+++ b/stdlib/source/test/lux/world.lux
@@ -13,7 +13,10 @@
["[1][0]" output
["[1]/[0]" video
["[1]/[0]" resolution]]]
- ["[1][0]" money]
+ ["[1][0]" finance
+ ["[1]/[0]" money]
+ ["[1]/[0]" trade
+ ["[1]/[0]" session]]]
["[1][0]" net]
["[1][0]" time]
["[1][0]" locale]
@@ -26,9 +29,13 @@
/shell.test
/console.test
/environment.test
+
/input/keyboard.test
/output/video/resolution.test
- /money.test
+
+ /finance/money.test
+ /finance/trade/session.test
+
/net.test
/time.test
/locale.test
diff --git a/stdlib/source/test/lux/world/money.lux b/stdlib/source/test/lux/world/finance/money.lux
index 4cddc38ee..773589a15 100644
--- a/stdlib/source/test/lux/world/money.lux
+++ b/stdlib/source/test/lux/world/finance/money.lux
@@ -13,48 +13,46 @@
["[0]" text (.only)
["%" \\format]]]
[math
- ["[0]" random (.only Random)]
+ ["[0]" random (.only Random) (.use "[1]#[0]" functor)]
[number
["n" nat]]]
[test
["_" property (.only Test)]]]]
[\\library
["[0]" / (.only)
- ["[0]" currency]]]
+ ["[0]" currency (.only Currency)]]]
["[0]" /
["[1][0]" currency]])
-(def .public random
- (Random (Ex (_ of)
- (/.Money of)))
- (do random.monad
- [expected_currency /currency.random
- expected_amount random.nat]
- (in (/.money expected_currency expected_amount))))
+(def .public (random $)
+ (All (_ $)
+ (-> (Currency $)
+ (Random (/.Money $))))
+ (random#each (/.money $)
+ random.nat))
(def .public test
Test
(<| (_.covering /._)
(do [! random.monad]
- [.let [expected_currency currency.usd]
- expected_amount random.nat
+ [expected_amount random.nat
expected_parameter (random.only (n.> 0) random.nat)
expected_subject random.nat])
(_.for [/.Money])
(all _.and
(_.for [/.equivalence /.=]
- (equivalenceS.spec /.equivalence ..random))
+ (equivalenceS.spec /.equivalence (..random currency.usd)))
(_.for [/.order /.<]
- (orderS.spec /.order ..random))
+ (orderS.spec /.order (..random currency.usd)))
(_.coverage [/.money /.currency /.amount]
- (let [it (/.money expected_currency expected_amount)]
- (and (same? expected_currency (/.currency it))
+ (let [it (/.money currency.usd expected_amount)]
+ (and (same? currency.usd (/.currency it))
(same? expected_amount (/.amount it)))))
(_.coverage [/.+ /.-]
- (let [parameter (/.money expected_currency expected_parameter)
- subject (/.money expected_currency expected_subject)]
+ (let [parameter (/.money currency.usd expected_parameter)
+ subject (/.money currency.usd expected_subject)]
(and (|> subject
(/.+ parameter)
(of /.equivalence = subject)
@@ -65,21 +63,21 @@
(maybe#each (of /.equivalence = subject))
(maybe.else false)))))
(_.coverage [/.min]
- (let [expected_parameter (/.money expected_currency expected_parameter)
- expected_subject (/.money expected_currency expected_subject)]
+ (let [expected_parameter (/.money currency.usd expected_parameter)
+ expected_subject (/.money currency.usd expected_subject)]
(and (/.<= expected_parameter
(/.min expected_parameter expected_subject))
(/.<= expected_subject
(/.min expected_parameter expected_subject)))))
(_.coverage [/.max]
- (let [expected_parameter (/.money expected_currency expected_parameter)
- expected_subject (/.money expected_currency expected_subject)]
+ (let [expected_parameter (/.money currency.usd expected_parameter)
+ expected_subject (/.money currency.usd expected_subject)]
(and (/.>= expected_parameter
(/.max expected_parameter expected_subject))
(/.>= expected_subject
(/.max expected_parameter expected_subject)))))
- (let [expected_parameter (/.money expected_currency expected_parameter)
- expected_subject (/.money expected_currency expected_subject)]
+ (let [expected_parameter (/.money currency.usd expected_parameter)
+ expected_subject (/.money currency.usd expected_subject)]
(all _.and
(_.coverage [/.>]
(bit#= (/.> expected_parameter expected_subject)
@@ -89,17 +87,17 @@
(/.>= expected_subject expected_parameter)))
))
(_.coverage [/.units /.sub_units]
- (let [expected (/.money expected_currency expected_amount)
- actual (/.money expected_currency (n.+ (/.units expected)
- (/.sub_units expected)))]
+ (let [expected (/.money currency.usd expected_amount)
+ actual (/.money currency.usd (n.+ (/.units expected)
+ (/.sub_units expected)))]
(/.= expected actual)))
(_.coverage [/.of_units /.of_sub_units]
- (let [expected (/.money expected_currency expected_amount)
- actual (/.+ (/.of_units expected_currency (/.units expected))
- (/.of_sub_units expected_currency (/.sub_units expected)))]
+ (let [expected (/.money currency.usd expected_amount)
+ actual (/.+ (/.of_units currency.usd (/.units expected))
+ (/.of_sub_units currency.usd (/.sub_units expected)))]
(/.= expected actual)))
(do !
- [it ..random]
+ [it (..random currency.usd)]
(_.coverage [/.format]
(and (text.starts_with? (%.nat (/.amount it))
(text.replaced_once "." "" (/.format it)))
diff --git a/stdlib/source/test/lux/world/money/currency.lux b/stdlib/source/test/lux/world/finance/money/currency.lux
index eeb59e9fc..eeb59e9fc 100644
--- a/stdlib/source/test/lux/world/money/currency.lux
+++ b/stdlib/source/test/lux/world/finance/money/currency.lux
diff --git a/stdlib/source/test/lux/world/finance/trade/session.lux b/stdlib/source/test/lux/world/finance/trade/session.lux
new file mode 100644
index 000000000..6ce1979d2
--- /dev/null
+++ b/stdlib/source/test/lux/world/finance/trade/session.lux
@@ -0,0 +1,89 @@
+(.require
+ [library
+ [lux (.except)
+ [abstract
+ [monad (.only do)]
+ [\\specification
+ ["[0]S" equivalence]]]
+ [data
+ ["[0]" bit (.use "[1]#[0]" equivalence)]
+ ["[0]" text (.use "[1]#[0]" equivalence)]
+ [collection
+ ["[0]" list]]]
+ [math
+ ["[0]" random (.only Random)]
+ [number
+ ["n" nat]]]
+ [test
+ ["_" property (.only Test)]]]]
+ [\\library
+ ["[0]" / (.only)
+ [///
+ ["[0]" money (.only)
+ ["[0]" currency (.only Currency)]]]]]
+ [///
+ ["[0]T" money]])
+
+(def .public (random $)
+ (All (_ $)
+ (-> (Currency $)
+ (Random (/.Session $))))
+ (do random.monad
+ [p0 (moneyT.random $)
+ p1 (moneyT.random $)
+ p2 (moneyT.random $)
+ p3 (moneyT.random $)
+ bullish? random.bit
+ volume random.nat]
+ (when (list.sorted money.< (list p0 p1 p2 p3))
+ (list low bottom top high)
+ (in [/.#open (if bullish?
+ bottom
+ top)
+ /.#high high
+ /.#low low
+ /.#close (if bullish?
+ top
+ bottom)
+ /.#volume volume])
+
+ _
+ (undefined))))
+
+(def .public test
+ Test
+ (<| (_.covering /._)
+ (do [! random.monad]
+ [before (..random currency.usd)
+ after (..random currency.usd)])
+ (_.for [/.Session /.Price /.Volume
+ /.#open /.#high /.#low /.#close /.#volume])
+ (all _.and
+ (_.for [/.equivalence]
+ (equivalenceS.spec /.equivalence (..random currency.usd)))
+
+ (_.coverage [/.composite]
+ (let [both (/.composite before after)]
+ (and (money.= (the /.#open before)
+ (the /.#open both))
+ (and (money.>= (the /.#high before)
+ (the /.#high both))
+ (money.>= (the /.#high after)
+ (the /.#high both)))
+ (and (money.<= (the /.#low before)
+ (the /.#low both))
+ (money.<= (the /.#low after)
+ (the /.#low both)))
+ (money.= (the /.#close after)
+ (the /.#close both))
+ (and (n.>= (the /.#volume before)
+ (the /.#volume both))
+ (n.>= (the /.#volume after)
+ (the /.#volume both))))))
+ (_.coverage [/.format]
+ (bit#= (of /.equivalence =
+ before
+ after)
+ (text#= (/.format before)
+ (/.format after))))
+ )))