-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.ts
112 lines (107 loc) · 3.57 KB
/
test.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
import rectangleArea2 from "./rectangleArea.ts";
import rectangleArea, { TwoDSplit } from "./index.ts";
import { assertEquals } from "https://deno.land/std@0.156.0/testing/asserts.ts";
Deno.test("TwoDSplit-1", () => {
const current = { left: 0, right: 1000000000, down: 0, up: 1000000000 };
const { left, right, up, down } = current;
const result = TwoDSplit(
current,
Math.floor((left + right) / 2),
Math.floor((down + up) / 2),
);
// console.log(current, result);
assertEquals(result, [
{ left: 0, right: 500000000, down: 0, up: 500000000 },
{ left: 0, right: 500000000, down: 500000000, up: 1000000000 },
{ left: 500000000, right: 1000000000, down: 0, up: 500000000 },
{ left: 500000000, right: 1000000000, down: 500000000, up: 1000000000 },
]);
});
Deno.test("TwoDSplit-2", () => {
const current = { left: 0, right: 3, down: 0, up: 3 };
const { left, right, up, down } = current;
const result = TwoDSplit(
current,
Math.floor((left + right) / 2),
Math.floor((down + up) / 2),
);
// console.log(current, result);
assertEquals(result, [
{ left: 0, right: 1, down: 0, up: 1 },
{ left: 0, right: 1, down: 1, up: 3 },
{ left: 1, right: 3, down: 0, up: 1 },
{ left: 1, right: 3, down: 1, up: 3 },
]);
});
Deno.test("TwoDSplit-3", () => {
const current = { left: 0, right: 1, down: 0, up: 1 };
const { left, right, up, down } = current;
const result = TwoDSplit(
current,
Math.floor((left + right) / 2),
Math.floor((down + up) / 2),
);
// console.log(current, result);
assertEquals(result, []);
});
Deno.test("TwoDSplit-4", () => {
const current = { left: 0, right: 0, down: 0, up: 0 };
const { left, right, up, down } = current;
const result = TwoDSplit(
current,
Math.floor((left + right) / 2),
Math.floor((down + up) / 2),
);
// console.log(current, result);
assertEquals(result, []);
});
Deno.test("TwoDSplit-5", () => {
const current = { left: 0, right: 6, down: 0, up: 1 };
const { left, right, up, down } = current;
const result = TwoDSplit(
current,
Math.floor((left + right) / 2),
Math.floor((down + up) / 2),
);
// console.log(current, result);
assertEquals(result, [{ left: 0, right: 3, down: 0, up: 1 }, {
left: 3,
right: 6,
down: 0,
up: 1,
}]);
});
Deno.test("rectangle-area-ii", () => {
testrectangleArea(rectangleArea);
});
Deno.test("rectangle-area-ii", () => {
testrectangleArea(rectangleArea2);
});
function testrectangleArea(
rectangleArea: {
(rectangles: number[][]): number;
},
) {
assertEquals(rectangleArea([[0, 0, 1000000000, 1000000000]]), 49);
assertEquals(rectangleArea([[0, 0, 2, 2], [0, 0, 1, 1]]), 4);
assertEquals(rectangleArea([[0, 0, 2, 2], [1, 0, 2, 3], [1, 0, 3, 1]]), 6);
assertEquals(
rectangleArea([
[93516, 44895, 94753, 69358],
[13141, 52454, 59740, 71232],
[22877, 11159, 85255, 61703],
[11917, 8218, 84490, 36637],
[75914, 29447, 83941, 64384],
[22490, 71433, 64258, 74059],
[18433, 51177, 87595, 98688],
[70854, 80720, 91838, 92304],
[46522, 49839, 48550, 94096],
[95435, 37993, 99139, 49382],
[10618, 696, 33239, 45957],
[18854, 2818, 57522, 78807],
[61229, 36593, 76550, 41271],
[99381, 90692, 99820, 95125],
]),
971243962,
);
}