-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
55 lines (52 loc) · 1.28 KB
/
test.js
File metadata and controls
55 lines (52 loc) · 1.28 KB
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
import assert from 'node:assert';
import Connectron from "./connectron.js";
const testData = [
{
rows: 6,
columns: 6,
playerCount: 2,
lineLength: 4,
grid : [
['2', '1', '2', '1', '2', '1'],
['1', '2', '1', '1', '1', '2'],
['2', '1', '2', '2', '2', '1'],
['1', '2', '1', '1', '1', '2'],
['2', '1', '2', '2', '1', '2'],
['1', '1', '2', '2', '2', '1']
],
expected: {"1": 2, "2": 2}
},
{
rows: 6,
columns: 6,
playerCount: 2,
lineLength: 3,
grid : [
['2', '1', '2', '1', '2', '1'],
['1', '2', '1', '1', '1', '2'],
['2', '1', '2', '2', '2', '1'],
['1', '2', '1', '1', '1', '2'],
['2', '1', '2', '2', '1', '2'],
['1', '1', '2', '2', '2', '1']
],
expected: {"1": 16, "2": 14}
}
];
const runTests = () => {
testData.forEach((data, index) => {
const testGame = new Connectron(data.rows, data.columns, data.playerCount, data.lineLength);
testGame.grid = data.grid;
testGame.printGrid();
const expected = data.expected;
testGame.calculatePoints();
try {
assert.deepEqual(testGame.pointsTable, expected);
console.log(`Test #${index+1} passed!`);
}
catch(e) {
console.error("Test failed!", e);
}
});
};
// Run tests
runTests();