-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
64 lines (52 loc) · 1.62 KB
/
index.test.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
const { getTwoFlightIndex, getTwoFlightIndexPerformance } = require('.');
test('Flow travels should return the longest flight possibles', () => {
// Arrange
const flights = [10, 20, 5, 1, 40];
const maxAirplaneDistance = 16;
// Act
const flightsResults = getTwoFlightIndex(flights, maxAirplaneDistance);
// Assert
expect(flightsResults.length).toEqual(2);
expect(flightsResults[0]).toEqual(0);
expect(flightsResults[1]).toEqual(2);
});
test('Flow travels should return the longest flight possibles', () => {
// Arrange
const flights = [10, 20, 5, 1, 40];
const maxAirplaneDistance = 16;
// Act
const flightsResults = getTwoFlightIndexPerformance(
flights,
maxAirplaneDistance
);
// Assert
expect(flightsResults.length).toEqual(2);
expect(flightsResults[0]).toEqual(0);
expect(flightsResults[1]).toEqual(2);
});
test('Flight travels should not be less than 2 flight', () => {
// Arrange
const flights = [];
const maxAirplaneDistance = 16;
// Act
function shouldThrowError() {
getTwoFlightIndex(flights, maxAirplaneDistance);
}
// Assert
expect(
shouldThrowError.bind(null, flights, maxAirplaneDistance)
).toThrowError(/Given flags could not be less than two flights/i);
});
test('Flight travels should not be less distance than 1', () => {
// Arrange
const flights = [10, 20, 30, 40];
const maxAirplaneDistance = 0;
// Act
function shouldThrowError() {
getTwoFlightIndex(flights, maxAirplaneDistance);
}
// Assert
expect(
shouldThrowError.bind(null, flights, maxAirplaneDistance)
).toThrowError(/Given flags could not be less than two flights/i);
});