|
1 |
| -import { getListOfWagons, fixListOfWagons, correctListOfWagons, updateRoutingInformation, removeTimeOfArrival } from './train-driver'; |
| 1 | +import { getListOfWagons, fixListOfWagons, correctListOfWagons, extendRouteInformation, separateTimeOfArrival } from './train-driver'; |
2 | 2 |
|
3 | 3 | describe('getListOfWagons', () => {
|
4 | 4 | test('return the correct array', () => {
|
5 |
| - expect(getListOfWagons(4,5,2,7,4)).toEqual([4,5,2,7,4]); |
| 5 | + expect(getListOfWagons(1,5,2,7,4)).toEqual([1,5,2,7,4]); |
6 | 6 | });
|
7 | 7 |
|
8 | 8 | test('works for a few arrgument', () => {
|
9 |
| - expect(getListOfWagons(4,5)).toEqual([4,5]); |
| 9 | + expect(getListOfWagons(1,5)).toEqual([1,5]); |
10 | 10 | });
|
11 | 11 |
|
12 | 12 | test('works for a one arrgument', () => {
|
13 |
| - expect(getListOfWagons(5)).toEqual([5]); |
| 13 | + expect(getListOfWagons(1)).toEqual([1]); |
14 | 14 | });
|
15 | 15 |
|
16 | 16 | test('works for many argument', () => {
|
17 |
| - expect(getListOfWagons(4,5,6,3,6,8,4,1,4,7)).toEqual([4,5,6,3,6,8,4,1,4,7]); |
| 17 | + expect(getListOfWagons(1,5,6,3,9,8,4,14,24,7)).toEqual([1,5,6,3,9,8,4,14,24,7]); |
18 | 18 | });
|
19 | 19 | });
|
20 | 20 |
|
21 | 21 | describe('fixListOfWagons', () => {
|
22 | 22 | test('reorder the first 2 wagons to the end of the array', () => {
|
23 |
| - const eachWagonsWieght = [3, 0, 5, 1, 0, 4, 1, 0, 3, 4, 3, 0, 8, 0]; |
24 |
| - const expected = [5, 1, 0, 4, 1, 0, 3, 4, 3, 0, 8, 0, 3, 0]; |
25 |
| - expect(fixListOfWagons(eachWagonsWieght)).toEqual(expected); |
| 23 | + const eachWagonsID = [3, 7, 1, 14, 10, 4, 12, 6, 23, 17, 13, 20, 8, 19]; |
| 24 | + const expected = [1, 14, 10, 4, 12, 6, 23, 17, 13, 20, 8, 19, 3, 7]; |
| 25 | + expect(fixListOfWagons(eachWagonsID)).toEqual(expected); |
26 | 26 | });
|
27 | 27 |
|
28 |
| - test('works when only 2 wagons given', () => { |
29 |
| - const eachWagonsWieght = [1, 2]; |
30 |
| - expect(fixListOfWagons(eachWagonsWieght)).toEqual([1, 2]); |
| 28 | + test('works when only 3 wagons given', () => { |
| 29 | + const eachWagonsID = [4, 2, 1]; |
| 30 | + expect(fixListOfWagons(eachWagonsID)).toEqual([1, 4, 2]); |
31 | 31 | });
|
32 | 32 |
|
33 | 33 | test('works for a few wagons', () => {
|
34 |
| - const eachWagonsWieght = [3, 4, 3, 3, 2, 1, 0]; |
35 |
| - expect(fixListOfWagons(eachWagonsWieght)).toEqual([3, 3, 2, 1, 0, 3, 4]); |
| 34 | + const eachWagonsID = [3, 4, 1, 5, 7, 9, 10]; |
| 35 | + expect(fixListOfWagons(eachWagonsID)).toEqual([1, 5, 7, 9, 10, 3, 4]); |
36 | 36 | });
|
37 | 37 | });
|
38 | 38 |
|
39 | 39 | describe('correctListOfWagons', () => {
|
40 | 40 | test('returns a wagon wieght list with the inserted array of values', () => {
|
41 |
| - const eachWagonsWieght = [3, 0, 5, 1, 0, 4, 1, 0, 3, 4, 3, 0]; |
42 |
| - const missingWagons = [8, 0, 5, 8, 0, 8, 0]; |
43 |
| - const expected = [3, 8, 0, 5, 8, 0, 8, 0, 0, 5, 1, 0, 4, 1, 0, 3, 4, 3, 0]; |
44 |
| - expect(correctListOfWagons(eachWagonsWieght, missingWagons)).toEqual(expected); |
| 41 | + const eachWagonsID = [1, 6, 11, 15, 13, 14, 17, 22, 2, 16, 19, 21]; |
| 42 | + const missingWagons = [8, 10, 5, 9, 3, 7, 20]; |
| 43 | + const expected = [1, 8, 10, 5, 9, 3, 7, 20, 6, 11, 15, 13, 14, 17, 22, 2, 16, 19, 21]; |
| 44 | + expect(correctListOfWagons(eachWagonsID, missingWagons)).toEqual(expected); |
45 | 45 | });
|
46 | 46 |
|
47 | 47 | test('works for short arrays', () => {
|
48 |
| - const eachWagonsWieght = [2, 0, 1, 0]; |
49 |
| - const missingWagons = [8, 6, 0]; |
50 |
| - const expected = [2, 8, 6, 0, 0, 1, 0]; |
51 |
| - expect(correctListOfWagons(eachWagonsWieght, missingWagons)).toEqual(expected); |
| 48 | + const eachWagonsID = [1, 7, 15, 24]; |
| 49 | + const missingWagons = [8, 6, 4]; |
| 50 | + const expected = [1, 8, 6, 4, 7, 15, 24]; |
| 51 | + expect(correctListOfWagons(eachWagonsID, missingWagons)).toEqual(expected); |
52 | 52 | });
|
53 | 53 |
|
54 | 54 | test('works when missingWagons is longer', () => {
|
55 |
| - const eachWagonsWieght = [2, 0, 1, 0]; |
56 |
| - const missingWagons = [8, 6, 0, 5, 8, 0, 8, 0]; |
57 |
| - const expected = [2, 8, 6, 0, 5, 8, 0, 8, 0, 0, 1, 0]; |
58 |
| - expect(correctListOfWagons(eachWagonsWieght, missingWagons)).toEqual(expected); |
| 55 | + const eachWagonsID = [1, 7, 15, 24]; |
| 56 | + const missingWagons = [8, 6, 4, 5, 9, 21, 2, 13]; |
| 57 | + const expected = [1, 8, 6, 4, 5, 9, 21, 2, 13, 7, 15, 24]; |
| 58 | + expect(correctListOfWagons(eachWagonsID, missingWagons)).toEqual(expected); |
59 | 59 | });
|
60 | 60 | });
|
61 | 61 |
|
62 |
| -describe('updateRoutingInformation', () => { |
63 |
| - test('correctly updates route information', () => { |
| 62 | +describe('extendRouteInformation', () => { |
| 63 | + test('correctly extend route information', () => { |
64 | 64 | const route = {from: "Berlin", to: "Hamburg"};
|
65 | 65 | const moreRouteInformation = {timeOfArrival: "12:00", precipitation: "10", temperature: "5"};
|
66 | 66 | const expected = {from: "Berlin", to: "Hamburg", timeOfArrival: "12:00", precipitation: "10", temperature: "5"};
|
67 |
| - expect(updateRoutingInformation(route, moreRouteInformation)).toEqual(expected); |
| 67 | + expect(extendRouteInformation(route, moreRouteInformation)).toEqual(expected); |
68 | 68 | });
|
69 | 69 |
|
70 | 70 | test('works when not adding precipitation', () => {
|
71 | 71 | const route = {from: "Paris", to: "London"};
|
72 | 72 | const moreRouteInformation = {timeOfArrival: "10:30", temperature: "20"};
|
73 | 73 | const expected = {from: "Paris", to: "London", timeOfArrival: "10:30", temperature: "20"};
|
74 |
| - expect(updateRoutingInformation(route, moreRouteInformation)).toEqual(expected); |
| 74 | + expect(extendRouteInformation(route, moreRouteInformation)).toEqual(expected); |
75 | 75 | });
|
76 | 76 |
|
77 | 77 | test('works when written in diffrent order', () => {
|
78 | 78 | const route = {from: "Gothenburg", to: "Copenhagen"};
|
79 | 79 | const moreRouteInformation = {precipitation: "1", timeOfArrival: "21:20", temperature: "-6"};
|
80 | 80 | const expected = {from: "Gothenburg", to: "Copenhagen", precipitation: "1", timeOfArrival: "21:20", temperature: "-6"};
|
81 |
| - expect(updateRoutingInformation(route, moreRouteInformation)).toEqual(expected); |
| 81 | + expect(extendRouteInformation(route, moreRouteInformation)).toEqual(expected); |
82 | 82 | });
|
83 | 83 | });
|
84 | 84 |
|
85 |
| -describe('removeTimeOfArrival', () => { |
86 |
| - test('remove removeTimeOfArrival from object', () => { |
| 85 | +describe('separateTimeOfArrival', () => { |
| 86 | + test('seperate timeOfArrival from object', () => { |
87 | 87 | const route = {from: "Berlin", to: "Hamburg", timeOfArrival: "12:00", precipitation: "10", temperature: "5"};
|
88 |
| - const expected = {from: "Berlin", to: "Hamburg", precipitation: "10", temperature: "5"}; |
89 |
| - expect(removeTimeOfArrival(route)).toEqual(expected); |
| 88 | + const expected = ["12:00", {from: "Berlin", to: "Hamburg", precipitation: "10", temperature: "5"}] |
| 89 | + expect(separateTimeOfArrival(route)).toEqual(expected); |
90 | 90 | });
|
91 | 91 |
|
92 |
| - test('remove removeTimeOfArrival with shorter object', () => { |
| 92 | + test('seperate timeOfArrival with shorter object', () => { |
93 | 93 | const route = {from: "Paris", to: "London", timeOfArrival: "10:30", temperature: "20"};
|
94 |
| - const expected = {from: "Paris", to: "London", temperature: "20"}; |
95 |
| - expect(removeTimeOfArrival(route)).toEqual(expected); |
| 94 | + const expected = ["10:30", {from: "Paris", to: "London", temperature: "20"}] |
| 95 | + expect(separateTimeOfArrival(route)).toEqual(expected); |
96 | 96 | });
|
97 | 97 |
|
98 |
| - test('remove removeTimeOfArrival from object', () => { |
| 98 | + test('seperate timeOfArrival from object', () => { |
99 | 99 | const route = {from: "Gothenburg", to: "Copenhagen", precipitation: "1", timeOfArrival: "21:20", temperature: "-6"};
|
100 |
| - const expected = {from: "Gothenburg", to: "Copenhagen", precipitation: "1", temperature: "-6"}; |
101 |
| - expect(removeTimeOfArrival(route)).toEqual(expected); |
| 100 | + const expected = ["21:20", {from: "Gothenburg", to: "Copenhagen", precipitation: "1", temperature: "-6"}] |
| 101 | + expect(separateTimeOfArrival(route)).toEqual(expected); |
102 | 102 | });
|
103 | 103 | });
|
0 commit comments