tobogganSe connecter

starfleet-ui

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

38 lignes · 1260 octetsBrut · Historique
1import { expect, test } from 'bun:test';
2import { DETAILS } from './fixtures';
3import { buildGraph, planTrip, systemPath } from './navigation';
4
5const graph = buildGraph(DETAILS);
6
7test('systemPath prefers the faster chain of jumps', () => {
8 // via B: (60+10) + (60+20) = 150 s; direct: 60+80 = 140 s → direct wins
9 expect(systemPath(graph, 'AA-1', 'CC-3')).toEqual(['AA-1', 'CC-3']);
10 expect(systemPath(graph, 'AA-1', 'BB-2')).toEqual(['AA-1', 'BB-2']);
11});
12
13test('in-system plan is one trip', () => {
14 const plan = planTrip(graph, 'AA-1-A', 'AA-1-B', 30)!;
15 expect(plan.legs).toHaveLength(1);
16 expect(plan.legs[0].distance).toBe(50);
17 expect(plan.fuel).toBe(5);
18 expect(plan.jumps).toBe(0);
19});
20
21test('cross-system plan goes gate to gate', () => {
22 const plan = planTrip(graph, 'AA-1-A', 'BB-2-B', 30)!;
23 expect(plan.legs.map((l) => `${l.kind}:${l.from}>${l.to}`)).toEqual([
24 'trip:AA-1-A>AA-1-B',
25 'jump:AA-1-B>BB-2-A',
26 'trip:BB-2-A>BB-2-B'
27 ]);
28 expect(plan.jumps).toBe(1);
29 expect(plan.nebula).toBe(true);
30});
31
32test('unknown waypoints cannot be planned', () => {
33 expect(planTrip(graph, 'AA-1-A', 'ZZ-9-A', 30)).toBeNull();
34});
35
36test('same waypoint is an empty plan', () => {
37 expect(planTrip(graph, 'AA-1-A', 'AA-1-A', 30)?.legs).toEqual([]);
38});