From fe9a58dfcd5732ef0c5e5c4b7e85370cdc0db45a Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 12 Dec 2022 03:47:35 -0400 Subject: Added trade session (OHLCV) abstraction. --- .../lux/data/collection/dictionary/ordered.lux | 3 +- stdlib/source/test/lux/data/color.lux | 85 ------- stdlib/source/test/lux/data/color/hsl.lux | 95 ++++++-- stdlib/source/test/lux/data/color/rgb.lux | 18 +- stdlib/source/test/lux/meta/extension.lux | 2 +- stdlib/source/test/lux/world.lux | 11 +- stdlib/source/test/lux/world/finance/money.lux | 108 +++++++++ .../test/lux/world/finance/money/currency.lux | 259 +++++++++++++++++++++ .../test/lux/world/finance/trade/session.lux | 89 +++++++ stdlib/source/test/lux/world/money.lux | 110 --------- stdlib/source/test/lux/world/money/currency.lux | 259 --------------------- 11 files changed, 552 insertions(+), 487 deletions(-) create mode 100644 stdlib/source/test/lux/world/finance/money.lux create mode 100644 stdlib/source/test/lux/world/finance/money/currency.lux create mode 100644 stdlib/source/test/lux/world/finance/trade/session.lux delete mode 100644 stdlib/source/test/lux/world/money.lux delete mode 100644 stdlib/source/test/lux/world/money/currency.lux (limited to 'stdlib/source/test') diff --git a/stdlib/source/test/lux/data/collection/dictionary/ordered.lux b/stdlib/source/test/lux/data/collection/dictionary/ordered.lux index d1c9ba933..410580860 100644 --- a/stdlib/source/test/lux/data/collection/dictionary/ordered.lux +++ b/stdlib/source/test/lux/data/collection/dictionary/ordered.lux @@ -42,7 +42,8 @@ (def .public test Test (<| (_.covering /._) - (_.for [/.Dictionary]) + (_.for [/.Dictionary + /.#order /.#root]) (do [! random.monad] [size (of ! each (n.% 100) random.nat) keys (random.set n.hash size random.nat) diff --git a/stdlib/source/test/lux/data/color.lux b/stdlib/source/test/lux/data/color.lux index ee2eb70b2..25c041fd7 100644 --- a/stdlib/source/test/lux/data/color.lux +++ b/stdlib/source/test/lux/data/color.lux @@ -36,68 +36,6 @@ (Random /.Color) (random#each /.of_rgb /rgb.random)) -(def scale - (-> Nat Frac) - (|>> .int int.frac)) - -(def square - (-> Frac Frac) - (f.pow +2.0)) - -(def square_root - (-> Frac Frac) - (f.pow +0.5)) - -(def (distance/3 from to) - (-> /.Color /.Color Frac) - (let [from (/.rgb from) - to (/.rgb to)] - (square_root - (all f.+ - (|> (scale (rgb.red to)) (f.- (scale (rgb.red from))) square) - (|> (scale (rgb.green to)) (f.- (scale (rgb.green from))) square) - (|> (scale (rgb.blue to)) (f.- (scale (rgb.blue from))) square))))) - -(def rgb_error_margin - +1.8) - -(with_template [ ] - [(def - (-> /.Color Frac) - (|>> /.rgb - hsl.of_rgb - ))] - - [saturation hsl.saturation] - [luminance hsl.luminance] - ) - -... (def transformation -... Test -... (do random.monad -... [mediocre (|> ..random -... (random.only (|>> saturation -... ((function (_ saturation) -... (and (f.>= +0.25 saturation) -... (f.<= +0.75 saturation))))))) -... ratio (|> random.safe_frac (random.only (f.>= +0.5)))] -... (all _.and -... (_.coverage [/.saturated] -... (f.> (saturation mediocre) -... (saturation (/.saturated ratio mediocre)))) -... (_.coverage [/.un_saturated] -... (f.< (saturation mediocre) -... (saturation (/.un_saturated ratio mediocre)))) -... (_.coverage [/.gray_scale] -... (let [gray'ed (/.gray_scale mediocre)] -... (and (f.= +0.0 -... (saturation gray'ed)) -... (|> (luminance gray'ed) -... (f.- (luminance mediocre)) -... f.abs -... (f.<= ..rgb_error_margin))))) -... ))) - ... (def palette ... Test ... (_.for [/.Spread /.Palette] @@ -123,28 +61,6 @@ ... [+1.0 /.analogous] ... [+0.5 /.monochromatic] ... )) -... (,, (with_template [] -... [(_.coverage [] -... (let [expected (/.of_hsb [eH eS +0.5]) -... [c0 c1 c2] ( expected)] -... (and (of /.equivalence = expected c0) -... (not (of /.equivalence = expected c1)) -... (not (of /.equivalence = expected c2)))))] - -... [/.triad] -... [/.clash] -... [/.split_complement])) -... (,, (with_template [] -... [(_.coverage [] -... (let [expected (/.of_hsb [eH eS +0.5]) -... [c0 c1 c2 c3] ( expected)] -... (and (of /.equivalence = expected c0) -... (not (of /.equivalence = expected c1)) -... (not (of /.equivalence = expected c2)) -... (not (of /.equivalence = expected c3)))))] - -... [/.square] -... [/.tetradic])) ... ))))) (def .public test @@ -154,7 +70,6 @@ (do [! random.monad] [expected ..random] (all _.and - ... ..transformation ... ..palette /rgb.test diff --git a/stdlib/source/test/lux/data/color/hsl.lux b/stdlib/source/test/lux/data/color/hsl.lux index 72782e0f2..de9c3ef8a 100644 --- a/stdlib/source/test/lux/data/color/hsl.lux +++ b/stdlib/source/test/lux/data/color/hsl.lux @@ -14,7 +14,8 @@ [\\library ["[0]" / (.only) [// - ["[0]" rgb]]]] + ["[0]" rgb] + ["[0]" hsb]]]] [// ["[0]T" rgb]]) @@ -30,6 +31,9 @@ luminance ..value] (in (/.hsl hue saturation luminance)))) +(def rgb_error_margin + +1.8) + (def .public test Test (<| (_.covering /._) @@ -38,7 +42,18 @@ expected_rgb rgbT.random expected_hsl ..random - possible_value random.frac]) + possible_value random.frac + + mediocre (|> ..random + (random.only (|>> (the /.#saturation) + ((function (_ it) + (and (f.>= +0.25 it) + (f.<= +0.75 it))))))) + ratio (|> random.safe_frac (random.only (f.>= +0.5))) + + eH (of ! each (|>> f.abs (f.% +0.9) (f.+ +0.05)) + random.safe_frac) + .let [eS +0.5]]) (all _.and (_.for [/.Value] (all _.and @@ -66,23 +81,63 @@ (/.value? (f.- f.smallest /.most)) (not (/.value? (f.+ f.smallest /.most))))) )) - (_.for [/.HSL] - (all _.and - (_.for [/.equivalence] - (equivalenceS.spec /.equivalence ..random)) + (_.for [/.HSL + /.#hue /.#saturation /.#luminance] + (`` (all _.and + (_.for [/.equivalence] + (equivalenceS.spec /.equivalence ..random)) - (_.coverage [/.hsl - /.hue /.saturation /.luminance] - (|> (/.hsl (/.hue expected_hsl) (/.saturation expected_hsl) (/.luminance expected_hsl)) - (of /.equivalence = expected_hsl))) - (_.coverage [/.of_rgb /.rgb] - (and (|> expected_rgb - /.of_rgb - /.rgb - (of rgb.equivalence = expected_rgb)) - (|> expected_hsl - /.rgb - /.of_rgb - (of /.equivalence = expected_hsl)))) - )) + (_.coverage [/.hsl] + (|> (/.hsl (the /.#hue expected_hsl) + (the /.#saturation expected_hsl) + (the /.#luminance expected_hsl)) + (of /.equivalence = expected_hsl))) + (_.coverage [/.of_rgb /.rgb] + (and (|> expected_rgb + /.of_rgb + /.rgb + (of rgb.equivalence = expected_rgb)) + (|> expected_hsl + /.rgb + /.of_rgb + (of /.equivalence = expected_hsl)))) + + (_.coverage [/.saturated] + (f.> (the /.#saturation mediocre) + (the /.#saturation (/.saturated ratio mediocre)))) + (_.coverage [/.un_saturated] + (f.< (the /.#saturation mediocre) + (the /.#saturation (/.un_saturated ratio mediocre)))) + (_.coverage [/.gray_scale] + (let [gray'ed (/.gray_scale mediocre)] + (and (f.= +0.0 + (the /.#saturation gray'ed)) + (|> (the /.#luminance gray'ed) + (f.- (the /.#luminance mediocre)) + f.abs + (f.<= ..rgb_error_margin))))) + + (,, (with_template [] + [(_.coverage [] + (let [expected (/.of_rgb (hsb.rgb (hsb.hsb eH eS +0.5))) + [c0 c1 c2] ( expected)] + (and (of /.equivalence = expected c0) + (not (of /.equivalence = expected c1)) + (not (of /.equivalence = expected c2)))))] + + [/.triad] + [/.clash] + [/.split_complement])) + (,, (with_template [] + [(_.coverage [] + (let [expected (/.of_rgb (hsb.rgb (hsb.hsb eH eS +0.5))) + [c0 c1 c2 c3] ( expected)] + (and (of /.equivalence = expected c0) + (not (of /.equivalence = expected c1)) + (not (of /.equivalence = expected c2)) + (not (of /.equivalence = expected c3)))))] + + [/.square] + [/.tetradic])) + ))) ))) diff --git a/stdlib/source/test/lux/data/color/rgb.lux b/stdlib/source/test/lux/data/color/rgb.lux index 19094bfe2..4325eb72b 100644 --- a/stdlib/source/test/lux/data/color/rgb.lux +++ b/stdlib/source/test/lux/data/color/rgb.lux @@ -55,9 +55,9 @@ Frac) (square_root (all f.+ - (|> (scale (/.red to)) (f.- (scale (/.red from))) square) - (|> (scale (/.green to)) (f.- (scale (/.green from))) square) - (|> (scale (/.blue to)) (f.- (scale (/.blue from))) square)))) + (|> (scale (the /.#red to)) (f.- (scale (the /.#red from))) square) + (|> (scale (the /.#green to)) (f.- (scale (the /.#green from))) square) + (|> (scale (the /.#blue to)) (f.- (scale (the /.#blue from))) square)))) (def .public test Test @@ -99,7 +99,8 @@ (n.= /.limit) not)) )) - (_.for [/.RGB] + (_.for [/.RGB + /.#red /.#green /.#blue] (all _.and (_.for [/.equivalence] (equivalenceS.spec /.equivalence ..random)) @@ -110,15 +111,14 @@ (_.for [/.subtraction] (monoidS.spec /.equivalence /.subtraction ..random)) - (_.coverage [/.rgb - /.red /.green /.blue] + (_.coverage [/.rgb] (let [it (/.rgb expected_red expected_green expected_blue)] (and (same? expected_red - (/.red it)) + (the /.#red it)) (same? expected_green - (/.green it)) + (the /.#green it)) (same? expected_blue - (/.blue it))))) + (the /.#blue it))))) (_.coverage [/.complement] (let [~expected (/.complement expected) (open "/#[0]") /.equivalence] diff --git a/stdlib/source/test/lux/meta/extension.lux b/stdlib/source/test/lux/meta/extension.lux index 9d49aeb16..f98359d94 100644 --- a/stdlib/source/test/lux/meta/extension.lux +++ b/stdlib/source/test/lux/meta/extension.lux @@ -39,12 +39,12 @@ ["[0]" name]]])) (.,, (.these))))] [compiler - ["[0]" phase] [meta [archive ["[0]" unit]]] [language [lux + ["[0]" phase] ["[0]" translation] ["[0]" declaration] ["[0]" analysis (.only) 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/finance/money.lux b/stdlib/source/test/lux/world/finance/money.lux new file mode 100644 index 000000000..773589a15 --- /dev/null +++ b/stdlib/source/test/lux/world/finance/money.lux @@ -0,0 +1,108 @@ +(.require + [library + [lux (.except) + [abstract + [monad (.only do)] + [\\specification + ["[0]S" equivalence] + ["[0]S" order]]] + [control + ["[0]" maybe (.use "[1]#[0]" functor)]] + [data + ["[0]" bit (.use "[1]#[0]" equivalence)] + ["[0]" text (.only) + ["%" \\format]]] + [math + ["[0]" random (.only Random) (.use "[1]#[0]" functor)] + [number + ["n" nat]]] + [test + ["_" property (.only Test)]]]] + [\\library + ["[0]" / (.only) + ["[0]" currency (.only Currency)]]] + ["[0]" / + ["[1][0]" currency]]) + +(def .public (random $) + (All (_ $) + (-> (Currency $) + (Random (/.Money $)))) + (random#each (/.money $) + random.nat)) + +(def .public test + Test + (<| (_.covering /._) + (do [! random.monad] + [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 currency.usd))) + (_.for [/.order /.<] + (orderS.spec /.order (..random currency.usd))) + + (_.coverage [/.money /.currency /.amount] + (let [it (/.money currency.usd expected_amount)] + (and (same? currency.usd (/.currency it)) + (same? expected_amount (/.amount it))))) + (_.coverage [/.+ /.-] + (let [parameter (/.money currency.usd expected_parameter) + subject (/.money currency.usd expected_subject)] + (and (|> subject + (/.+ parameter) + (of /.equivalence = subject) + not) + (|> subject + (/.+ parameter) + (/.- parameter) + (maybe#each (of /.equivalence = subject)) + (maybe.else false))))) + (_.coverage [/.min] + (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 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 currency.usd expected_parameter) + expected_subject (/.money currency.usd expected_subject)] + (all _.and + (_.coverage [/.>] + (bit#= (/.> expected_parameter expected_subject) + (/.< expected_subject expected_parameter))) + (_.coverage [/.<= /.>=] + (bit#= (/.<= expected_parameter expected_subject) + (/.>= expected_subject expected_parameter))) + )) + (_.coverage [/.units /.sub_units] + (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 currency.usd expected_amount) + actual (/.+ (/.of_units currency.usd (/.units expected)) + (/.of_sub_units currency.usd (/.sub_units expected)))] + (/.= expected actual))) + (do ! + [it (..random currency.usd)] + (_.coverage [/.format] + (and (text.starts_with? (%.nat (/.amount it)) + (text.replaced_once "." "" (/.format it))) + (text.ends_with? (currency.alphabetic_code (/.currency it)) + (/.format it))))) + + /currency.test + ))) diff --git a/stdlib/source/test/lux/world/finance/money/currency.lux b/stdlib/source/test/lux/world/finance/money/currency.lux new file mode 100644 index 000000000..eeb59e9fc --- /dev/null +++ b/stdlib/source/test/lux/world/finance/money/currency.lux @@ -0,0 +1,259 @@ +(.require + [library + [lux (.except) + [abstract + [monad (.only do)] + [\\specification + ["[0]S" equivalence]]] + [data + ["[0]" text] + [collection + ["[0]" list (.use "[1]#[0]" functor)] + ["[0]" set]]] + [math + ["[0]" random (.only Random) (.use "[1]#[0]" monad)] + [number + ["n" nat]]] + [test + ["_" property (.only Test)]]]] + [\\library + ["[0]" /]]) + +(with_expansions [ (these [/.aed /.AED /.united_arab_emirates_dirham] + [/.afn /.AFN /.afghan_afghani] + [/.all /.ALL /.albanian_lek] + [/.amd /.AMD /.armenian_dram] + [/.ang /.ANG /.netherlands_antillean_guilder] + [/.aoa /.AOA /.angolan_kwanza] + [/.ars /.ARS /.argentine_peso] + [/.aud /.AUD /.australian_dollar] + [/.awg /.AWG /.aruban_florin] + [/.azn /.AZN /.azerbaijani_manat] + [/.bam /.BAM /.bosnia_and_herzegovina_convertible_mark] + + [/.bbd /.BBD /.barbados_dollar] + [/.bdt /.BDT /.bangladeshi_taka] + [/.bgn /.BGN /.bulgarian_lev] + [/.bhd /.BHD /.bahraini_dinar] + [/.bif /.BIF /.burundian_franc] + [/.bmd /.BMD /.bermudian_dollar] + [/.bnd /.BND /.brunei_dollar] + [/.bob /.BOB /.boliviano] + [/.brl /.BRL /.brazilian_real] + [/.bsd /.BSD /.bahamian_dollar] + [/.btn /.BTN /.bhutanese_ngultrum] + [/.bwp /.BWP /.botswana_pula] + [/.byn /.BYN /.belarusian_ruble] + [/.bzd /.BZD /.belize_dollar] + + [/.cad /.CAD /.canadian_dollar] + [/.cdf /.CDF /.congolese_franc] + [/.chf /.CHF /.swiss_franc] + [/.clp /.CLP /.chilean_peso] + [/.cop /.COP /.colombian_peso] + [/.crc /.CRC /.costa_rican_colon] + [/.cuc /.CUC /.cuban_convertible_peso] + [/.cup /.CUP /.cuban_peso] + [/.cve /.CVE /.cape_verdean_escudo] + [/.czk /.CZK /.czech_koruna] + + [/.djf /.DJF /.djiboutian_franc] + [/.dkk /.DKK /.danish_krone] + [/.dop /.DOP /.dominican_peso] + [/.dzd /.DZD /.algerian_dinar] + + [/.egp /.EGP /.egyptian_pound] + [/.ern /.ERN /.eritrean_nakfa] + [/.etb /.ETB /.ethiopian_birr] + [/.eur /.EUR /.euro] + + [/.fjd /.FJD /.fiji_dollar] + [/.fkp /.FKP /.falkland_islands_pound] + + [/.gbp /.GBP /.pound_sterling] + [/.gel /.GEL /.georgian_lari] + [/.ghs /.GHS /.ghanaian_cedi] + [/.gip /.GIP /.gibraltar_pound] + [/.gmd /.GMD /.gambian_dalasi] + [/.gnf /.GNF /.guinean_franc] + [/.gtq /.GTQ /.guatemalan_quetzal] + [/.gyd /.GYD /.guyanese_dollar] + + [/.hkd /.HKD /.hong_kong_dollar] + [/.hnl /.HNL /.honduran_lempira] + [/.hrk /.HRK /.croatian_kuna] + [/.htg /.HTG /.haitian_gourde] + [/.huf /.HUF /.hungarian_forint] + + [/.idr /.IDR /.indonesian_rupiah] + [/.ils /.ILS /.israeli_new_shekel] + [/.inr /.INR /.indian_rupee] + [/.iqd /.IQD /.iraqi_dinar] + [/.irr /.IRR /.iranian_rial] + [/.isk /.ISK /.icelandic_krona] + + [/.jmd /.JMD /.jamaican_dollar] + [/.jod /.JOD /.jordanian_dinar] + [/.jpy /.JPY /.japanese_yen] + + [/.kes /.KES /.kenyan_shilling] + [/.kgs /.KGS /.kyrgyzstani_som] + [/.khr /.KHR /.cambodian_riel] + [/.kmf /.KMF /.comoro_franc] + [/.kpw /.KPW /.north_korean_won] + [/.krw /.KRW /.south_korean_won] + [/.kwd /.KWD /.kuwaiti_dinar] + [/.kyd /.KYD /.cayman_islands_dollar] + [/.kzt /.KZT /.kazakhstani_tenge] + + [/.lak /.LAK /.lao_kip] + [/.lbp /.LBP /.lebanese_pound] + [/.lkr /.LKR /.sri_lankan_rupee] + [/.lrd /.LRD /.liberian_dollar] + [/.lsl /.LSL /.lesotho_loti] + [/.lyd /.LYD /.libyan_dinar] + + [/.mad /.MAD /.moroccan_dirham] + [/.mdl /.MDL /.moldovan_leu] + [/.mga /.MGA /.malagasy_ariary] + [/.mkd /.MKD /.macedonian_denar] + [/.mmk /.MMK /.myanmar_kyat] + [/.mnt /.MNT /.mongolian_togrog] + [/.mop /.MOP /.macanese_pataca] + [/.mru /.MRU /.mauritanian_ouguiya] + [/.mur /.MUR /.mauritian_rupee] + [/.mvr /.MVR /.maldivian_rufiyaa] + [/.mwk /.MWK /.malawian_kwacha] + [/.mxn /.MXN /.mexican_peso] + [/.myr /.MYR /.malaysian_ringgit] + [/.mzn /.MZN /.mozambican_metical] + + [/.nad /.NAD /.namibian_dollar] + [/.ngn /.NGN /.nigerian_naira] + [/.nio /.NIO /.nicaraguan_cordoba] + [/.nok /.NOK /.norwegian_krone] + [/.npr /.NPR /.nepalese_rupee] + [/.nzd /.NZD /.new_zealand_dollar] + + [/.omr /.OMR /.omani_rial] + + [/.pab /.PAB /.panamanian_balboa] + [/.pen /.PEN /.peruvian_sol] + [/.pgk /.PGK /.papua_new_guinean_kina] + [/.php /.PHP /.philippine_peso] + [/.pkr /.PKR /.pakistani_rupee] + [/.pln /.PLN /.polish_ztoty] + [/.pyg /.PYG /.paraguayan_guarani] + + [/.qar /.QAR /.qatari_riyal] + + [/.ron /.RON /.romanian_leu] + [/.rsd /.RSD /.serbian_dinar] + [/.cny /.CNY /.renminbi] + [/.rub /.RUB /.russian_ruble] + [/.rwf /.RWF /.rwandan_franc] + + [/.sar /.SAR /.saudi_riyal] + [/.sbd /.SBD /.solomon_islands_dollar] + [/.scr /.SCR /.seychelles_rupee] + [/.sdg /.SDG /.sudanese_pound] + [/.sek /.SEK /.swedish_krona] + [/.sgd /.SGD /.singapore_dollar] + [/.shp /.SHP /.saint_helena_pound] + [/.sos /.SOS /.somali_shilling] + [/.srd /.SRD /.surinamese_dollar] + [/.ssp /.SSP /.south_sudanese_pound] + [/.stn /.STN /.sao_tome_and_principe_dobra] + [/.svc /.SVC /.salvadoran_colon] + [/.syp /.SYP /.syrian_pound] + [/.szl /.SZL /.swazi_lilangeni] + + [/.thb /.THB /.thai_baht] + [/.tjs /.TJS /.tajikistani_somoni] + [/.tmt /.TMT /.turkmenistan_manat] + [/.tnd /.TND /.tunisian_dinar] + [/.top /.TOP /.tongan_pa'anga] + [/.try /.TRY /.turkish_lira] + [/.ttd /.TTD /.trinidad_and_tobago_dollar] + [/.twd /.TWD /.new_taiwan_dollar] + [/.tzs /.TZS /.tanzanian_shilling] + + [/.uah /.UAH /.ukrainian_hryvnia] + [/.ugx /.UGX /.ugandan_shilling] + [/.usd /.USD /.united_states_dollar] + [/.uyu /.UYU /.uruguayan_peso] + [/.uzs /.UZS /.uzbekistan_sum] + [/.ves /.VES /.venezuelan_sovereign_bolivar] + [/.vnd /.VND /.vietnamese_dong] + [/.vuv /.VUV /.vanuatu_vatu] + [/.wst /.WST /.samoan_tala] + + [/.xag /.XAG /.silver] + [/.xau /.XAU /.gold] + [/.xcd /.XCD /.east_caribbean_dollar] + [/.xpd /.XPD /.palladium] + [/.xpt /.XPT /.platinum] + + [/.zar /.ZAR /.south_african_rand] + [/.zmw /.ZMW /.zambian_kwacha] + [/.zwl /.ZWL /.zimbabwean_dollar] + )] + (def .public random + (Random (Ex (_ of) + (/.Currency of))) + (`` (all random.either + (,, (with_template [ ] + [(random#in )] + + + )) + ))) + + (def .public test + Test + (<| (_.covering /._) + (do [! random.monad] + []) + (_.for [/.Currency]) + (all _.and + (_.for [/.equivalence] + (equivalenceS.spec /.equivalence ..random)) + + (with_expansions [ (with_template [ ] + [] + + + )] + (<| (_.for []) + (let [options (is (List (/.Currency Any)) + (list ))]) + (all _.and + (_.coverage [/.alphabetic_code] + (let [uniques (|> options + (list#each /.alphabetic_code) + (set.of_list text.hash))] + (n.= (list.size options) + (set.size uniques)))) + (_.coverage [/.numeric_code] + (let [uniques (|> options + (list#each /.numeric_code) + (set.of_list n.hash))] + (n.= (list.size options) + (set.size uniques)))) + (_.coverage [/.sub_divisions] + (list.every? (|>> /.sub_divisions (n.> 0)) + options)) + ))) + (<| (_.for [/.currency /.type]) + (`` (all _.and + (,, (with_template [ ] + [(_.coverage [ ] + (same? (is (/.Currency ) + ) + (is (/.Currency ) + )))] + + + )) + ))) + )))) 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)))) + ))) diff --git a/stdlib/source/test/lux/world/money.lux b/stdlib/source/test/lux/world/money.lux deleted file mode 100644 index 4cddc38ee..000000000 --- a/stdlib/source/test/lux/world/money.lux +++ /dev/null @@ -1,110 +0,0 @@ -(.require - [library - [lux (.except) - [abstract - [monad (.only do)] - [\\specification - ["[0]S" equivalence] - ["[0]S" order]]] - [control - ["[0]" maybe (.use "[1]#[0]" functor)]] - [data - ["[0]" bit (.use "[1]#[0]" equivalence)] - ["[0]" text (.only) - ["%" \\format]]] - [math - ["[0]" random (.only Random)] - [number - ["n" nat]]] - [test - ["_" property (.only Test)]]]] - [\\library - ["[0]" / (.only) - ["[0]" 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 test - Test - (<| (_.covering /._) - (do [! random.monad] - [.let [expected_currency currency.usd] - 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)) - (_.for [/.order /.<] - (orderS.spec /.order ..random)) - - (_.coverage [/.money /.currency /.amount] - (let [it (/.money expected_currency expected_amount)] - (and (same? expected_currency (/.currency it)) - (same? expected_amount (/.amount it))))) - (_.coverage [/.+ /.-] - (let [parameter (/.money expected_currency expected_parameter) - subject (/.money expected_currency expected_subject)] - (and (|> subject - (/.+ parameter) - (of /.equivalence = subject) - not) - (|> subject - (/.+ parameter) - (/.- parameter) - (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)] - (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)] - (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)] - (all _.and - (_.coverage [/.>] - (bit#= (/.> expected_parameter expected_subject) - (/.< expected_subject expected_parameter))) - (_.coverage [/.<= /.>=] - (bit#= (/.<= expected_parameter expected_subject) - (/.>= 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)))] - (/.= 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)))] - (/.= expected actual))) - (do ! - [it ..random] - (_.coverage [/.format] - (and (text.starts_with? (%.nat (/.amount it)) - (text.replaced_once "." "" (/.format it))) - (text.ends_with? (currency.alphabetic_code (/.currency it)) - (/.format it))))) - - /currency.test - ))) diff --git a/stdlib/source/test/lux/world/money/currency.lux b/stdlib/source/test/lux/world/money/currency.lux deleted file mode 100644 index eeb59e9fc..000000000 --- a/stdlib/source/test/lux/world/money/currency.lux +++ /dev/null @@ -1,259 +0,0 @@ -(.require - [library - [lux (.except) - [abstract - [monad (.only do)] - [\\specification - ["[0]S" equivalence]]] - [data - ["[0]" text] - [collection - ["[0]" list (.use "[1]#[0]" functor)] - ["[0]" set]]] - [math - ["[0]" random (.only Random) (.use "[1]#[0]" monad)] - [number - ["n" nat]]] - [test - ["_" property (.only Test)]]]] - [\\library - ["[0]" /]]) - -(with_expansions [ (these [/.aed /.AED /.united_arab_emirates_dirham] - [/.afn /.AFN /.afghan_afghani] - [/.all /.ALL /.albanian_lek] - [/.amd /.AMD /.armenian_dram] - [/.ang /.ANG /.netherlands_antillean_guilder] - [/.aoa /.AOA /.angolan_kwanza] - [/.ars /.ARS /.argentine_peso] - [/.aud /.AUD /.australian_dollar] - [/.awg /.AWG /.aruban_florin] - [/.azn /.AZN /.azerbaijani_manat] - [/.bam /.BAM /.bosnia_and_herzegovina_convertible_mark] - - [/.bbd /.BBD /.barbados_dollar] - [/.bdt /.BDT /.bangladeshi_taka] - [/.bgn /.BGN /.bulgarian_lev] - [/.bhd /.BHD /.bahraini_dinar] - [/.bif /.BIF /.burundian_franc] - [/.bmd /.BMD /.bermudian_dollar] - [/.bnd /.BND /.brunei_dollar] - [/.bob /.BOB /.boliviano] - [/.brl /.BRL /.brazilian_real] - [/.bsd /.BSD /.bahamian_dollar] - [/.btn /.BTN /.bhutanese_ngultrum] - [/.bwp /.BWP /.botswana_pula] - [/.byn /.BYN /.belarusian_ruble] - [/.bzd /.BZD /.belize_dollar] - - [/.cad /.CAD /.canadian_dollar] - [/.cdf /.CDF /.congolese_franc] - [/.chf /.CHF /.swiss_franc] - [/.clp /.CLP /.chilean_peso] - [/.cop /.COP /.colombian_peso] - [/.crc /.CRC /.costa_rican_colon] - [/.cuc /.CUC /.cuban_convertible_peso] - [/.cup /.CUP /.cuban_peso] - [/.cve /.CVE /.cape_verdean_escudo] - [/.czk /.CZK /.czech_koruna] - - [/.djf /.DJF /.djiboutian_franc] - [/.dkk /.DKK /.danish_krone] - [/.dop /.DOP /.dominican_peso] - [/.dzd /.DZD /.algerian_dinar] - - [/.egp /.EGP /.egyptian_pound] - [/.ern /.ERN /.eritrean_nakfa] - [/.etb /.ETB /.ethiopian_birr] - [/.eur /.EUR /.euro] - - [/.fjd /.FJD /.fiji_dollar] - [/.fkp /.FKP /.falkland_islands_pound] - - [/.gbp /.GBP /.pound_sterling] - [/.gel /.GEL /.georgian_lari] - [/.ghs /.GHS /.ghanaian_cedi] - [/.gip /.GIP /.gibraltar_pound] - [/.gmd /.GMD /.gambian_dalasi] - [/.gnf /.GNF /.guinean_franc] - [/.gtq /.GTQ /.guatemalan_quetzal] - [/.gyd /.GYD /.guyanese_dollar] - - [/.hkd /.HKD /.hong_kong_dollar] - [/.hnl /.HNL /.honduran_lempira] - [/.hrk /.HRK /.croatian_kuna] - [/.htg /.HTG /.haitian_gourde] - [/.huf /.HUF /.hungarian_forint] - - [/.idr /.IDR /.indonesian_rupiah] - [/.ils /.ILS /.israeli_new_shekel] - [/.inr /.INR /.indian_rupee] - [/.iqd /.IQD /.iraqi_dinar] - [/.irr /.IRR /.iranian_rial] - [/.isk /.ISK /.icelandic_krona] - - [/.jmd /.JMD /.jamaican_dollar] - [/.jod /.JOD /.jordanian_dinar] - [/.jpy /.JPY /.japanese_yen] - - [/.kes /.KES /.kenyan_shilling] - [/.kgs /.KGS /.kyrgyzstani_som] - [/.khr /.KHR /.cambodian_riel] - [/.kmf /.KMF /.comoro_franc] - [/.kpw /.KPW /.north_korean_won] - [/.krw /.KRW /.south_korean_won] - [/.kwd /.KWD /.kuwaiti_dinar] - [/.kyd /.KYD /.cayman_islands_dollar] - [/.kzt /.KZT /.kazakhstani_tenge] - - [/.lak /.LAK /.lao_kip] - [/.lbp /.LBP /.lebanese_pound] - [/.lkr /.LKR /.sri_lankan_rupee] - [/.lrd /.LRD /.liberian_dollar] - [/.lsl /.LSL /.lesotho_loti] - [/.lyd /.LYD /.libyan_dinar] - - [/.mad /.MAD /.moroccan_dirham] - [/.mdl /.MDL /.moldovan_leu] - [/.mga /.MGA /.malagasy_ariary] - [/.mkd /.MKD /.macedonian_denar] - [/.mmk /.MMK /.myanmar_kyat] - [/.mnt /.MNT /.mongolian_togrog] - [/.mop /.MOP /.macanese_pataca] - [/.mru /.MRU /.mauritanian_ouguiya] - [/.mur /.MUR /.mauritian_rupee] - [/.mvr /.MVR /.maldivian_rufiyaa] - [/.mwk /.MWK /.malawian_kwacha] - [/.mxn /.MXN /.mexican_peso] - [/.myr /.MYR /.malaysian_ringgit] - [/.mzn /.MZN /.mozambican_metical] - - [/.nad /.NAD /.namibian_dollar] - [/.ngn /.NGN /.nigerian_naira] - [/.nio /.NIO /.nicaraguan_cordoba] - [/.nok /.NOK /.norwegian_krone] - [/.npr /.NPR /.nepalese_rupee] - [/.nzd /.NZD /.new_zealand_dollar] - - [/.omr /.OMR /.omani_rial] - - [/.pab /.PAB /.panamanian_balboa] - [/.pen /.PEN /.peruvian_sol] - [/.pgk /.PGK /.papua_new_guinean_kina] - [/.php /.PHP /.philippine_peso] - [/.pkr /.PKR /.pakistani_rupee] - [/.pln /.PLN /.polish_ztoty] - [/.pyg /.PYG /.paraguayan_guarani] - - [/.qar /.QAR /.qatari_riyal] - - [/.ron /.RON /.romanian_leu] - [/.rsd /.RSD /.serbian_dinar] - [/.cny /.CNY /.renminbi] - [/.rub /.RUB /.russian_ruble] - [/.rwf /.RWF /.rwandan_franc] - - [/.sar /.SAR /.saudi_riyal] - [/.sbd /.SBD /.solomon_islands_dollar] - [/.scr /.SCR /.seychelles_rupee] - [/.sdg /.SDG /.sudanese_pound] - [/.sek /.SEK /.swedish_krona] - [/.sgd /.SGD /.singapore_dollar] - [/.shp /.SHP /.saint_helena_pound] - [/.sos /.SOS /.somali_shilling] - [/.srd /.SRD /.surinamese_dollar] - [/.ssp /.SSP /.south_sudanese_pound] - [/.stn /.STN /.sao_tome_and_principe_dobra] - [/.svc /.SVC /.salvadoran_colon] - [/.syp /.SYP /.syrian_pound] - [/.szl /.SZL /.swazi_lilangeni] - - [/.thb /.THB /.thai_baht] - [/.tjs /.TJS /.tajikistani_somoni] - [/.tmt /.TMT /.turkmenistan_manat] - [/.tnd /.TND /.tunisian_dinar] - [/.top /.TOP /.tongan_pa'anga] - [/.try /.TRY /.turkish_lira] - [/.ttd /.TTD /.trinidad_and_tobago_dollar] - [/.twd /.TWD /.new_taiwan_dollar] - [/.tzs /.TZS /.tanzanian_shilling] - - [/.uah /.UAH /.ukrainian_hryvnia] - [/.ugx /.UGX /.ugandan_shilling] - [/.usd /.USD /.united_states_dollar] - [/.uyu /.UYU /.uruguayan_peso] - [/.uzs /.UZS /.uzbekistan_sum] - [/.ves /.VES /.venezuelan_sovereign_bolivar] - [/.vnd /.VND /.vietnamese_dong] - [/.vuv /.VUV /.vanuatu_vatu] - [/.wst /.WST /.samoan_tala] - - [/.xag /.XAG /.silver] - [/.xau /.XAU /.gold] - [/.xcd /.XCD /.east_caribbean_dollar] - [/.xpd /.XPD /.palladium] - [/.xpt /.XPT /.platinum] - - [/.zar /.ZAR /.south_african_rand] - [/.zmw /.ZMW /.zambian_kwacha] - [/.zwl /.ZWL /.zimbabwean_dollar] - )] - (def .public random - (Random (Ex (_ of) - (/.Currency of))) - (`` (all random.either - (,, (with_template [ ] - [(random#in )] - - - )) - ))) - - (def .public test - Test - (<| (_.covering /._) - (do [! random.monad] - []) - (_.for [/.Currency]) - (all _.and - (_.for [/.equivalence] - (equivalenceS.spec /.equivalence ..random)) - - (with_expansions [ (with_template [ ] - [] - - - )] - (<| (_.for []) - (let [options (is (List (/.Currency Any)) - (list ))]) - (all _.and - (_.coverage [/.alphabetic_code] - (let [uniques (|> options - (list#each /.alphabetic_code) - (set.of_list text.hash))] - (n.= (list.size options) - (set.size uniques)))) - (_.coverage [/.numeric_code] - (let [uniques (|> options - (list#each /.numeric_code) - (set.of_list n.hash))] - (n.= (list.size options) - (set.size uniques)))) - (_.coverage [/.sub_divisions] - (list.every? (|>> /.sub_divisions (n.> 0)) - options)) - ))) - (<| (_.for [/.currency /.type]) - (`` (all _.and - (,, (with_template [ ] - [(_.coverage [ ] - (same? (is (/.Currency ) - ) - (is (/.Currency ) - )))] - - - )) - ))) - )))) -- cgit v1.2.3