Created a file that has an eg usage of factory

This commit is contained in:
Lucas Alves 2021-07-01 01:00:56 -03:00
parent c3ace1a31b
commit c7042966dc

View File

@ -0,0 +1,28 @@
package main
import (
"testing"
)
var c = CarFactory{}
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())
}