2020-04-21 17:50:21 +03:00
|
|
|
package factorymethod
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
2020-04-24 06:15:47 +03:00
|
|
|
func doWork(factory IRobotFactory, cleanhour int) string {
|
|
|
|
robot := factory.Build()
|
|
|
|
robot.Clean(cleanhour)
|
|
|
|
|
|
|
|
robot.Speak("robot name")
|
|
|
|
|
|
|
|
return robot.Work()
|
|
|
|
|
2020-04-21 17:50:21 +03:00
|
|
|
}
|
|
|
|
|
2020-04-24 06:15:47 +03:00
|
|
|
func TestRobotFactory(t *testing.T) {
|
|
|
|
var factory IRobotFactory
|
2020-04-21 17:50:21 +03:00
|
|
|
|
2020-04-24 06:15:47 +03:00
|
|
|
factory = FightingRobotFactory{}
|
|
|
|
if doWork(factory, 2) != "i can fighting2" {
|
2020-04-21 17:50:21 +03:00
|
|
|
t.Fatal("error with factory method pattern")
|
|
|
|
}
|
|
|
|
|
2020-04-24 06:15:47 +03:00
|
|
|
factory = HomeRobotFactory{}
|
|
|
|
if doWork(factory, 1) != "i can do homework1" {
|
2020-04-21 17:50:21 +03:00
|
|
|
t.Fatal("error with factory method pattern")
|
|
|
|
}
|
|
|
|
}
|