mirror of
https://github.com/crazybber/awesome-patterns.git
synced 2024-11-21 20:36:01 +03:00
Created a file that has an eg usage of factory
This commit is contained in:
parent
c3ace1a31b
commit
c7042966dc
28
creational/abstract_factory/main_test.go
Normal file
28
creational/abstract_factory/main_test.go
Normal 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())
|
||||
}
|
Loading…
Reference in New Issue
Block a user