diff --git a/tests/pirate-ai.test.mjs b/tests/pirate-ai.test.mjs new file mode 100644 index 0000000..b1390d8 --- /dev/null +++ b/tests/pirate-ai.test.mjs @@ -0,0 +1,29 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; + +import { PIRATE_CLASSES, pirateClassForWave, separationVector } from '../src/pirate-ai.js'; + +test('pirate classes expose distinct combat roles', () => { + assert.ok(PIRATE_CLASSES.raider.speed > PIRATE_CLASSES.frigate.speed); + assert.ok(PIRATE_CLASSES.raider.hull < PIRATE_CLASSES.frigate.hull); + assert.ok(PIRATE_CLASSES.captain.hull > PIRATE_CLASSES.frigate.hull); + assert.ok(PIRATE_CLASSES.captain.damage > PIRATE_CLASSES.frigate.damage); +}); + +test('waves introduce raiders and captains without exceeding the wave composition', () => { + assert.equal(pirateClassForWave(1, 0, 1).key, 'frigate'); + assert.equal(pirateClassForWave(3, 0, 3).key, 'raider'); + assert.equal(pirateClassForWave(4, 3, 4).key, 'captain'); +}); + +test('separation steering pushes nearby ships apart and ignores distant ships', () => { + const ship = { x: 100, y: 100, active: true }; + const close = { x: 150, y: 100, active: true }; + const far = { x: 500, y: 100, active: true }; + + const vector = separationVector(ship, [ship, close, far], 125); + + assert.ok(vector.x < 0, 'ship should steer away from a close ship on its right'); + assert.equal(vector.y, 0); + assert.ok(Math.hypot(vector.x, vector.y) <= 1); +});