This repository has been archived by the owner on Mar 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelevatorsystem_test.go
88 lines (68 loc) · 1.74 KB
/
elevatorsystem_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package mesoelevator
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func PrintStatus(es ElevatorSystem){
status, ok := es.Status()
if(ok) {
fmt.Printf("Status: %v\n", status)
}
}
func TestNewElevatorSystem(t *testing.T) {
const numElevators = 8
elevatorSystem := NewElevatorSystem(8)
if assert.NotNil(t, elevatorSystem) {
assert.Equal(t, numElevators, len(elevatorSystem.elevators))
assert.Equal(t, 0, elevatorSystem.pickupQueue.Size())
}
}
func TestStatus(t *testing.T) {
const numElevators = 4
elevatorSystem := NewElevatorSystem(numElevators)
if assert.NotNil(t, elevatorSystem) {
// build the test slice to check against
row := 4
checkSlice := make([][]int, row)
for i := range checkSlice {
checkSlice[i] = []int{i+1, 0, 1}
}
slice, ok := elevatorSystem.Status()
assert.Equal(t, true, ok)
assert.Equal(t, checkSlice, slice)
}
}
func TestStep(t *testing.T) {
const numElevators = 2
elevatorSystem := NewElevatorSystem(numElevators)
if assert.NotNil(t, elevatorSystem) {
elevatorSystem.Step()
elevatorSystem.Pickup(2, 1)
elevatorSystem.Step()
PrintStatus(elevatorSystem)
elevatorSystem.Step()
elevatorSystem.Pickup(3, -1)
elevatorSystem.Pickup(3, 1)
elevatorSystem.Pickup(1, 1)
elevatorSystem.Step()
PrintStatus(elevatorSystem)
elevatorSystem.Step()
PrintStatus(elevatorSystem)
elevatorSystem.Step()
PrintStatus(elevatorSystem)
elevatorSystem.Step()
PrintStatus(elevatorSystem)
elevatorSystem.Pickup(5, -1)
elevatorSystem.Step()
PrintStatus(elevatorSystem)
elevatorSystem.Step()
elevatorSystem.Step()
elevatorSystem.Step()
elevatorSystem.Step()
elevatorSystem.Step()
elevatorSystem.Step()
elevatorSystem.Step()
PrintStatus(elevatorSystem)
}
}