-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_simple_test.go
69 lines (57 loc) · 1.47 KB
/
example_simple_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
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2017 by Fabian Kohn
//
// This source code is licensed under the Apache License, Version 2.0, found in
// the LICENSE file in the root directory of this source tree.
////////////////////////////////////////////////////////////////////////////////
package topo
import (
"testing"
"github.com/stretchr/testify/require"
)
func testStringType(t *testing.T) []string {
// List of all simple strings (to be sorted)
var allStrings = []string{
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"H",
}
// All string dependencies
var stringDependencies = []Dependency[string]{
{Child: "B", Parent: "A"},
{Child: "B", Parent: "C"},
{Child: "B", Parent: "D"},
{Child: "A", Parent: "E"},
{Child: "D", Parent: "C"},
}
// Perform topological sort
require.Nil(t, Sort(allStrings, stringDependencies))
// Check if all StrDependencies are fulfilled
for _, dependency := range stringDependencies {
posFrom, posTo := -1, -1
for j := 0; j < len(allStrings); j++ {
if allStrings[j] == dependency.Child {
posFrom = j
}
if allStrings[j] == dependency.Parent {
posTo = j
}
}
require.Less(t, posTo, posFrom)
}
return allStrings
}
func TestStringType(t *testing.T) {
testStringType(t)
}
func TestStringTypeStability(t *testing.T) {
expected := testStringType(t)
for run := 0; run < nRunsConsistency; run++ {
require.EqualValues(t, expected, testStringType(t))
}
}