aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-03-22 10:27:52 +0100
committerDmitry Vyukov <dvyukov@google.com>2020-03-24 08:42:59 +0100
commit2a504af1a3f752882c9027d64f2260424e91f1d6 (patch)
tree0b723edb2aefbb29e2296281ad1a758a22bdb384
parentf211a294e59206f15b4e406de79311ed87d67a2f (diff)
prog: add test for truncateToBitSize
-rw-r--r--prog/rand_test.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/prog/rand_test.go b/prog/rand_test.go
index cfea62e27..09f3b359c 100644
--- a/prog/rand_test.go
+++ b/prog/rand_test.go
@@ -171,3 +171,24 @@ func TestFlags(t *testing.T) {
test.vv, test.bitmask, test.old, throws, buf.String())
}
}
+
+func TestTruncateToBitSize(t *testing.T) {
+ tests := []struct{ v, bits, res uint64 }{
+ {0, 1, 0},
+ {1, 1, 1},
+ {0x123, 4, 0x3},
+ {0xabc, 4, 0xc},
+ {0x123, 8, 0x23},
+ {0xabc, 8, 0xbc},
+ {0x12345678abcdabcd, 64, 0x12345678abcdabcd},
+ {0xf2345678abcdabcd, 64, 0xf2345678abcdabcd},
+ }
+ for i, test := range tests {
+ t.Run(fmt.Sprint(i), func(t *testing.T) {
+ res := truncateToBitSize(test.v, test.bits)
+ if res != test.res {
+ t.Fatalf("truncateToBitSize(0x%x, %v)=0x%x, want 0x%x", test.v, test.bits, res, test.res)
+ }
+ })
+ }
+}