-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
73 lines (67 loc) · 2.24 KB
/
main_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
package main
import (
"testing"
)
func TestReadFile(t *testing.T) {
result := readFile("final_round_2017.in/test.in")
var expected file
expected.routerRange = 3
expected.backboneCost = 1
expected.routerCost = 100
expected.budget = 220
if result.routerRange != expected.routerRange {
t.Fatalf("Read File Error: \n%v\n%v", result.routerRange, expected.routerRange)
}
if result.backboneCost != expected.backboneCost {
t.Fatalf("Read File Error: \n%v\n%v", result.backboneCost, expected.backboneCost)
}
if result.routerCost != expected.routerCost {
t.Fatalf("Read File Error: \n%v\n%v", result.routerCost, expected.routerCost)
}
if result.budget != expected.budget {
t.Fatalf("Read File Error: \n%v\n%v", result.budget, expected.budget)
}
if result.grid[2][7].backbone != true {
t.Fatalf("Read File Error: \n%v\n%v", result.grid[2][7].backbone, true)
}
}
func TestCoverage(t *testing.T) {
file := readFile("final_round_2017.in/test.in")
file.grid[4][9].router = true
file.grid = addCoverage(file.grid, file.routerRange, 4, 9)
result := covered(file.grid)
expected := 21
if result != expected {
t.Errorf("Coverage Error: %v != %v\nrouter: %v, %v", result, expected, 4, 9)
}
file = readFile("final_round_2017.in/test.in")
file.grid[2][7].router = true
file.grid = addCoverage(file.grid, file.routerRange, 2, 7)
result = covered(file.grid)
expected = 16
if result != expected {
t.Errorf("Coverage Error: %v != %v\nrouter: %v, %v", result, expected, 2, 7)
}
file = readFile("final_round_2017.in/test.in")
file.grid[2][15].router = true
file.grid = addCoverage(file.grid, file.routerRange, 2, 15)
result = covered(file.grid)
expected = 20
if result != expected {
t.Errorf("Coverage Error: %v != %v\nrouter: %v, %v", result, expected, 2, 15)
}
}
func TestScore(t *testing.T) {
file := readFile("final_round_2017.in/test.in")
file.grid[3][6].router = true
file.grid = addCoverage(file.grid, file.routerRange, 3, 6)
file.grid = connectToBackbone(file.grid, 3, 6)
file.grid[3][9].router = true
file.grid = addCoverage(file.grid, file.routerRange, 3, 9)
file.grid = connectToBackbone(file.grid, 3, 9)
result := calculateScore(file)
expected := 35017
if result != expected {
t.Errorf("Score Error: %v != %v\n", result, expected)
}
}