-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathstate_test.go
42 lines (38 loc) · 882 Bytes
/
state_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
package observer
import "testing"
func testStateNew[T comparable](t *testing.T, state *state[T], val T) {
if state.value != val {
t.Fatalf("Expecting %#v but got %#v\n", val, state.value)
}
if state.next != nil {
t.Fatalf("Expecting no next but got %#v\n", state.next)
}
select {
case <-state.done:
t.Fatalf("Expecting not done\n")
default:
}
}
func TestStateNew(t *testing.T) {
state := newState(10)
testStateNew(t, state, 10)
}
func TestStateUpdate(t *testing.T) {
state1 := newState(10)
state2 := state1.update(15)
if state1 == state2 {
t.Fatalf("Expecting different states\n")
}
if state2.value != 15 {
t.Fatalf("Expecting 15 but got %#v\n", state1.value)
}
if state1.next == nil {
t.Fatalf("Expecting next but got %#v\n", state1.next)
}
select {
case <-state1.done:
default:
t.Fatalf("Expecting done\n")
}
testStateNew(t, state2, 15)
}