-
Notifications
You must be signed in to change notification settings - Fork 33
/
list_test.go
88 lines (84 loc) · 1.49 KB
/
list_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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package dijkstra
import (
"slices"
"testing"
)
func TestLists(t *testing.T) {
inputs := []currentDistance{
{0, 1},
{1, 2},
{2, 3},
{3, 4},
{4, 5},
{5, 6},
{6, 7},
{7, 8},
{8, 9},
{9, 10},
{10, 1 * 2},
{11, 2 * 2},
{12, 3 * 2},
{13, 4 * 2},
{14, 5 * 2},
{15, 6 * 2},
{16, 7 * 2},
{17, 8 * 2},
{18, 9 * 2},
{19, 10 * 2},
{99, 10},
}
shortResult := []currentDistance{
{0, 1},
{1, 2},
{10, 1 * 2},
{2, 3},
{3, 4},
{11, 2 * 2},
{4, 5},
{5, 6},
{12, 3 * 2},
{6, 7},
{7, 8},
{13, 4 * 2},
{8, 9},
{9, 10},
{99, 10},
{14, 5 * 2},
{15, 6 * 2},
{16, 7 * 2},
{17, 8 * 2},
{18, 9 * 2},
{19, 10 * 2},
}
longResult := make([]currentDistance, len(shortResult))
copy(longResult, shortResult)
slices.Reverse(longResult)
lists := []struct {
listEnum int
listName string
}{
{listShortPQ, "listShortPQ"},
{listLongPQ, "listLongPQ"},
{listShortLL, "listShortLL"},
{listLongLL, "listLongLL"},
}
for _, list := range lists {
t.Run(list.listName, func(t *testing.T) {
dl := (&Graph{}).getList(list.listEnum)
var result []currentDistance
if list.listEnum == listShortPQ || list.listEnum == listShortLL {
result = shortResult
} else {
result = longResult
}
for _, input := range inputs {
dl.PushOrdered(input)
}
for i, want := range result {
if got := dl.PopOrdered(); got.distance != want.distance {
t.Errorf("Incorrect order, index %d\nwant:%v\n got:%v", i, want, got)
}
}
})
}
}