-
Notifications
You must be signed in to change notification settings - Fork 2
/
node_test.go
45 lines (42 loc) · 1.02 KB
/
node_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
package chain
import (
"testing"
)
func TestLastElement(t *testing.T) {
ConfirmLastElement := func(n Node, r interface{}) {
x := LastElement(n)
switch x := x.(type) {
case Equatable:
if !x.Equal(r) {
t.Fatalf("Last(%v) Equatable: should be '%v' but is '%v'", n, r, x)
}
default:
if r != x {
t.Fatalf("Last(%v) default: should be '%v' but is '%v'", n, r, x)
}
}
}
ConfirmLastElement(Cons(0), 0)
ConfirmLastElement(Cons(0, 1), 1)
ConfirmLastElement(Cons(0, 1, 2), 2)
}
func TestMoveToNode(t *testing.T) {
ConfirmMoveTo := func(n Node, i int, r interface{}) {
if x := n.MoveTo(i); x.Content() != r {
t.Fatalf("%v.MoveTo(%v) should be '%v' but is '%v'", n, i, r, x.Content())
}
}
RefuteMoveTo := func(n Node, i int) {
if x := n.MoveTo(i); x != nil {
t.Fatalf("%v.MoveTo(%v) should not succeed", n, i)
}
}
c := Cons(1, 2, 3, 4, 5)
ConfirmMoveTo(c, 0, 1)
ConfirmMoveTo(c, 1, 2)
ConfirmMoveTo(c, 2, 3)
ConfirmMoveTo(c, 3, 4)
ConfirmMoveTo(c, 4, 5)
RefuteMoveTo(c, -1)
RefuteMoveTo(c, 5)
}