github.com/lrita/numa@v1.0.2/bitmask_test.go (about) 1 package numa 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/stretchr/testify/require" 8 ) 9 10 func TestBitmask(t *testing.T) { 11 assert := require.New(t) 12 for i := 0; i < 256; i++ { 13 mask := NewBitmask(i) 14 15 assert.True(mask.Len()%8 == 0) 16 assert.True(len(mask)*64 >= i) 17 18 for j := 0; j < i; j++ { 19 mask.Set(j, true) 20 assert.True(mask.Get(j)) 21 assert.Equal(j+1, mask.OnesCount()) 22 mask.Set(j, false) 23 assert.False(mask.Get(j)) 24 mask.Set(j, true) 25 26 for k := j + 1; k < i; k++ { 27 assert.False(mask.Get(k)) 28 } 29 } 30 31 clone := mask.Clone() 32 for j := 0; j < mask.Len(); j++ { 33 assert.Equal(mask.Get(j), clone.Get(j)) 34 } 35 36 if i != 0 { 37 assert.Equal(len(mask), strings.Count(mask.String(), ",")+1) 38 assert.Equal(mask.OnesCount(), strings.Count(mask.Text(), ",")+1) 39 } else { 40 assert.Empty(mask.String()) 41 assert.Empty(mask.Text()) 42 } 43 44 mask.ClearAll() 45 assert.Equal(0, mask.OnesCount()) 46 mask.SetAll() 47 for j := 0; j < i; j++ { 48 assert.True(mask.Get(j)) 49 } 50 } 51 }