aboutsummaryrefslogtreecommitdiff
path: root/stdlib/test
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/test')
-rw-r--r--stdlib/test/test/lux/data/bit.lux92
1 files changed, 51 insertions, 41 deletions
diff --git a/stdlib/test/test/lux/data/bit.lux b/stdlib/test/test/lux/data/bit.lux
index 0c9f5ac3d..2ba2c8e57 100644
--- a/stdlib/test/test/lux/data/bit.lux
+++ b/stdlib/test/test/lux/data/bit.lux
@@ -13,49 +13,59 @@
[pattern R;nat
idx (:: @ map (n.% width) R;nat)]
($_ seq
- (assert "" (and (n.< (&;count (&;set idx pattern))
- (&;count (&;clear idx pattern)))
- (n.<= (&;count pattern)
- (&;count (&;clear idx pattern)))
- (n.>= (&;count pattern)
- (&;count (&;set idx pattern)))
+ (assert "Clearing and settings bits should alter the count."
+ (and (n.< (&;count (&;set idx pattern))
+ (&;count (&;clear idx pattern)))
+ (n.<= (&;count pattern)
+ (&;count (&;clear idx pattern)))
+ (n.>= (&;count pattern)
+ (&;count (&;set idx pattern)))))
+ (assert "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 (&;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))))
-
- (n.= width
- (n.+ (&;count pattern)
- (&;count (&;~ pattern))))
-
- (n.= +0
- (&;& pattern
- (&;~ pattern)))
- (n.= (&;~ +0)
- (&;| pattern
- (&;~ pattern)))
- (n.= (&;~ +0)
- (&;^ pattern
- (&;~ pattern)))
- (n.= +0
- (&;^ pattern
- pattern))
-
- (|> pattern (&;rotate-left idx) (&;rotate-right idx) (n.= pattern))
- (|> pattern (&;rotate-right idx) (&;rotate-left idx) (n.= pattern))
- (|> pattern (&;rotate-left idx) (&;rotate-left (n.- idx width)) (n.= pattern))
- (|> pattern (&;rotate-right idx) (&;rotate-right (n.- idx width)) (n.= pattern))
- ))
-
+ (or (and (&;set? idx pattern)
+ (not (&;set? idx (&;flip idx pattern))))
+ (and (not (&;set? idx pattern))
+ (&;set? idx (&;flip idx pattern))))))
+ (assert "The negation of a bit pattern should have a complementary bit count."
+ (n.= width
+ (n.+ (&;count pattern)
+ (&;count (&;not pattern)))))
+ (assert "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))))
+ (assert "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))))
+ (assert "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))))
(assert "Shift right respect the sign of ints."
(let [value (nat-to-int pattern)]
(if (i.< 0 value)
- (i.< 0 (&;>> idx value))
- (i.>= 0 (&;>> idx value)))))
+ (i.< 0 (&;shift-right idx value))
+ (i.>= 0 (&;shift-right idx value)))))
))