-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfully_traverse_test.go
47 lines (39 loc) · 968 Bytes
/
fully_traverse_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
package problem1579
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
type Result struct {
N int
Edges [][]int
Expected int
}
var Results = []Result{
{4, [][]int{{3, 1, 2}, {3, 2, 3}, {1, 1, 3}, {1, 2, 4}, {1, 1, 2}, {2, 3, 4}}, 2},
{4, [][]int{{3, 1, 2}, {3, 2, 3}, {1, 1, 4}, {2, 1, 4}}, 0},
{4, [][]int{{3, 2, 3}, {1, 1, 2}, {2, 3, 4}}, -1},
}
func TestMaxEdgesRemovedTraversal(t *testing.T) {
assert := assert.New(t)
for _, res := range Results {
want := res.Expected
got := maxNumEdgesToRemove(res.N, copyIntInt(res.Edges))
assert.Equal(want, got, fmt.Sprintf("%+v", res))
}
}
func BenchmarkMaxEdgesRemovedTraversal(b *testing.B) {
for i := 0; i < b.N; i++ {
for _, res := range Results {
maxNumEdgesToRemove(res.N, copyIntInt(res.Edges))
}
}
}
func copyIntInt(a [][]int) [][]int {
res := make([][]int, len(a))
for i := range a {
res[i] = make([]int, len(a[i]))
copy(res[i], a[i])
}
return res
}