LINE1 10 20 30 40 50 60 701import { test } from 'bun:test';2import assert from 'node:assert/strict';34import * as hex from '../src/hex.js';56test('the board is thirteen columns by ten rows', () => {7 assert.equal(hex.allHexes().length, 130);8 assert.equal(hex.makeHex(13, 0), null);9 assert.equal(hex.makeHex(0, 10), null);10 assert.deepEqual(hex.makeHex(2, 3), { column: 2, row: 3 });11});1213test('each hex has six neighbours and distance is symmetric', () => {14 for (const cell of hex.allHexes()) {15 assert.ok(hex.neighbors(cell).length <= 6);16 }17 const a = { column: 2, row: 8 };18 const b = { column: 4, row: 5 };19 assert.equal(hex.distance(a, b), 4);20 assert.equal(hex.distance(b, a), 4);21 assert.equal(hex.distance(a, a), 0);22});2324test('a line crosses every cell between two hexes', () => {25 const cells = hex.line({ column: 2, row: 8 }, { column: 2, row: 5 });26 assert.deepEqual(cells, [27 { column: 2, row: 8 },28 { column: 2, row: 7 },29 { column: 2, row: 6 },30 { column: 2, row: 5 },31 ]);32});3334test('row centers follow the odd-row offset layout', () => {35 const even = hex.center({ column: 0, row: 0 });36 assert.equal(even.x, -6.25);37 assert.ok(Math.abs(even.z + 3.8971143170299736) < 1e-9);38 const odd = hex.center({ column: 0, row: 1 });39 assert.equal(odd.x, -5.75);40 assert.ok(Math.abs(odd.z + 3.031088913245535) < 1e-9);41});4243test('a point converts back to its hex and outside points do not', () => {44 const cell = { column: 4, row: 6 };45 const point = hex.center(cell);46 assert.deepEqual(hex.hexFromPoint(point.x, point.z), cell);47 assert.equal(hex.hexFromPoint(20, 20), null);48});