package peer

import (
	"math/rand"
	"testing"
)

func TestBitSet(t *testing.T) {
	state := make([]bool, bitSetSize)
	for i := range state {
		state[i] = rand.Float32() > 0.5
	}

	bs := bitSet{}

	for i := range state {
		if state[i] {
			bs.Set(i)
		}
	}

	for i := range state {
		if bs.Get(i) != state[i] {
			t.Fatal(i, state[i], bs.Get(i))
		}
	}

	for i := range state {
		if rand.Float32() > 0.5 {
			state[i] = false
			bs.Clear(i)
		}
	}

	for i := range state {
		if bs.Get(i) != state[i] {
			t.Fatal(i, state[i], bs.Get(i))
		}
	}

	bs.ClearAll()

	for i := range state {
		if bs.Get(i) {
			t.Fatal(i, bs.Get(i))
		}
	}
}
