diff options
Diffstat (limited to 'stdlib/source/test/lux/data')
-rw-r--r-- | stdlib/source/test/lux/data/number.lux | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/stdlib/source/test/lux/data/number.lux b/stdlib/source/test/lux/data/number.lux new file mode 100644 index 000000000..876cf4c4d --- /dev/null +++ b/stdlib/source/test/lux/data/number.lux @@ -0,0 +1,88 @@ +(.module: + [lux #* + ["_" test (#+ Test)] + [control + ["." try]] + [data + ["." text + ["%" format (#+ format)]] + [number + ["n" nat] + ["i" int] + ["r" rev] + ["f" frac]]]] + {1 + ["." /]}) + +(def: clean-commas + (-> Text Text) + (text.replace-all "," "")) + +(def: #export test + Test + (<| (_.covering /._) + ($_ _.and + (_.cover [/.bin] + (`` (and (~~ (template [<=> <codec> <number>] + [(case (:: <codec> decode (..clean-commas <number>)) + (#try.Success actual) + (<=> (/.bin <number>) actual) + + (#try.Failure error) + false)] + + [n.= n.binary "11001001"] + [n.= n.binary "11,00,10,01"] + + [i.= i.binary "+11001001"] + [i.= i.binary "-11,00,10,01"] + + [r.= r.binary ".11001001"] + [r.= r.binary ".11,00,10,01"] + + [f.= f.binary "+1100.1001"] + [f.= f.binary "-11,00.10,01"] + ))))) + (_.cover [/.oct] + (`` (and (~~ (template [<=> <codec> <number>] + [(case (:: <codec> decode (..clean-commas <number>)) + (#try.Success actual) + (<=> (/.oct <number>) actual) + + (#try.Failure error) + false)] + + [n.= n.octal "615243"] + [n.= n.octal "615,243"] + + [i.= i.octal "+615243"] + [i.= i.octal "-615,243"] + + [r.= r.octal ".615243"] + [r.= r.octal ".615,243"] + + [f.= f.octal "+6152.43"] + [f.= f.octal "-61,52.43"] + ))))) + (_.cover [/.hex] + (`` (and (~~ (template [<=> <codec> <number>] + [(case (:: <codec> decode (..clean-commas <number>)) + (#try.Success actual) + (<=> (/.hex <number>) actual) + + (#try.Failure error) + false)] + + [n.= n.hex "deadBEEF"] + [n.= n.hex "dead,BEEF"] + + [i.= i.hex "+deadBEEF"] + [i.= i.hex "-dead,BEEF"] + + [r.= r.hex ".deadBEEF"] + [r.= r.hex ".dead,BEEF"] + + [f.= f.hex "+dead.BEEF"] + [f.= f.hex "-dead,BE.EF"] + ))))) + ))) |