-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbit_flags_test.go
59 lines (50 loc) · 1.45 KB
/
bit_flags_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package bit_flags
import (
"testing"
"github.com/stretchr/testify/require"
)
const (
testProperty1 = 1 << iota
testProperty2
testProperty3
testProperty4
testProperty5
testProperty6
)
func TestBitProperties_Set(t *testing.T) {
bf := New[uint8]()
bf.Set(testProperty1 | testProperty5)
require.Equal(t, uint8(17), bf.Get())
}
func TestBitProperties_Add(t *testing.T) {
bf := New[uint8]()
bf.Set(testProperty1 | testProperty5)
bf.Add(testProperty2 | testProperty3)
require.Equal(t, uint8(23), bf.Get())
}
func TestBitProperties_Remove(t *testing.T) {
bf := New[uint8]()
bf.Set(testProperty1 | testProperty5 | testProperty4 | testProperty6)
bf.Remove(testProperty5)
require.Equal(t, uint8(41), bf.Get())
require.Equal(t, false, bf.Has(testProperty5|testProperty1))
require.Equal(t, true, bf.Has(testProperty1))
}
func TestBitProperties_Reset(t *testing.T) {
bf := New[uint8]()
bf.Set(testProperty1 | testProperty5)
bf.Reset()
require.Equal(t, uint8(0), bf.Get())
}
func TestBitProperties_Has(t *testing.T) {
bf := New[uint8]()
bf.Set(testProperty1 | testProperty5 | testProperty4 | testProperty6)
require.Equal(t, true, bf.Has(testProperty5|testProperty1))
require.Equal(t, false, bf.Has(testProperty2))
}
func TestBitProperties_List(t *testing.T) {
bf := New[uint8]()
bf.Set(testProperty1 | testProperty5 | testProperty4 | testProperty6)
exp := []uint8{testProperty1, testProperty4, testProperty5, testProperty6}
require.Equal(t, exp, bf.List())
}