102 lines
2.1 KiB
JavaScript
102 lines
2.1 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { calculateScore } from "./scoring.js";
|
|
|
|
const square = [
|
|
{ x: 20, y: 20 },
|
|
{ x: 40, y: 20 },
|
|
{ x: 60, y: 20 },
|
|
{ x: 80, y: 20 },
|
|
{ x: 80, y: 40 },
|
|
{ x: 80, y: 60 },
|
|
{ x: 80, y: 80 },
|
|
{ x: 60, y: 80 },
|
|
{ x: 40, y: 80 },
|
|
{ x: 20, y: 80 },
|
|
{ x: 20, y: 60 },
|
|
{ x: 20, y: 40 },
|
|
{ x: 20, y: 20 },
|
|
];
|
|
|
|
const shiftedSquare = square.map((point) => ({
|
|
x: Math.min(100, point.x + 12),
|
|
y: point.y,
|
|
}));
|
|
|
|
const smallSquare = square.map((point) => ({
|
|
x: 35 + (point.x - 20) * 0.5,
|
|
y: 35 + (point.y - 20) * 0.5,
|
|
}));
|
|
|
|
const secondIsland = [
|
|
{ x: 5, y: 5 },
|
|
{ x: 10, y: 5 },
|
|
{ x: 15, y: 5 },
|
|
{ x: 15, y: 10 },
|
|
{ x: 15, y: 15 },
|
|
{ x: 10, y: 15 },
|
|
{ x: 5, y: 15 },
|
|
{ x: 5, y: 10 },
|
|
{ x: 5, y: 7 },
|
|
{ x: 5, y: 5 },
|
|
{ x: 7, y: 5 },
|
|
{ x: 10, y: 5 },
|
|
{ x: 5, y: 5 },
|
|
];
|
|
|
|
const firstIsland = [
|
|
{ x: 5, y: 70 },
|
|
{ x: 12, y: 70 },
|
|
{ x: 20, y: 70 },
|
|
{ x: 20, y: 77 },
|
|
{ x: 20, y: 85 },
|
|
{ x: 12, y: 85 },
|
|
{ x: 5, y: 85 },
|
|
{ x: 5, y: 78 },
|
|
{ x: 5, y: 74 },
|
|
{ x: 5, y: 70 },
|
|
{ x: 8, y: 70 },
|
|
{ x: 12, y: 70 },
|
|
{ x: 5, y: 70 },
|
|
];
|
|
|
|
const tinyNoise = [
|
|
{ x: 90, y: 90 },
|
|
{ x: 91, y: 90 },
|
|
{ x: 91, y: 91 },
|
|
];
|
|
|
|
assert.equal(calculateScore(square, { rings: [square] }), 100);
|
|
assert.equal(calculateScore([], { rings: [square] }), 0);
|
|
assert.equal(calculateScore(square.slice(0, 4), { rings: [square] }), 0);
|
|
assert.ok(calculateScore(shiftedSquare, { rings: [square] }) < 100);
|
|
assert.ok(calculateScore(smallSquare, { rings: [square] }) < 60);
|
|
assert.ok(calculateScore(square, { rings: [square, secondIsland] }) >= 95);
|
|
assert.ok(
|
|
calculateScore([square, secondIsland], { rings: [square, secondIsland] }) >=
|
|
95,
|
|
);
|
|
assert.equal(
|
|
calculateScore([tinyNoise, square], { rings: [square] }),
|
|
100,
|
|
);
|
|
assert.ok(
|
|
calculateScore([firstIsland, secondIsland], {
|
|
rings: [firstIsland, secondIsland],
|
|
}) > 90,
|
|
);
|
|
assert.ok(
|
|
calculateScore([firstIsland, secondIsland], {
|
|
rings: [
|
|
[
|
|
{ x: 5, y: 5 },
|
|
{ x: 20, y: 5 },
|
|
{ x: 20, y: 85 },
|
|
{ x: 5, y: 85 },
|
|
{ x: 5, y: 5 },
|
|
],
|
|
],
|
|
}) < 50,
|
|
);
|
|
|
|
console.log("scoring tests passed");
|