-
Notifications
You must be signed in to change notification settings - Fork 23
/
command_test.go
55 lines (36 loc) · 1.06 KB
/
command_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
package command
import "testing"
func TestTroopCommand(t *testing.T) {
//教官
in := Instructor{}
//受训队伍1
tr1 := &Troop{name: "girl team"}
turnLeft := &TurnLeftCommand{receiver: tr1}
//受训队伍2
tr2 := &Troop{name: "boy team"}
turnRight := &TurnLeftCommand{receiver: tr2}
//准备命令发给不同的队伍
in.AddCommand(turnRight)
in.AddCommand(turnLeft)
turnback := &TurnBackCommand{receiver: tr2}
in.AddCommand(turnback)
turnback = &TurnBackCommand{receiver: tr1}
in.AddCommand(turnback)
//开始发布指令
in.Execute()
}
func TestDrawCommand(t *testing.T) {
painter := PathPainter{}
painter.Append(&DrawCommand{&Position{1, 1}})
painter.Append(&DrawCommand{&Position{2, 2}})
painter.Append(&DrawCommand{&Position{1, 3}})
expect := "1.1\n2.2\n1.3\n"
if painter.Execute() != expect {
t.Errorf("Expect result to equal %s, but %s.\n", expect, painter.Execute())
}
painter.Undo()
expect = "1.1\n2.2\n"
if painter.Execute() != expect {
t.Errorf("Expect result to equal %s, but %s.\n", expect, painter.Execute())
}
}