From 6acf4ffc362c0f8ef77d96f8cfe991adb2d9a0eb Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Fri, 13 Jul 2018 20:17:21 -0400 Subject: - Re-named "lux/data/bit" to "lux/data/number/i64". --- stdlib/test/test/lux.lux | 5 ++- stdlib/test/test/lux/data/bit.lux | 76 -------------------------------- stdlib/test/test/lux/data/number/i64.lux | 76 ++++++++++++++++++++++++++++++++ stdlib/test/test/lux/world/blob.lux | 6 +-- 4 files changed, 82 insertions(+), 81 deletions(-) delete mode 100644 stdlib/test/test/lux/data/bit.lux create mode 100644 stdlib/test/test/lux/data/number/i64.lux (limited to 'stdlib/test') diff --git a/stdlib/test/test/lux.lux b/stdlib/test/test/lux.lux index 706e6e4bb..4f1a810c2 100644 --- a/stdlib/test/test/lux.lux +++ b/stdlib/test/test/lux.lux @@ -6,7 +6,8 @@ ["r" math/random] [data [maybe] - [bit] + [number + [i64]] [text ("text/" Equivalence) format]] ["." macro @@ -133,7 +134,7 @@ (def: frac-rev (r.Random Rev) (|> r.rev - (:: r.Functor map (|>> (bit.left-shift +11) (bit.logical-right-shift +11))))) + (:: r.Functor map (|>> (i64.left-shift +11) (i64.logical-right-shift +11))))) (do-template [category rand-gen -> <- = ] [(context: (format "[" category "] " "Numeric conversions") diff --git a/stdlib/test/test/lux/data/bit.lux b/stdlib/test/test/lux/data/bit.lux deleted file mode 100644 index 6d76ac4e2..000000000 --- a/stdlib/test/test/lux/data/bit.lux +++ /dev/null @@ -1,76 +0,0 @@ -(.module: - [lux #* - [io] - [control - ["M" monad (#+ do Monad)]] - [data - ["&" bit] - number] - [math - ["r" random]]] - lux/test) - -(context: "Bitwise operations." - (<| (times +100) - (do @ - [pattern r.nat - idx (:: @ map (n/% &.width) r.nat)] - ($_ seq - (test "Clearing and settings bits should alter the count." - (and (n/= (dec (&.count (&.set idx pattern))) - (&.count (&.clear idx pattern))) - (|> (&.count pattern) - (n/- (&.count (&.clear idx pattern))) - (n/<= +1)) - (|> (&.count (&.set idx pattern)) - (n/- (&.count pattern)) - (n/<= +1)))) - (test "Can query whether a bit is set." - (and (or (and (&.set? idx pattern) - (not (&.set? idx (&.clear idx pattern)))) - (and (not (&.set? idx pattern)) - (&.set? idx (&.set idx pattern)))) - - (or (and (&.set? idx pattern) - (not (&.set? idx (&.flip idx pattern)))) - (and (not (&.set? idx pattern)) - (&.set? idx (&.flip idx pattern)))))) - (test "The negation of a bit pattern should have a complementary bit-count." - (n/= &.width - (n/+ (&.count pattern) - (&.count (&.not pattern))))) - (test "Can do simple binary boolean logic." - (and (n/= +0 - (&.and pattern - (&.not pattern))) - (n/= (&.not +0) - (&.or pattern - (&.not pattern))) - (n/= (&.not +0) - (&.xor pattern - (&.not pattern))) - (n/= +0 - (&.xor pattern - pattern)))) - (test "rotate-left and rotate-right are inverses of one another." - (and (|> pattern - (&.rotate-left idx) - (&.rotate-right idx) - (n/= pattern)) - (|> pattern - (&.rotate-right idx) - (&.rotate-left idx) - (n/= pattern)))) - (test "Rotate as many spaces as the bit-pattern's width leaves the pattern unchanged." - (and (|> pattern - (&.rotate-left &.width) - (n/= pattern)) - (|> pattern - (&.rotate-right &.width) - (n/= pattern)))) - (test "Shift right respect the sign of ints." - (let [value (.int pattern)] - (if (i/< 0 value) - (i/< 0 (&.arithmetic-right-shift idx value)) - (i/>= 0 (&.arithmetic-right-shift idx value))))) - )))) diff --git a/stdlib/test/test/lux/data/number/i64.lux b/stdlib/test/test/lux/data/number/i64.lux new file mode 100644 index 000000000..1dd9dd314 --- /dev/null +++ b/stdlib/test/test/lux/data/number/i64.lux @@ -0,0 +1,76 @@ +(.module: + [lux #* + [io] + [control + ["M" monad (#+ do Monad)]] + [data + [number #* + ["&" i64]]] + [math + ["r" random]]] + lux/test) + +(context: "Bitwise operations." + (<| (times +100) + (do @ + [pattern r.nat + idx (:: @ map (n/% &.width) r.nat)] + ($_ seq + (test "Clearing and settings bits should alter the count." + (and (n/= (dec (&.count (&.set idx pattern))) + (&.count (&.clear idx pattern))) + (|> (&.count pattern) + (n/- (&.count (&.clear idx pattern))) + (n/<= +1)) + (|> (&.count (&.set idx pattern)) + (n/- (&.count pattern)) + (n/<= +1)))) + (test "Can query whether a bit is set." + (and (or (and (&.set? idx pattern) + (not (&.set? idx (&.clear idx pattern)))) + (and (not (&.set? idx pattern)) + (&.set? idx (&.set idx pattern)))) + + (or (and (&.set? idx pattern) + (not (&.set? idx (&.flip idx pattern)))) + (and (not (&.set? idx pattern)) + (&.set? idx (&.flip idx pattern)))))) + (test "The negation of a bit pattern should have a complementary bit-count." + (n/= &.width + (n/+ (&.count pattern) + (&.count (&.not pattern))))) + (test "Can do simple binary boolean logic." + (and (n/= +0 + (&.and pattern + (&.not pattern))) + (n/= (&.not +0) + (&.or pattern + (&.not pattern))) + (n/= (&.not +0) + (&.xor pattern + (&.not pattern))) + (n/= +0 + (&.xor pattern + pattern)))) + (test "rotate-left and rotate-right are inverses of one another." + (and (|> pattern + (&.rotate-left idx) + (&.rotate-right idx) + (n/= pattern)) + (|> pattern + (&.rotate-right idx) + (&.rotate-left idx) + (n/= pattern)))) + (test "Rotate as many spaces as the bit-pattern's width leaves the pattern unchanged." + (and (|> pattern + (&.rotate-left &.width) + (n/= pattern)) + (|> pattern + (&.rotate-right &.width) + (n/= pattern)))) + (test "Shift right respect the sign of ints." + (let [value (.int pattern)] + (if (i/< 0 value) + (i/< 0 (&.arithmetic-right-shift idx value)) + (i/>= 0 (&.arithmetic-right-shift idx value))))) + )))) diff --git a/stdlib/test/test/lux/world/blob.lux b/stdlib/test/test/lux/world/blob.lux index 7bce91298..f93b4e5dd 100644 --- a/stdlib/test/test/lux/world/blob.lux +++ b/stdlib/test/test/lux/world/blob.lux @@ -5,9 +5,9 @@ [monad (#+ do)] [pipe]] [data - [bit] - [number] ["e" error] + ["." number + [i64]] [collection [list]]] [world ["/" blob]] @@ -43,7 +43,7 @@ (-> Nat (-> Nat /.Blob (e.Error Nat)) (-> Nat Nat /.Blob (e.Error Any)) Nat Bool) (let [blob (/.create +8) bits (n/* +8 bytes) - capped-value (|> +1 (bit.left-shift bits) dec (bit.and value))] + capped-value (|> +1 (i64.left-shift bits) dec (i64.and value))] (succeed (do e.Monad [_ (write +0 value blob) -- cgit v1.2.3