consensus/utils/number_test.go
DataHoarder 3b268558d8
All checks were successful
continuous-integration/drone/push Build is passing
Split and cleanup merkle tree for transactions
2023-05-23 15:38:20 +02:00

31 lines
533 B
Go

package utils
import (
"testing"
)
func TestNumber(t *testing.T) {
s := "S"
n := uint64(28)
if DecodeBinaryNumber(s) != n {
t.Fail()
}
}
func TestPreviousPowerOfTwo(t *testing.T) {
loopPath := func(x uint64) int {
//find closest low power of two
var cnt uint64
for cnt = 1; cnt <= x; cnt <<= 1 {
}
cnt >>= 1
return int(cnt)
}
for i := uint64(1); i < 65536; i++ {
if PreviousPowerOfTwo(i) != loopPath(i) {
t.Fatalf("expected %d, got %d for iteration %d", loopPath(i), PreviousPowerOfTwo(i), i)
}
}
}