Ejemplo n.º 1
0
func New(numElevators, numFloors int) *ElevatorsGroup {
	elevators := make([]*elevator.Elevator, numElevators)
	for i := 0; i < numElevators; i++ {
		elevators[i] = elevator.New(i, numFloors)
		elevators[i].Start()
	}
	return &ElevatorsGroup{
		numElevators:           numElevators,
		numFloors:              numFloors,
		elevators:              elevators,
		picker:                 DefaultElevatorPicker{},
		queuedElevatorRequests: make(chan ElevatorRequest),
		shutdown:               make(chan bool),
	}
}
Ejemplo n.º 2
0
package elevator_test

import (
	"github.com/fordaz/elevator-kata/elevator"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"time"
)

var _ = Describe("Elevator", func() {
	Describe("RequestDestinationFloor", func() {
		var (
			ele1 *elevator.Elevator
		)
		BeforeEach(func() {
			ele1 = elevator.New(1, 10)
			ele1.Start()
		})

		AfterEach(func() {
			ele1.Shutdown()
		})

		checkVisitedFloor := func(expectedFloor int, e1 *elevator.Elevator, timeoutMillis time.Duration) {
			select {
			case visitedFloor := <-e1.GetVisitedFloors():
				Expect(visitedFloor).To(Equal(expectedFloor))
			case <-time.After(time.Millisecond * timeoutMillis):
			}
		}