go-pattern-examples/creation/03_builder/builder_test.go

33 lines
684 B
Go
Raw Normal View History

2020-04-21 17:50:21 +03:00
package builder
2020-04-27 07:49:49 +03:00
import (
"fmt"
"testing"
)
2020-04-21 17:50:21 +03:00
2020-04-27 07:49:49 +03:00
func TestBuilderCar(t *testing.T) {
builder := NewCarStudio()
builder.Brand("sky").Speed(120).Engine("audi")
car := builder.Build()
if car.Speed() != 120 {
t.Fatalf("Builder1 fail expect 120 ,but get %d", car.Speed())
2020-04-21 17:50:21 +03:00
}
2020-04-27 07:49:49 +03:00
if car.Brand() != "sky" {
t.Fatalf("Builder1 fail expect sky ,but get %s", car.Brand())
2020-04-21 17:50:21 +03:00
}
2020-04-27 07:49:49 +03:00
fmt.Println(car.Speed())
fmt.Println(car.Brand())
2020-04-21 17:50:21 +03:00
}
2020-04-27 12:17:55 +03:00
func TestBuilderCarMore(t *testing.T) {
builder := NewCarStudio()
builder.Brand("land").Speed(110).Engine("bmw")
builder.Engine("man made").Brand("panda").Wheel(15)
car := builder.Build()
fmt.Println(car.Speed())
fmt.Println(car.Brand())
car.Brief()
}