-
-
Notifications
You must be signed in to change notification settings - Fork 633
/
Copy pathtrain-driver.spec.js
175 lines (159 loc) · 4.89 KB
/
train-driver.spec.js
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import {
getListOfWagons,
fixListOfWagons,
correctListOfWagons,
extendRouteInformation,
separateTimeOfArrival,
} from './train-driver';
describe('getListOfWagons', () => {
test('return the correct array', () => {
expect(getListOfWagons(1, 5, 2, 7, 4)).toEqual([1, 5, 2, 7, 4]);
});
test('works for a few arrgument', () => {
expect(getListOfWagons(1, 5)).toEqual([1, 5]);
});
test('works for a one arrgument', () => {
expect(getListOfWagons(1)).toEqual([1]);
});
test('works for many argument', () => {
expect(getListOfWagons(1, 5, 6, 3, 9, 8, 4, 14, 24, 7)).toEqual([
1, 5, 6, 3, 9, 8, 4, 14, 24, 7,
]);
});
});
describe('fixListOfWagons', () => {
test('reorder the first 2 wagons to the end of the array', () => {
const eachWagonsID = [3, 7, 1, 14, 10, 4, 12, 6, 23, 17, 13, 20, 8, 19];
const expected = [1, 14, 10, 4, 12, 6, 23, 17, 13, 20, 8, 19, 3, 7];
expect(fixListOfWagons(eachWagonsID)).toEqual(expected);
});
test('works when only 3 wagons given', () => {
const eachWagonsID = [4, 2, 1];
expect(fixListOfWagons(eachWagonsID)).toEqual([1, 4, 2]);
});
test('works for a few wagons', () => {
const eachWagonsID = [3, 4, 1, 5, 7, 9, 10];
expect(fixListOfWagons(eachWagonsID)).toEqual([1, 5, 7, 9, 10, 3, 4]);
});
});
describe('correctListOfWagons', () => {
test('returns a wagon wieght list with the inserted array of values', () => {
const eachWagonsID = [1, 6, 11, 15, 13, 14, 17, 22, 2, 16, 19, 21];
const missingWagons = [8, 10, 5, 9, 3, 7, 20];
const expected = [
1, 8, 10, 5, 9, 3, 7, 20, 6, 11, 15, 13, 14, 17, 22, 2, 16, 19, 21,
];
expect(correctListOfWagons(eachWagonsID, missingWagons)).toEqual(expected);
});
test('works for short arrays', () => {
const eachWagonsID = [1, 7, 15, 24];
const missingWagons = [8, 6, 4];
const expected = [1, 8, 6, 4, 7, 15, 24];
expect(correctListOfWagons(eachWagonsID, missingWagons)).toEqual(expected);
});
test('works when missingWagons is longer', () => {
const eachWagonsID = [1, 7, 15, 24];
const missingWagons = [8, 6, 4, 5, 9, 21, 2, 13];
const expected = [1, 8, 6, 4, 5, 9, 21, 2, 13, 7, 15, 24];
expect(correctListOfWagons(eachWagonsID, missingWagons)).toEqual(expected);
});
});
describe('extendRouteInformation', () => {
test('correctly extend route information', () => {
const route = { from: 'Berlin', to: 'Hamburg' };
const moreRouteInformation = {
timeOfArrival: '12:00',
precipitation: '10',
temperature: '5',
};
const expected = {
from: 'Berlin',
to: 'Hamburg',
timeOfArrival: '12:00',
precipitation: '10',
temperature: '5',
};
expect(extendRouteInformation(route, moreRouteInformation)).toEqual(
expected,
);
});
test('works when not adding precipitation', () => {
const route = { from: 'Paris', to: 'London' };
const moreRouteInformation = { timeOfArrival: '10:30', temperature: '20' };
const expected = {
from: 'Paris',
to: 'London',
timeOfArrival: '10:30',
temperature: '20',
};
expect(extendRouteInformation(route, moreRouteInformation)).toEqual(
expected,
);
});
test('works when written in diffrent order', () => {
const route = { from: 'Gothenburg', to: 'Copenhagen' };
const moreRouteInformation = {
precipitation: '1',
timeOfArrival: '21:20',
temperature: '-6',
};
const expected = {
from: 'Gothenburg',
to: 'Copenhagen',
precipitation: '1',
timeOfArrival: '21:20',
temperature: '-6',
};
expect(extendRouteInformation(route, moreRouteInformation)).toEqual(
expected,
);
});
});
describe('separateTimeOfArrival', () => {
test('seperate timeOfArrival from object', () => {
const route = {
from: 'Berlin',
to: 'Hamburg',
timeOfArrival: '12:00',
precipitation: '10',
temperature: '5',
};
const expected = [
'12:00',
{ from: 'Berlin', to: 'Hamburg', precipitation: '10', temperature: '5' },
];
expect(separateTimeOfArrival(route)).toEqual(expected);
});
test('seperate timeOfArrival with shorter object', () => {
const route = {
from: 'Paris',
to: 'London',
timeOfArrival: '10:30',
temperature: '20',
};
const expected = [
'10:30',
{ from: 'Paris', to: 'London', temperature: '20' },
];
expect(separateTimeOfArrival(route)).toEqual(expected);
});
test('seperate timeOfArrival from object', () => {
const route = {
from: 'Gothenburg',
to: 'Copenhagen',
precipitation: '1',
timeOfArrival: '21:20',
temperature: '-6',
};
const expected = [
'21:20',
{
from: 'Gothenburg',
to: 'Copenhagen',
precipitation: '1',
temperature: '-6',
},
];
expect(separateTimeOfArrival(route)).toEqual(expected);
});
});