forked from dominikbraun/graph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
traits_test.go
145 lines (119 loc) · 2.52 KB
/
traits_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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package graph
import "testing"
func TestDirected(t *testing.T) {
tests := map[string]struct {
expected *Traits
}{
"directed graph": {
expected: &Traits{
IsDirected: true,
},
},
}
for name, test := range tests {
p := &Traits{}
Directed()(p)
if !traitsAreEqual(test.expected, p) {
t.Errorf("%s: trait expectation doesn't match: expected %v, got %v", name, test.expected, p)
}
}
}
func TestAcyclic(t *testing.T) {
tests := map[string]struct {
expected *Traits
}{
"acyclic graph": {
expected: &Traits{
IsAcyclic: true,
},
},
}
for name, test := range tests {
p := &Traits{}
Acyclic()(p)
if !traitsAreEqual(test.expected, p) {
t.Errorf("%s: trait expectation doesn't match: expected %v, got %v", name, test.expected, p)
}
}
}
func TestWeighted(t *testing.T) {
tests := map[string]struct {
expected *Traits
}{
"weighted graph": {
expected: &Traits{
IsWeighted: true,
},
},
}
for name, test := range tests {
p := &Traits{}
Weighted()(p)
if !traitsAreEqual(test.expected, p) {
t.Errorf("%s: trait expectation doesn't match: expected %v, got %v", name, test.expected, p)
}
}
}
func TestRooted(t *testing.T) {
tests := map[string]struct {
expected *Traits
}{
"rooted graph": {
expected: &Traits{
IsRooted: true,
},
},
}
for name, test := range tests {
p := &Traits{}
Rooted()(p)
if !traitsAreEqual(test.expected, p) {
t.Errorf("%s: trait expectation doesn't match: expected %v, got %v", name, test.expected, p)
}
}
}
func TestTree(t *testing.T) {
tests := map[string]struct {
expected *Traits
}{
"tree graph": {
expected: &Traits{
IsAcyclic: true,
IsRooted: true,
},
},
}
for name, test := range tests {
p := &Traits{}
Tree()(p)
if !traitsAreEqual(test.expected, p) {
t.Errorf("%s: trait expectation doesn't match: expected %v, got %v", name, test.expected, p)
}
}
}
func TestPreventCycles(t *testing.T) {
tests := map[string]struct {
expected *Traits
}{
"prevent cycles": {
expected: &Traits{
IsAcyclic: true,
PreventCycles: true,
},
},
}
for name, test := range tests {
p := &Traits{}
PreventCycles()(p)
if !traitsAreEqual(test.expected, p) {
t.Errorf("%s: trait expectation doesn't match: expected %v, got %v", name, test.expected, p)
}
}
}
func traitsAreEqual(a, b *Traits) bool {
return a.IsAcyclic == b.IsAcyclic &&
a.IsDirected == b.IsDirected &&
a.IsRooted == b.IsRooted &&
a.IsWeighted == b.IsWeighted &&
a.PreventCycles == b.PreventCycles
}