-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5.spec.ts
138 lines (137 loc) · 3.75 KB
/
5.spec.ts
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
import { getCoordinates } from './5';
describe('getCoordinates', () => {
it('should get correct result horizontally', () => {
// arrange
const x = 0;
const fromY = 0;
const toY = 5;
// act
const actual = getCoordinates({ from: [x, fromY], to: [x, toY] });
// assert
expect(actual).toEqual([
[0, 0],
[0, 1],
[0, 2],
[0, 3],
[0, 4],
[0, 5],
]);
});
it('should get correct result vertically', () => {
// arrange
const y = 0;
const fromX = 0;
const toX = 5;
// act
const actual = getCoordinates({ from: [fromX, y], to: [toX, y] });
// assert
expect(actual).toEqual([
[0, 0],
[1, 0],
[2, 0],
[3, 0],
[4, 0],
[5, 0],
]);
});
it('should get correct result diagonally when x increases and y decreases symetrically', () => {
// arrange
const fromX = 0;
const fromY = 5;
const toX = 5;
const toY = 0;
// act
const actual = getCoordinates({ from: [fromX, fromY], to: [toX, toY] }, true);
// assert
expect(actual).toEqual([
[0, 5],
[1, 4],
[2, 3],
[3, 2],
[4, 1],
[5, 0],
]);
});
it('should get correct result diagonally when x increases and y decreases asymetrically', () => {
// arrange
const fromX = 1;
const fromY = 5;
const toX = 4;
const toY = 2;
// act
const actual = getCoordinates({ from: [fromX, fromY], to: [toX, toY] }, true);
// assert
expect(actual).toEqual([
[1, 5],
[2, 4],
[3, 3],
[4, 2],
]);
});
it('should get correct result diagonally when x decreases and y increases symetrically', () => {
// arrange
const fromX = 5;
const fromY = 0;
const toX = 0;
const toY = 5;
// act
const actual = getCoordinates({ from: [fromX, fromY], to: [toX, toY] }, true);
// assert
expect(actual).toEqual([
[0, 5],
[1, 4],
[2, 3],
[3, 2],
[4, 1],
[5, 0],
]);
});
it('should get correct result diagonally when x decreases and y increases asymetrically', () => {
// arrange
const fromX = 5;
const fromY = 2;
const toX = 0;
const toY = 7;
// act
const actual = getCoordinates({ from: [fromX, fromY], to: [toX, toY] }, true);
// assert
expect(actual).toEqual([
[0, 7],
[1, 6],
[2, 5],
[3, 4],
[4, 3],
[5, 2],
]);
});
it('should get correct result diagonally when both x and y increase with same starting values', () => {
// arrange
const fromX = 1;
const fromY = 1;
const toX = 3;
const toY = 3;
// act
const actual = getCoordinates({ from: [fromX, fromY], to: [toX, toY] }, true);
// assert
expect(actual).toEqual([
[1, 1],
[2, 2],
[3, 3],
]);
});
it('should get correct result diagonally both x and y increase with different starting values', () => {
// arrange
const fromX = 1;
const fromY = 2;
const toX = 3;
const toY = 4;
// act
const actual = getCoordinates({ from: [fromX, fromY], to: [toX, toY] }, true);
// assert
expect(actual).toEqual([
[1, 2],
[2, 3],
[3, 4],
]);
});
});