github.com/benz9527/xboot@v0.0.0-20240504061247-c23f15593274/lib/bits/bitmap_test.go (about)

     1  package bits
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  )
     8  
     9  func TestNewX32Bitmap(t *testing.T) {
    10  	bm := NewX32Bitmap(10)
    11  	bm2 := NewX32Bitmap(10)
    12  	originalOffsets := []uint64{9, 5, 7, 3, 2, 8, 1}
    13  	expectedOffsets := []uint64{1, 2, 3, 5, 7, 8, 9}
    14  	for _, offset := range originalOffsets {
    15  		bm.SetBit(offset)
    16  		bm2.SetBit(offset)
    17  	}
    18  	bm.SetBit(100)
    19  	bm.UnsetBit(100)
    20  	bm2.UnsetBit(4)
    21  	for _, offset := range expectedOffsets {
    22  		require.True(t, bm.GetBit(offset))
    23  	}
    24  	require.True(t, bm.EqualTo(bm2))
    25  	require.False(t, bm.GetBit(100))
    26  	bm.Purge()
    27  
    28  	bm = NewX32Bitmap(maxBitMapSize + 1)
    29  	bm.Purge()
    30  }