aboutsummaryrefslogtreecommitdiff
path: root/stdlib/test
diff options
context:
space:
mode:
authorEduardo Julian2017-05-03 19:42:23 -0400
committerEduardo Julian2017-05-03 19:42:23 -0400
commit83c809e53f339f9eb20e2a950680c8843d147ecb (patch)
tree3f929e5b9dcdbbfbcc175103ced21d19ba466e72 /stdlib/test
parentce25394961da87fa2cba64259c0d32972194f458 (diff)
- Gave less cryptic names to bit-wise functions.
- Improved the tests for lux/data/bit.
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)))))
))