go-pattern-examples/creation/04_factory_method/factorymethod_test.go

27 lines
473 B
Go
Raw Normal View History

2020-04-21 17:50:21 +03:00
package factorymethod
import "testing"
2020-04-23 07:23:28 +03:00
func compute(factory IRobotFactory, a, b int) int {
2020-04-21 17:50:21 +03:00
op := factory.Create()
op.SetA(a)
op.SetB(b)
return op.Result()
}
func TestOperator(t *testing.T) {
var (
factory OperatorFactory
)
factory = PlusOperatorFactory{}
if compute(factory, 1, 2) != 3 {
t.Fatal("error with factory method pattern")
}
factory = MinusOperatorFactory{}
if compute(factory, 4, 2) != 2 {
t.Fatal("error with factory method pattern")
}
}