-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.html
111 lines (98 loc) · 3.66 KB
/
test.html
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
<html>
<head>
<script src="util.js"></script>
<script src="windowtiler.js"></script>
<script>
var windowTiler = new WindowTiler();
var success = true;
// TODO: Need to import and use an actual test harness.
function test() {
var bigArea = createArea(0, 0, 1280, 1024);
var mediumArea = createArea(0, 0, 800, 600);
var smallArea = createArea(0, 0, 640, 480);
var bigAreaCopy = createArea(0, 0, 1280, 1024);
///////////////////////////////////////////////////////////////////////////
window.console.log('compareAreas');
assert(WindowTilerUtils.compareAreas(bigArea, smallArea) > 0);
assert(WindowTilerUtils.compareAreas(bigArea, mediumArea) > 0);
assert(WindowTilerUtils.compareAreas(smallArea, mediumArea) < 0);
assert(WindowTilerUtils.compareAreas(bigArea, bigAreaCopy) == 0);
///////////////////////////////////////////////////////////////////////////
window.console.log('computeTiles');
window.console.log('One Single Window');
var oneWindowFullScreenTileSet = [createArea(0, 0, 800, 600)];
var computedTileSet = windowTiler.computeTiles([], 1, 0, 0, 800, 600);
assertTileSetsEqual(oneWindowFullScreenTileSet, computedTileSet);
///////////////////////////////////////////////////////////////////////////
window.console.log('Two windows in wide screen');
var twoWindowsInWideScreenTileSet = [
createArea(0, 0, 200, 100),
createArea(201, 0, 200, 100)];
computedTileSet = windowTiler.computeTiles([], 2, 0, 0, 400, 100);
assertTileSetsEqual(twoWindowsInWideScreenTileSet, computedTileSet);
///////////////////////////////////////////////////////////////////////////
window.console.log('Two windows in high screen');
var twoWindowsInHighScreenTileSet = [
createArea(0, 0, 100, 200),
createArea(0, 201, 100, 200)];
computedTileSet = windowTiler.computeTiles([], 2, 0, 0, 100, 400);
assertTileSetsEqual(twoWindowsInHighScreenTileSet, computedTileSet);
///////////////////////////////////////////////////////////////////////////
window.console.log('Four windows');
var fourWindowsTileSet = [
createArea(0, 0, 100, 100),
createArea(101, 0, 100, 100),
createArea(0, 101, 100, 100),
createArea(101, 101, 100, 100)];
computedTileSet = windowTiler.computeTiles([], 4, 0, 0, 200, 200);
assertTileSetsEqual(fourWindowsTileSet, computedTileSet);
///////////////////////////////////////////////////////////////////////////
window.console.log('Rectangle intersection');
var overlap = WindowTilerUtils.rectangleOverlap(5, 5, 10, 5,
8, 10, 9, 7);
assert(overlap == 10);
// Propagate success or failure to the webpage.
var successDiv = document.getElementById('result');
var message = success ? 'Success' : 'Failure';
successDiv.innerHTML = '<span>' + message + '</span>';
}
function assertTileSetsEqual(setA, setB) {
if (setA.length != setB.length) {
success = false;
}
for (var i = 0; i < setA.length; i++) {
assertTilesEqual(setA[i], setB[i]);
}
}
function assertTilesEqual(tileA, tileB) {
if (tileA.left != tileB.left) {
success = false;
}
if (tileA.top != tileB.top) {
success = false;
}
if (tileA.width != tileB.width) {
success = false;
}
if (tileA.height != tileB.height) {
success = false;
}
}
function createArea(x, y, width, height) {
return {
'left': x,
'top': y,
'width': width,
'height': height};
}
function assert(statement) {
if (!statement) {
success = false;
}
}
</script>
</head>
<body onload="test()">
<div id="result"></div>
</body>
</html>