github.com/insolar/vanilla@v0.0.0-20201023172447-248fdf805322/merkler/utils_test.go (about) 1 // Copyright 2020 Insolar Network Ltd. 2 // All rights reserved. 3 // This material is licensed under the Insolar License version 1.0, 4 // available at https://github.com/insolar/assured-ledger/blob/master/LICENSE.md. 5 6 package merkler 7 8 import ( 9 "testing" 10 11 "github.com/stretchr/testify/assert" 12 "github.com/stretchr/testify/require" 13 ) 14 15 func TestUnbalancedBitCount(t *testing.T) { 16 for i := uint8(0); i <= 64; i++ { 17 assert.Equal(t, uint8(0), UnbalancedBitCount(uint(1)<<i-1, i)) 18 } 19 20 for bitCount := uint8(1); bitCount <= 8; bitCount++ { 21 for n, i := bitCount, uint(0); n > 0; n-- { 22 for j := uint(1) << (n - 1); j > 0; i, j = i+1, j-1 { 23 v := UnbalancedBitCount(i, bitCount) 24 //t.Logf("%2d %3d %2d", bitCount, i, v) 25 require.Equal(t, n, v, "bits=%d index=%d", bitCount, i) 26 } 27 } 28 } 29 }