'use strict'; const { describe, it } = require('node:test'); const assert = require('node:assert/strict'); const Planet = require('../src/planet.js'); describe('Planet field and defaults', () => { it('has a 10 by 13 field', () => { assert.equal(Planet.FIELD_WIDTH, 10); assert.equal(Planet.FIELD_HEIGHT, 13); }); it('default planet is Terra with mid-range physics', () => { const p = Planet.defaultPlanet(); assert.equal(p.name, 'Terra'); assert.equal(p.people, 'Terrans'); assert.equal(p.jumpsToClear, 2); assert.equal(p.fallTime, 3); assert.equal(p.riseTime, 1.5); assert.equal(p.colors.length, 5); assert.equal(p.baseJumpHeight, 1.5 * 13 / 2); assert.equal(p.fallSpeed, 0.5 * 13 / 3); }); it('clamps gravity, air and mass to the stage-3 ranges', () => { const lo = Planet.createPlanet({ jumpsToClear: 0, fallTime: 0, riseTime: 0 }); assert.equal(lo.jumpsToClear, 1); assert.equal(lo.fallTime, 1); assert.equal(lo.riseTime, 0.5); const hi = Planet.createPlanet({ jumpsToClear: 9, fallTime: 99, riseTime: 99 }); assert.equal(hi.jumpsToClear, 4); assert.equal(hi.fallTime, 5); assert.equal(hi.riseTime, 3); }); it('keeps colors and shapes data-driven with a unique shape per color', () => { const colors = Planet.defaultColors(); assert.equal(colors.length, 5); const shapes = new Set(colors.map((c) => c.shape)); const images = new Set(colors.map((c) => c.image)); assert.equal(shapes.size, 5); assert.equal(images.size, 5); for (const c of colors) { assert.ok(c.hex.startsWith('#')); assert.ok(c.image.startsWith('images/')); assert.ok(typeof c.name === 'string' && c.name.length > 0); } }); }); describe('Jump height rules', () => { const planet = Planet.defaultPlanet(); const base = planet.baseJumpHeight; it('a horizontal match of 3 uses the base jump height', () => { assert.equal(Planet.jumpHeight(planet, 3, false), base); }); it('a vertical match of 3 is 120% of a horizontal row', () => { assert.equal(Planet.jumpHeight(planet, 3, true), base * 1.2); }); it('each extra block beyond 3 adds 5% jump height', () => { assert.ok(Math.abs(Planet.jumpHeight(planet, 4, false) - base * 1.05) < 1e-12); assert.ok(Math.abs(Planet.jumpHeight(planet, 5, false) - base * 1.10) < 1e-12); assert.ok(Math.abs(Planet.jumpHeight(planet, 4, true) - base * (1.2 + 0.05)) < 1e-12); assert.ok(Math.abs(Planet.jumpHeight(planet, 6, true) - base * (1.2 + 0.15)) < 1e-12); }); it('at min gravity one horizontal-3 jump is 50% taller than the field', () => { const easy = Planet.createPlanet({ jumpsToClear: 1 }); assert.equal(Planet.jumpHeight(easy, 3, false), 1.5 * 13); assert.equal(Planet.JUMP_HEIGHT_SCALE, 1.5); }); it('at max gravity four horizontal-3 jumps equal 1.5 times the field height', () => { const hard = Planet.createPlanet({ jumpsToClear: 4 }); assert.equal(Planet.jumpHeight(hard, 3, false) * 4, 1.5 * 13); }); }); describe('Launch and fall physics parameters', () => { it('a jump of height H peaks in riseTime at constant deceleration', () => { const p = Planet.defaultPlanet(); const H = 6.5; const v0 = Planet.launchVelocity(p, H); const a = Planet.launchDeceleration(p, H); assert.equal(v0, 2 * H / p.riseTime); assert.equal(a, 2 * H / (p.riseTime * p.riseTime)); // v = v0 - a t; v=0 at t=riseTime; s = v0 t - 0.5 a t^2 = H const t = p.riseTime; assert.ok(Math.abs((v0 - a * t)) < 1e-12); assert.ok(Math.abs((v0 * t - 0.5 * a * t * t) - H) < 1e-12); }); it('apex time is independent of jump height (mass)', () => { const p = Planet.defaultPlanet(); const a1 = Planet.launchDeceleration(p, 4); const v1 = Planet.launchVelocity(p, 4); const a2 = Planet.launchDeceleration(p, 10); const v2 = Planet.launchVelocity(p, 10); assert.ok(Math.abs(v1 / a1 - p.riseTime) < 1e-12); assert.ok(Math.abs(v2 / a2 - p.riseTime) < 1e-12); }); it('fall speed is half the field height over fallTime (t1122), ratios kept', () => { const slow = Planet.createPlanet({ fallTime: 5 }); const fast = Planet.createPlanet({ fallTime: 1 }); assert.equal(Planet.DESCENT_SPEED_SCALE, 0.5); assert.equal(slow.fallSpeed, 0.5 * 13 / 5); assert.equal(fast.fallSpeed, 0.5 * 13); assert.ok(fast.fallSpeed > slow.fallSpeed); // Relative difference between planets is unchanged (1 / fallTime). assert.ok(Math.abs(fast.fallSpeed / slow.fallSpeed - 5) < 1e-12); }); }); describe('Power and display values', () => { it('easiest planet has power 0 and 60% miss chance', () => { const easy = Planet.createPlanet({ jumpsToClear: 1, fallTime: 5, riseTime: 3 }); assert.equal(Planet.power(easy), 0); assert.equal(Planet.missChance(easy), 0.60); }); it('hardest planet has power 1 and 5% miss chance', () => { const hard = Planet.createPlanet({ jumpsToClear: 4, fallTime: 1, riseTime: 0.5 }); assert.ok(Math.abs(Planet.power(hard) - 1) < 1e-12); assert.ok(Math.abs(Planet.missChance(hard) - 0.05) < 1e-12); }); it('display values are numeric gravity, density, newtons and power %', () => { const p = Planet.defaultPlanet(); const d = Planet.displayValues(p); assert.ok(d.gravity > 0); assert.ok(d.density > 0); assert.ok(d.newtons > 0); assert.equal(typeof d.power, 'number'); assert.ok(d.power >= 0 && d.power <= 100); // Mid-range Terra (jumps=2) shows Earth-like 9.81 assert.ok(Math.abs(d.gravity - 9.81) < 1e-9); }); it('displayed Power is 1 − missChance / 0.60, so 0% miss shows as 100% Power', () => { const easy = Planet.createPlanet({ jumpsToClear: 1, fallTime: 5, riseTime: 3 }); const hard = Planet.createPlanet({ jumpsToClear: 4, fallTime: 1, riseTime: 0.5 }); const terra = Planet.defaultPlanet(); // 60% miss → 0% Power; 5% miss → 92% (not 100 — the floor is 5%, not 0). assert.equal(Planet.displayPower(easy), 0); assert.equal(Planet.displayValues(easy).power, 0); assert.equal(Planet.displayPower(hard), Math.round((1 - 0.05 / 0.60) * 100)); assert.equal(Planet.displayPower(hard), 92); const terraMiss = Planet.missChance(terra); assert.equal(Planet.displayPower(terra), Math.round((1 - terraMiss / 0.60) * 100)); assert.equal(Planet.displayValues(terra).power, 44); // Gameplay power() and missChance() are unchanged. assert.equal(Planet.power(easy), 0); assert.ok(Math.abs(Planet.power(hard) - 1) < 1e-12); assert.equal(Planet.missChance(easy), 0.60); assert.ok(Math.abs(Planet.missChance(hard) - 0.05) < 1e-12); // Monotonic: a lower miss chance means a higher displayed Power. assert.ok(Planet.displayPower(hard) > Planet.displayPower(terra)); assert.ok(Planet.displayPower(terra) > Planet.displayPower(easy)); }); }); describe('Planet catalog', () => { it('has 8–12 named worlds, each with a people name and five unique shapes', () => { const all = Planet.allPlanets(); assert.ok(all.length >= 8 && all.length <= 12, 'catalog size ' + all.length); const ids = new Set(); const images = new Set(); for (const p of all) { assert.ok(p.id && p.name && p.people, p.id); assert.ok(!ids.has(p.id), 'duplicate id ' + p.id); ids.add(p.id); assert.equal(p.colors.length, 5); const shapes = new Set(p.colors.map((c) => c.shape)); assert.equal(shapes.size, 5, p.id + ' shapes'); for (const c of p.colors) { assert.ok(c.image.startsWith('images/block-' + p.id + '-'), c.image); assert.ok(!images.has(c.image), 'duplicate image ' + c.image); images.add(c.image); } assert.ok(p.jumpsToClear >= 1 && p.jumpsToClear <= 4); assert.ok(p.fallTime >= 1 && p.fallTime <= 5); assert.ok(p.riseTime >= 0.5 && p.riseTime <= 3); } assert.ok(ids.has('terra')); assert.equal(Planet.defaultPlanet().id, 'terra'); assert.equal(Planet.planetById('cinder').name, 'Cinder'); }); it('Aurel is the easiest (gameplay Power 0, 60% miss, shown as 0%) and Cinder the hardest (gameplay Power 1, 5% miss, shown as 92%)', () => { const aurel = Planet.planetById('aurel'); const cinder = Planet.planetById('cinder'); assert.equal(Planet.power(aurel), 0); assert.equal(Planet.missChance(aurel), 0.60); assert.ok(Math.abs(Planet.power(cinder) - 1) < 1e-12); assert.ok(Math.abs(Planet.missChance(cinder) - 0.05) < 1e-12); assert.equal(Planet.displayValues(aurel).power, 0); assert.equal(Planet.displayValues(cinder).power, 92); }); });