BlueGit

projects-timfalken-com meteors

Files

meteors / test / cluster-descent.test.js

cluster-descent.test.js

cluster-descent.test.js 3.0 KiB Download Raw
1'use strict';
2
3const { describe, it } = require('node:test');
4const assert = require('node:assert/strict');
5const { makeGame, placeRow, almost, Planet } = require('./helpers.js');
6
7describe('Cluster float-down is halved, single-block fall is not (t1124)', () =>
8{
9 it('a newly spawned block falls at the full fallSpeed', () =>
10 {
11 const g = makeGame({ seed: 3 });
12 const spawned = g.trySpawn();
13 assert.ok(spawned);
14 assert.equal(spawned.state, 'falling');
15 assert.ok(almost(spawned.vy, -g.planet.fallSpeed, 1e-12));
16 assert.ok(g.planet.fallSpeed > g.planet.clusterFallSpeed + 0.5);
17 const y1 = spawned.y;
18 g.step(0.2, 1 / 120);
19 const speed = (y1 - spawned.y) / 0.2;
20 assert.ok(almost(speed, g.planet.fallSpeed, 0.15), 'spawn speed=' + speed);
21 });
22
23 it('unsupported and ingested garbage fall at the full fallSpeed', () =>
24 {
25 const g = makeGame({ noSpawn: true, seed: 2 });
26 const hanging = g.place(0, 4, 1);
27 g.releaseUnsupported();
28 assert.equal(hanging.state, 'falling');
29 assert.ok(almost(hanging.vy, 0, 1e-12), 'starts from rest');
30 g.step(g.planet.apexEaseTime + 0.05, 1 / 120);
31 assert.ok(almost(Math.abs(hanging.vy), g.planet.fallSpeed, 0.1),
32 'unsupported terminal vy=' + hanging.vy);
33
34 const garbage = g.ingestGarbage(3);
35 assert.ok(almost(garbage.vy, -g.planet.fallSpeed, 1e-12));
36 });
37
38 it('a launched cluster eases into the halved clusterFallSpeed, not fallSpeed', () =>
39 {
40 const g = makeGame({ noSpawn: true });
41 placeRow(g, 0, [0, 1, 2], 0);
42 g.resolveMatches();
43 g.step(g.planet.riseTime + g.planet.apexEaseTime + 0.05, 1 / 240);
44 const cluster = g.clusters[g.blocks[0].clusterId];
45 assert.ok(cluster, 'still flying');
46 assert.equal(cluster.phase, 'down');
47 assert.ok(almost(Math.abs(cluster.vy), g.planet.clusterFallSpeed, 0.08),
48 'cluster vy=' + cluster.vy + ' expected ' + (-g.planet.clusterFallSpeed));
49 assert.ok(Math.abs(cluster.vy) < g.planet.fallSpeed - 0.5,
50 'must not use the full single-block fallSpeed');
51 });
52
53 it('a manual jump comes down at the full fallSpeed', () =>
54 {
55 const g = makeGame({ noSpawn: true });
56 const block = g.place(4, 0, 2);
57 g.startManualLaunch(block);
58 assert.equal(block.state, 'manual');
59 g.step(g.planet.riseTime + g.planet.apexEaseTime + 0.05, 1 / 240);
60 assert.equal(block.manualPhase, 'down');
61 assert.ok(almost(Math.abs(block.vy), g.planet.fallSpeed, 0.12),
62 'manual vy=' + block.vy + ' expected ' + (-g.planet.fallSpeed));
63 assert.ok(Math.abs(block.vy) > g.planet.clusterFallSpeed + 0.5);
64 });
65
66 it('cargo riding a descending cluster shares the halved float-down', () =>
67 {
68 const g = makeGame({ noSpawn: true });
69 placeRow(g, 0, [0, 1, 2], 0);
70 const cargo = g.place(1, 1, 4);
71 g.resolveMatches();
72 assert.equal(cargo.state, 'flying');
73 g.step(g.planet.riseTime + g.planet.apexEaseTime + 0.05, 1 / 240);
74 const cluster = g.clusters[cargo.clusterId];
75 assert.ok(cluster);
76 assert.ok(almost(Math.abs(cluster.vy), g.planet.clusterFallSpeed, 0.08));
77 assert.ok(almost(cargo.vy, cluster.vy, 1e-9));
78 });
79});