'use strict'; const { describe, it } = require('node:test'); const assert = require('node:assert/strict'); const Planet = require('../src/planet.js'); const almost = (a, b, eps) => Math.abs(a - b) <= eps; 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, 13 / 3); assert.equal(p.clusterFallSpeed, 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, 2, 'gravity minimum is 2 since t1199'); assert.equal(Planet.createPlanet({ jumpsToClear: 1.5 }).jumpsToClear, 2); assert.equal(Planet.createPlanet({ jumpsToClear: 2.4 }).jumpsToClear, 2.4); 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 (2, t1199) one horizontal-3 jump is 75% of the field', () => { const easy = Planet.createPlanet({ jumpsToClear: 2 }); assert.equal(Planet.jumpHeight(easy, 3, false), 1.5 * 13 / 2); 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('single-block fall speed is field height over fallTime; cluster float-down is half (t1124)', () => { const slow = Planet.createPlanet({ fallTime: 5 }); const fast = Planet.createPlanet({ fallTime: 1 }); assert.equal(Planet.DESCENT_SPEED_SCALE, 0.5); assert.equal(slow.fallSpeed, 13 / 5); assert.equal(fast.fallSpeed, 13); assert.equal(slow.clusterFallSpeed, 0.5 * 13 / 5); assert.equal(fast.clusterFallSpeed, 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); assert.ok(Math.abs(fast.clusterFallSpeed / slow.clusterFallSpeed - 5) < 1e-12); // Apex ease duration is shared; cluster accel scales with the halved speed. assert.ok(Math.abs(slow.clusterFallAccel - slow.clusterFallSpeed / slow.apexEaseTime) < 1e-12); assert.ok(Math.abs(slow.fallAccel - slow.fallSpeed / slow.apexEaseTime) < 1e-12); assert.equal(slow.clusterFallSpeed, Planet.DESCENT_SPEED_SCALE * slow.fallSpeed); }); }); describe('Power and display values', () => { it('easiest planet (gravity 2 since t1199) has power 1/9, ~54% miss, shown as 10%', () => { const easy = Planet.createPlanet({ jumpsToClear: 2, fallTime: 5, riseTime: 3 }); assert.ok(Math.abs(Planet.power(easy) - 1 / 9) < 1e-12); assert.ok(Math.abs(Planet.missChance(easy) - (0.60 - 0.55 / 9)) < 1e-12); assert.equal(Planet.displayPower(easy), 10); // The Power scale itself is unchanged: an unclamped gravity-1 input // would still be 0 (the formula keeps its old 1..4 axis). assert.equal(Planet.power({ jumpsToClear: 1, fallTime: 5, riseTime: 3 }), 0); }); 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 = { jumpsToClear: 1, fallTime: 5, riseTime: 3 }; // formula input, not a real planet (t1199) 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.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 (gravity 2 since t1199: Power 1/9, shown as 10%) and Cinder the hardest (gameplay Power 1, 5% miss, shown as 92%)', () => { const aurel = Planet.planetById('aurel'); const cinder = Planet.planetById('cinder'); assert.equal(aurel.jumpsToClear, 2); assert.ok(Math.abs(Planet.power(aurel) - 1 / 9) < 1e-12); for (const p of Planet.officialPlanets()) assert.ok(Planet.power(p) >= Planet.power(aurel) - 1e-12, p.id); 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, 10); assert.equal(Planet.displayValues(cinder).power, 92); }); }); describe('Gravity minimum and percentage display (t1199)', () => { it('constants: range 2..4, 9.81 g at 100%', () => { assert.equal(Planet.GRAVITY_MIN, 2); assert.equal(Planet.GRAVITY_MAX, 4); assert.equal(Planet.EARTH_G, 9.81); }); it('percentage is linear: (v − 1)·100, so 2 → 100%, 3 → 200%, 4 → 300%', () => { assert.equal(Planet.gravityPercent(2), 100); assert.equal(Planet.gravityPercent(2.5), 150); assert.equal(Planet.gravityPercent(3), 200); assert.equal(Planet.gravityPercent(4), 300); assert.equal(Planet.gravityPercent(1), 100, 'below the minimum shows the minimum'); }); it('g follows the percentage: 9.81·(v − 1)', () => { assert.ok(almost(Planet.gravityG(2), 9.81, 1e-12)); assert.ok(almost(Planet.gravityG(3), 19.62, 1e-12)); assert.ok(almost(Planet.gravityG(4), 29.43, 1e-12)); assert.ok(almost(Planet.displayValues(Planet.defaultPlanet()).gravity, 9.81, 1e-12)); assert.equal(Planet.displayValues(Planet.createPlanet({ jumpsToClear: 4 })).gravityPct, 300); }); it('stats text shows "g 100% (9.81g)" for Terra and 300% for Cinder', () => { assert.ok(Planet.formatStats(Planet.defaultPlanet()).startsWith('g 100% (9.81g) ')); assert.ok(Planet.formatStats(Planet.planetById('cinder')).startsWith('g 300% (29.43g) ')); assert.equal(Planet.formatGravity(2.5), '150% (14.71g)'); }); it('every standard planet has gravity ≥ 2', () => { for (const p of Planet.officialPlanets()) assert.ok(p.jumpsToClear >= 2, p.id); const raw = require('../server/lib/planets.json').planets; for (const p of raw) assert.ok(p.jumpsToClear >= 2, 'catalog ' + p.id); for (const id of ['aurel', 'lunara', 'zephyr']) assert.equal(Planet.planetById(id).jumpsToClear, 2, id); }); it('a saved custom planet below 2 loads as 2', () => { const p = Planet.planetFromData({ id: 'c_old', name: 'Oud', people: 'Ouden', jumpsToClear: 1, fallTime: 3, riseTime: 1.5, custom: true }); assert.equal(p.jumpsToClear, 2); }); it('i18n has stats.gravity in every language', () => { const cat = require('../server/lib/i18n.json'); for (const loc of cat.localeIds) { const s = cat.locales[loc]['stats.gravity']; assert.ok(s && s.includes('{pct}') && s.includes('{g}'), loc); } }); });