aboutsummaryrefslogtreecommitdiff
path: root/internal/hash/log2_test.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2019-01-16 02:01:09 +0100
committerDimitri Sokolyuk <demon@dim13.org>2019-01-16 02:01:09 +0100
commit3dbb460b6a9f82c159f6cc9beaa64eb9f7782256 (patch)
tree0010165f800fb7c7ac30040417c867b0ed27aea1 /internal/hash/log2_test.go
parente7928b177e156a36dbbd253439f902ddbf4fd858 (diff)
rename
Diffstat (limited to 'internal/hash/log2_test.go')
-rw-r--r--internal/hash/log2_test.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/internal/hash/log2_test.go b/internal/hash/log2_test.go
new file mode 100644
index 0000000..c58e213
--- /dev/null
+++ b/internal/hash/log2_test.go
@@ -0,0 +1,42 @@
+package hash
+
+import (
+ "fmt"
+ "testing"
+)
+
+func TestLog2(t *testing.T) {
+ testCases := []struct {
+ num, want uint32
+ }{
+ {0, 0},
+ {1, 0},
+ {2, 1},
+ {3, 2},
+ {4, 2},
+ {8, 3},
+ {9, 4},
+ {128, 7},
+ {129, 8},
+ {1024, 10},
+ }
+ for _, tc := range testCases {
+ t.Run(fmt.Sprintf("log2(%v)=%v", tc.num, tc.want), func(t *testing.T) {
+ got := log2(tc.num)
+ if got != tc.want {
+ t.Errorf("got %v, want %v", got, tc.want)
+ }
+ })
+ }
+}
+
+func BenchmarkLog2(b *testing.B) {
+ benchCases := []uint32{1, 1024}
+ for _, bc := range benchCases {
+ b.Run(fmt.Sprintf("log(%v)", bc), func(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ log2(1024)
+ }
+ })
+ }
+}