-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
40 lines (31 loc) · 954 Bytes
/
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
package main
import (
"encoding/json"
"testing"
)
func TestFindWaySorry(t *testing.T) {
b := `{"forward":"tiger", "left": "ogre", "right":"demon"}`
store := make(map[string]interface{})
json.Unmarshal([]byte(b), &store)
result := FindWay(store)
if result != "Sorry" {
t.Fatalf(`failed sorry test,get %s expected Sorry:`, result)
}
}
func TestFindWayNullTest(t *testing.T) {
store := make(map[string]interface{})
result := FindWay(store)
if result != "Sorry" {
t.Fatalf(`failed null test,get %s expected Sorry:`, result)
}
}
func TestFindWaySuccessful(t *testing.T) {
b := `{"forward":"tiger", "left":{"forward":{"upstairs":"exit"}, "left":"dragon"}, "right":{"forward":
"dead end"}}`
store := make(map[string]interface{})
json.Unmarshal([]byte(b), &store)
result := FindWay(store)
if result != `["left","forward","upstairs"]` {
t.Fatalf(`failed success test,get %s expected ["left","forward","upstairs"]:`, result)
}
}