-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper_test.go
47 lines (43 loc) · 1.06 KB
/
helper_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 main
import (
"errors"
"reflect"
"testing"
)
func Test_readFile(t *testing.T) {
tests := []struct {
name string
path string
expectedInputData inputData
expectedErr error
}{
{
name: "test happy path",
path: "data/input.json",
expectedInputData: inputData{
Dimensions: 4,
Moves: "DLUURR",
Zombie: zombie{XPos: 2, YPos: 1},
Creatures: []creature{
creature{XPos: 0, YPos: 1},
creature{XPos: 1, YPos: 2},
creature{XPos: 3, YPos: 1},
},
},
},
{
name: "test wrong path",
path: "test.json",
expectedErr: errors.New("open test.json: no such file or directory"),
},
}
for _, test := range tests {
output, err := readFile(test.path)
if !reflect.DeepEqual(test.expectedInputData, output) {
t.Errorf("for %s, expected result %v, but got %v", test.name, test.expectedInputData, output)
}
if err != nil && test.expectedErr.Error() != err.Error() {
t.Errorf("for %s, expected error %v, but got %v", test.name, test.expectedErr, err)
}
}
}