Quellcode durchsuchen

Unexport test data structures and fields

It seems these do not need to be exported.
Raul Silvera vor 8 Jahren
Ursprung
Commit
67652dc78c
1 geänderte Dateien mit 67 neuen und 67 gelöschten Zeilen
  1. 67
    67
      internal/graph/graph_test.go

+ 67
- 67
internal/graph/graph_test.go Datei anzeigen

@@ -44,16 +44,16 @@ func graphDebugString(graph *Graph) string {
44 44
 	return debug
45 45
 }
46 46
 
47
-func expectedNodesDebugString(expected []ExpectedNode) string {
47
+func expectedNodesDebugString(expected []expectedNode) string {
48 48
 	debug := ""
49 49
 	for i, node := range expected {
50
-		debug += fmt.Sprintf("Node %d: %p\n", i, node.Node)
50
+		debug += fmt.Sprintf("Node %d: %p\n", i, node.node)
51 51
 	}
52 52
 
53 53
 	for i, node := range expected {
54 54
 		debug += "\n"
55
-		debug += fmt.Sprintf("===  Node %d: %p  ===\n", i, node.Node)
56
-		debug += edgeMapsDebugString(node.In, node.Out)
55
+		debug += fmt.Sprintf("===  Node %d: %p  ===\n", i, node.node)
56
+		debug += edgeMapsDebugString(node.in, node.out)
57 57
 	}
58 58
 	return debug
59 59
 }
@@ -72,19 +72,19 @@ func edgeMapsEqual(this, that EdgeMap) bool {
72 72
 }
73 73
 
74 74
 // nodesEqual checks if node is equal to expected.
75
-func nodesEqual(node *Node, expected ExpectedNode) bool {
76
-	return node == expected.Node && edgeMapsEqual(node.In, expected.In) &&
77
-		edgeMapsEqual(node.Out, expected.Out)
75
+func nodesEqual(node *Node, expected expectedNode) bool {
76
+	return node == expected.node && edgeMapsEqual(node.In, expected.in) &&
77
+		edgeMapsEqual(node.Out, expected.out)
78 78
 }
79 79
 
80 80
 // graphsEqual checks if graph is equivalent to the graph templated by expected.
81
-func graphsEqual(graph *Graph, expected []ExpectedNode) bool {
81
+func graphsEqual(graph *Graph, expected []expectedNode) bool {
82 82
 	if len(graph.Nodes) != len(expected) {
83 83
 		return false
84 84
 	}
85
-	expectedSet := make(map[*Node]ExpectedNode)
85
+	expectedSet := make(map[*Node]expectedNode)
86 86
 	for i := range expected {
87
-		expectedSet[expected[i].Node] = expected[i]
87
+		expectedSet[expected[i].node] = expected[i]
88 88
 	}
89 89
 
90 90
 	for _, node := range graph.Nodes {
@@ -96,21 +96,21 @@ func graphsEqual(graph *Graph, expected []ExpectedNode) bool {
96 96
 	return true
97 97
 }
98 98
 
99
-type ExpectedNode struct {
100
-	Node    *Node
101
-	In, Out EdgeMap
99
+type expectedNode struct {
100
+	node    *Node
101
+	in, out EdgeMap
102 102
 }
103 103
 
104
-type TrimTreeTestCase struct {
105
-	Initial  *Graph
106
-	Expected []ExpectedNode
107
-	Keep     NodePtrSet
104
+type trimTreeTestcase struct {
105
+	initial  *Graph
106
+	expected []expectedNode
107
+	keep     NodePtrSet
108 108
 }
109 109
 
110 110
 // makeExpectedEdgeResidual makes the edge from parent to child residual.
111
-func makeExpectedEdgeResidual(parent, child ExpectedNode) {
112
-	parent.Out[child.Node].Residual = true
113
-	child.In[parent.Node].Residual = true
111
+func makeExpectedEdgeResidual(parent, child expectedNode) {
112
+	parent.out[child.node].Residual = true
113
+	child.in[parent.node].Residual = true
114 114
 }
115 115
 
116 116
 func makeEdgeInline(edgeMap EdgeMap, node *Node) {
@@ -141,16 +141,16 @@ func createEmptyNode() *Node {
141 141
 	}
142 142
 }
143 143
 
144
-// createExpectedNodes creates a slice of ExpectedNodes from nodes.
145
-func createExpectedNodes(nodes ...*Node) ([]ExpectedNode, NodePtrSet) {
146
-	expected := make([]ExpectedNode, len(nodes))
144
+// createExpectedNodes creates a slice of expectedNodes from nodes.
145
+func createExpectedNodes(nodes ...*Node) ([]expectedNode, NodePtrSet) {
146
+	expected := make([]expectedNode, len(nodes))
147 147
 	keep := make(NodePtrSet, len(nodes))
148 148
 
149 149
 	for i, node := range nodes {
150
-		expected[i] = ExpectedNode{
151
-			Node: node,
152
-			In:   make(EdgeMap),
153
-			Out:  make(EdgeMap),
150
+		expected[i] = expectedNode{
151
+			node: node,
152
+			in:   make(EdgeMap),
153
+			out:  make(EdgeMap),
154 154
 		}
155 155
 		keep[node] = true
156 156
 	}
@@ -160,14 +160,14 @@ func createExpectedNodes(nodes ...*Node) ([]ExpectedNode, NodePtrSet) {
160 160
 
161 161
 // createExpectedEdges creates directed edges from the parent to each of the
162 162
 // children.
163
-func createExpectedEdges(parent ExpectedNode, children ...ExpectedNode) {
163
+func createExpectedEdges(parent expectedNode, children ...expectedNode) {
164 164
 	for _, child := range children {
165 165
 		edge := &Edge{
166
-			Src:  parent.Node,
167
-			Dest: child.Node,
166
+			Src:  parent.node,
167
+			Dest: child.node,
168 168
 		}
169
-		parent.Out[child.Node] = edge
170
-		child.In[parent.Node] = edge
169
+		parent.out[child.node] = edge
170
+		child.in[parent.node] = edge
171 171
 	}
172 172
 }
173 173
 
@@ -182,8 +182,8 @@ func createExpectedEdges(parent ExpectedNode, children ...ExpectedNode) {
182 182
 //     0
183 183
 // (3)/ \(4)
184 184
 //   2   3.
185
-func createTestCase1() TrimTreeTestCase {
186
-	// Create Initial graph
185
+func createTestCase1() trimTreeTestcase {
186
+	// Create initial graph
187 187
 	graph := &Graph{make(Nodes, 4)}
188 188
 	nodes := graph.Nodes
189 189
 	for i := range nodes {
@@ -197,18 +197,18 @@ func createTestCase1() TrimTreeTestCase {
197 197
 	setEdgeWeight(nodes[1].Out, nodes[2], 3)
198 198
 	setEdgeWeight(nodes[1].Out, nodes[3], 4)
199 199
 
200
-	// Create Expected graph
200
+	// Create expected graph
201 201
 	expected, keep := createExpectedNodes(nodes[0], nodes[2], nodes[3])
202 202
 	createExpectedEdges(expected[0], expected[1], expected[2])
203
-	makeEdgeInline(expected[0].Out, expected[1].Node)
203
+	makeEdgeInline(expected[0].out, expected[1].node)
204 204
 	makeExpectedEdgeResidual(expected[0], expected[1])
205 205
 	makeExpectedEdgeResidual(expected[0], expected[2])
206
-	setEdgeWeight(expected[0].Out, expected[1].Node, 3)
207
-	setEdgeWeight(expected[0].Out, expected[2].Node, 4)
208
-	return TrimTreeTestCase{
209
-		Initial:  graph,
210
-		Expected: expected,
211
-		Keep:     keep,
206
+	setEdgeWeight(expected[0].out, expected[1].node, 3)
207
+	setEdgeWeight(expected[0].out, expected[2].node, 4)
208
+	return trimTreeTestcase{
209
+		initial:  graph,
210
+		expected: expected,
211
+		keep:     keep,
212 212
 	}
213 213
 }
214 214
 
@@ -227,8 +227,8 @@ func createTestCase1() TrimTreeTestCase {
227 227
 //   3
228 228
 //   | (10)
229 229
 //   4.
230
-func createTestCase2() TrimTreeTestCase {
231
-	// Create Initial graph
230
+func createTestCase2() trimTreeTestcase {
231
+	// Create initial graph
232 232
 	graph := &Graph{make(Nodes, 5)}
233 233
 	nodes := graph.Nodes
234 234
 	for i := range nodes {
@@ -243,27 +243,27 @@ func createTestCase2() TrimTreeTestCase {
243 243
 	setEdgeWeight(nodes[2].Out, nodes[0], 15)
244 244
 	setEdgeWeight(nodes[0].Out, nodes[4], 10)
245 245
 
246
-	// Create Expected graph
246
+	// Create expected graph
247 247
 	expected, keep := createExpectedNodes(nodes[3], nodes[4])
248 248
 	createExpectedEdges(expected[0], expected[1])
249 249
 	makeExpectedEdgeResidual(expected[0], expected[1])
250
-	setEdgeWeight(expected[0].Out, expected[1].Node, 10)
251
-	return TrimTreeTestCase{
252
-		Initial:  graph,
253
-		Expected: expected,
254
-		Keep:     keep,
250
+	setEdgeWeight(expected[0].out, expected[1].node, 10)
251
+	return trimTreeTestcase{
252
+		initial:  graph,
253
+		expected: expected,
254
+		keep:     keep,
255 255
 	}
256 256
 }
257 257
 
258 258
 // createTestCase3 creates an initally empty graph and expects an empty graph
259 259
 // after trimming.
260
-func createTestCase3() TrimTreeTestCase {
260
+func createTestCase3() trimTreeTestcase {
261 261
 	graph := &Graph{make(Nodes, 0)}
262 262
 	expected, keep := createExpectedNodes()
263
-	return TrimTreeTestCase{
264
-		Initial:  graph,
265
-		Expected: expected,
266
-		Keep:     keep,
263
+	return trimTreeTestcase{
264
+		initial:  graph,
265
+		expected: expected,
266
+		keep:     keep,
267 267
 	}
268 268
 }
269 269
 
@@ -272,28 +272,28 @@ func createTestCase3() TrimTreeTestCase {
272 272
 //
273 273
 // After keeping 0, it expects the graph:
274 274
 //   0.
275
-func createTestCase4() TrimTreeTestCase {
275
+func createTestCase4() trimTreeTestcase {
276 276
 	graph := &Graph{make(Nodes, 1)}
277 277
 	nodes := graph.Nodes
278 278
 	for i := range nodes {
279 279
 		nodes[i] = createEmptyNode()
280 280
 	}
281 281
 	expected, keep := createExpectedNodes(nodes[0])
282
-	return TrimTreeTestCase{
283
-		Initial:  graph,
284
-		Expected: expected,
285
-		Keep:     keep,
282
+	return trimTreeTestcase{
283
+		initial:  graph,
284
+		expected: expected,
285
+		keep:     keep,
286 286
 	}
287 287
 }
288 288
 
289
-func createTrimTreeTestCases() []TrimTreeTestCase {
290
-	caseGenerators := []func() TrimTreeTestCase{
289
+func createTrimTreeTestCases() []trimTreeTestcase {
290
+	caseGenerators := []func() trimTreeTestcase{
291 291
 		createTestCase1,
292 292
 		createTestCase2,
293 293
 		createTestCase3,
294 294
 		createTestCase4,
295 295
 	}
296
-	cases := make([]TrimTreeTestCase, len(caseGenerators))
296
+	cases := make([]trimTreeTestcase, len(caseGenerators))
297 297
 	for i, gen := range caseGenerators {
298 298
 		cases[i] = gen()
299 299
 	}
@@ -303,11 +303,11 @@ func createTrimTreeTestCases() []TrimTreeTestCase {
303 303
 func TestTrimTree(t *testing.T) {
304 304
 	tests := createTrimTreeTestCases()
305 305
 	for _, test := range tests {
306
-		graph := test.Initial
307
-		graph.TrimTree(test.Keep)
308
-		if !graphsEqual(graph, test.Expected) {
306
+		graph := test.initial
307
+		graph.TrimTree(test.keep)
308
+		if !graphsEqual(graph, test.expected) {
309 309
 			t.Fatalf("Graphs do not match.\nExpected: %s\nFound: %s\n",
310
-				expectedNodesDebugString(test.Expected),
310
+				expectedNodesDebugString(test.expected),
311 311
 				graphDebugString(graph))
312 312
 		}
313 313
 	}