mirror of
https://github.com/crazybber/awesome-patterns.git
synced 2024-11-25 14:26:04 +03:00
26 lines
457 B
Go
26 lines
457 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestCarFactory(t *testing.T) {
|
||
|
carFactory, err := CreateVehicleFactory(CAR)
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
luxuryCar, err := carFactory.NewVehicle(LuxuryCarType)
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
car, ok := luxuryCar.(Car)
|
||
|
if !ok {
|
||
|
t.Fatal("struct assertion failed")
|
||
|
}
|
||
|
|
||
|
t.Logf("CarType: Luxury NumWheels=%d, NumSeats=%d, NumDoors=%d",
|
||
|
luxuryCar.NumWheels(), luxuryCar.NumSeats(), car.NumDoors())
|
||
|
}
|