-
Notifications
You must be signed in to change notification settings - Fork 4
/
uint64_test.go
50 lines (37 loc) · 1001 Bytes
/
uint64_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
package atomix
import (
"testing"
)
func TestUint64(t *testing.T) {
a := NewUint64(10)
mustEqual(t, a.String(), "10")
mustEqual(t, a.Load(), uint64(10))
mustEqual(t, a.Add(5), uint64(15))
mustEqual(t, a.Sub(3), uint64(12))
mustEqual(t, a.Inc(), uint64(13))
mustEqual(t, a.Dec(), uint64(12))
mustEqual(t, a.CAS(12, 0), true)
mustEqual(t, a.Load(), uint64(0))
mustEqual(t, a.CAS(13, 0), false)
mustEqual(t, a.Swap(1), uint64(0))
mustEqual(t, a.Load(), uint64(1))
a.Store(15)
mustEqual(t, a.Load(), uint64(15))
}
func TestUint64Compare(t *testing.T) {
a := NewUint64(42)
old, ok := a.SwapGreater(80)
mustEqual(t, old, uint64(42))
mustEqual(t, ok, true)
mustEqual(t, a.Load(), uint64(80))
old, ok = a.SwapGreater(40)
mustEqual(t, old, uint64(80))
mustEqual(t, ok, false)
old, ok = a.SwapLess(8)
mustEqual(t, old, uint64(80))
mustEqual(t, ok, true)
mustEqual(t, a.Load(), uint64(8))
old, ok = a.SwapLess(40)
mustEqual(t, old, uint64(8))
mustEqual(t, ok, false)
}