go-pattern-examples/behavior/07_visitor/visitor_test.go
2020-05-04 23:05:00 +08:00

48 lines
856 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package visitor
import "testing"
func TestSingleVisitor(t *testing.T) {
//汽油提供给,制衣工厂
g := gas{density: 100}
//柴油,提供给军工厂
d := diesel{energy: 897}
//购买石油的客户
m := &militaryFactory{}
c := &clothFactory{}
g.Accept(c)
d.Accept(m)
}
func TestGameVisitorsList(t *testing.T) {
retriveSetting := SettingVisitor{}
attacker := Attacker{}
pA := Player{"snow dance", 100} //角色名名snow dance 100级
pB := Player{"fire dragon", 120}
npc := NPC{"groceries", true} //卖杂货的NPC是能被打死的
env := SystemEnv{"made by china", "v1.2.11"}
//游戏对象
gameObjects := []IGameObject{pA, npc, env, pB}
for _, v := range gameObjects {
v.Accept(retriveSetting)
}
t.Log("\n---- attack- --")
for _, v := range gameObjects {
v.Accept(attacker)
}
}