mirror of
https://github.com/crazybber/go-pattern-examples.git
synced 2024-11-28 22:46:03 +03:00
28 lines
532 B
Go
28 lines
532 B
Go
package factorymethod
|
|
|
|
import "testing"
|
|
|
|
func doWork(factory IRobotFactory, cleanhour int) string {
|
|
robot := factory.Build()
|
|
robot.Clean(cleanhour)
|
|
|
|
robot.Speak("robot name")
|
|
|
|
return robot.Work()
|
|
|
|
}
|
|
|
|
func TestRobotFactory(t *testing.T) {
|
|
var factory IRobotFactory
|
|
|
|
factory = FightingRobotFactory{}
|
|
if doWork(factory, 2) != "i can fighting2" {
|
|
t.Fatal("error with factory method pattern")
|
|
}
|
|
|
|
factory = HomeRobotFactory{}
|
|
if doWork(factory, 1) != "i can do homework1" {
|
|
t.Fatal("error with factory method pattern")
|
|
}
|
|
}
|