|
| 1 | +import { describe, it, expect, beforeEach } from 'vitest'; |
| 2 | +import { buildSolarSystemMap, SCENARIOS, findBaseHex, findBaseHexes, bodyHasGravity } from '../map-data'; |
| 3 | +import { hexKey } from '../hex'; |
| 4 | +import type { SolarSystemMap } from '../types'; |
| 5 | + |
| 6 | +let map: SolarSystemMap; |
| 7 | + |
| 8 | +beforeEach(() => { |
| 9 | + map = buildSolarSystemMap(); |
| 10 | +}); |
| 11 | + |
| 12 | +describe('buildSolarSystemMap', () => { |
| 13 | + it('produces a non-empty hex map', () => { |
| 14 | + expect(map.hexes.size).toBeGreaterThan(0); |
| 15 | + }); |
| 16 | + |
| 17 | + it('has valid bounds', () => { |
| 18 | + expect(map.bounds.minQ).toBeLessThan(map.bounds.maxQ); |
| 19 | + expect(map.bounds.minR).toBeLessThan(map.bounds.maxR); |
| 20 | + }); |
| 21 | + |
| 22 | + it('includes all expected celestial bodies', () => { |
| 23 | + const names = map.bodies.map(b => b.name); |
| 24 | + expect(names).toContain('Sol'); |
| 25 | + expect(names).toContain('Mercury'); |
| 26 | + expect(names).toContain('Venus'); |
| 27 | + expect(names).toContain('Terra'); |
| 28 | + expect(names).toContain('Luna'); |
| 29 | + expect(names).toContain('Mars'); |
| 30 | + expect(names).toContain('Ceres'); |
| 31 | + expect(names).toContain('Jupiter'); |
| 32 | + expect(names).toContain('Io'); |
| 33 | + expect(names).toContain('Callisto'); |
| 34 | + expect(names).toContain('Ganymede'); |
| 35 | + expect(names.length).toBe(11); |
| 36 | + }); |
| 37 | + |
| 38 | + it('marks Sol surface as destructive', () => { |
| 39 | + const solCenter = map.bodies.find(b => b.name === 'Sol')!.center; |
| 40 | + const hex = map.hexes.get(hexKey(solCenter))!; |
| 41 | + expect(hex.terrain).toBe('sunSurface'); |
| 42 | + expect(hex.body?.destructive).toBe(true); |
| 43 | + }); |
| 44 | + |
| 45 | + it('marks planet surfaces as non-destructive', () => { |
| 46 | + const mars = map.bodies.find(b => b.name === 'Mars')!; |
| 47 | + const hex = map.hexes.get(hexKey(mars.center))!; |
| 48 | + expect(hex.terrain).toBe('planetSurface'); |
| 49 | + expect(hex.body?.destructive).toBe(false); |
| 50 | + }); |
| 51 | + |
| 52 | + it('includes asteroid hexes', () => { |
| 53 | + const asteroids = [...map.hexes.entries()].filter(([, h]) => h.terrain === 'asteroid'); |
| 54 | + expect(asteroids.length).toBeGreaterThan(10); |
| 55 | + }); |
| 56 | +}); |
| 57 | + |
| 58 | +describe('bodyHasGravity', () => { |
| 59 | + it('returns true for bodies with gravity rings', () => { |
| 60 | + expect(bodyHasGravity('Sol', map)).toBe(true); |
| 61 | + expect(bodyHasGravity('Mercury', map)).toBe(true); |
| 62 | + expect(bodyHasGravity('Venus', map)).toBe(true); |
| 63 | + expect(bodyHasGravity('Terra', map)).toBe(true); |
| 64 | + expect(bodyHasGravity('Mars', map)).toBe(true); |
| 65 | + expect(bodyHasGravity('Jupiter', map)).toBe(true); |
| 66 | + }); |
| 67 | + |
| 68 | + it('returns true for moons with weak gravity', () => { |
| 69 | + expect(bodyHasGravity('Luna', map)).toBe(true); |
| 70 | + expect(bodyHasGravity('Io', map)).toBe(true); |
| 71 | + expect(bodyHasGravity('Callisto', map)).toBe(true); |
| 72 | + expect(bodyHasGravity('Ganymede', map)).toBe(true); |
| 73 | + }); |
| 74 | + |
| 75 | + it('returns false for Ceres (no gravity rings)', () => { |
| 76 | + expect(bodyHasGravity('Ceres', map)).toBe(false); |
| 77 | + }); |
| 78 | + |
| 79 | + it('returns false for non-existent bodies', () => { |
| 80 | + expect(bodyHasGravity('Pluto', map)).toBe(false); |
| 81 | + }); |
| 82 | +}); |
| 83 | + |
| 84 | +describe('findBaseHex / findBaseHexes', () => { |
| 85 | + it('finds bases for Mercury (2 bases)', () => { |
| 86 | + const bases = findBaseHexes(map, 'Mercury'); |
| 87 | + expect(bases.length).toBe(2); |
| 88 | + }); |
| 89 | + |
| 90 | + it('finds bases for Venus (6 bases)', () => { |
| 91 | + const bases = findBaseHexes(map, 'Venus'); |
| 92 | + expect(bases.length).toBe(6); |
| 93 | + }); |
| 94 | + |
| 95 | + it('finds bases for Terra (6 bases)', () => { |
| 96 | + const bases = findBaseHexes(map, 'Terra'); |
| 97 | + expect(bases.length).toBe(6); |
| 98 | + }); |
| 99 | + |
| 100 | + it('finds bases for Luna (6 bases)', () => { |
| 101 | + const bases = findBaseHexes(map, 'Luna'); |
| 102 | + expect(bases.length).toBe(6); |
| 103 | + }); |
| 104 | + |
| 105 | + it('finds bases for Mars (6 bases)', () => { |
| 106 | + const bases = findBaseHexes(map, 'Mars'); |
| 107 | + expect(bases.length).toBe(6); |
| 108 | + }); |
| 109 | + |
| 110 | + it('finds a single base for Ceres', () => { |
| 111 | + const bases = findBaseHexes(map, 'Ceres'); |
| 112 | + expect(bases.length).toBe(1); |
| 113 | + }); |
| 114 | + |
| 115 | + it('finds a single base for Io', () => { |
| 116 | + const bases = findBaseHexes(map, 'Io'); |
| 117 | + expect(bases.length).toBe(1); |
| 118 | + }); |
| 119 | + |
| 120 | + it('finds a single base for Callisto', () => { |
| 121 | + const bases = findBaseHexes(map, 'Callisto'); |
| 122 | + expect(bases.length).toBe(1); |
| 123 | + }); |
| 124 | + |
| 125 | + it('returns no bases for Jupiter (no base directions)', () => { |
| 126 | + const bases = findBaseHexes(map, 'Jupiter'); |
| 127 | + expect(bases.length).toBe(0); |
| 128 | + }); |
| 129 | + |
| 130 | + it('returns no bases for Ganymede (no base directions)', () => { |
| 131 | + const bases = findBaseHexes(map, 'Ganymede'); |
| 132 | + expect(bases.length).toBe(0); |
| 133 | + }); |
| 134 | + |
| 135 | + it('findBaseHex returns first base or null', () => { |
| 136 | + expect(findBaseHex(map, 'Mars')).not.toBeNull(); |
| 137 | + expect(findBaseHex(map, 'Jupiter')).toBeNull(); |
| 138 | + }); |
| 139 | + |
| 140 | + it('base hexes are on gravity rings, not surfaces', () => { |
| 141 | + for (const body of ['Venus', 'Terra', 'Mars', 'Mercury']) { |
| 142 | + const bases = findBaseHexes(map, body); |
| 143 | + for (const base of bases) { |
| 144 | + const hex = map.hexes.get(hexKey(base))!; |
| 145 | + expect(hex.terrain).not.toBe('planetSurface'); |
| 146 | + expect(hex.base).toBeDefined(); |
| 147 | + expect(hex.base!.bodyName).toBe(body); |
| 148 | + } |
| 149 | + } |
| 150 | + }); |
| 151 | +}); |
| 152 | + |
| 153 | +describe('SCENARIOS', () => { |
| 154 | + it('all scenarios have valid player definitions', () => { |
| 155 | + for (const [name, scenario] of Object.entries(SCENARIOS)) { |
| 156 | + expect(scenario.players.length).toBeGreaterThanOrEqual(2); |
| 157 | + expect(scenario.name).toBeTruthy(); |
| 158 | + expect(scenario.description).toBeTruthy(); |
| 159 | + } |
| 160 | + }); |
| 161 | + |
| 162 | + it('biplanetary has 2 corvettes with target bodies', () => { |
| 163 | + const s = SCENARIOS.biplanetary; |
| 164 | + expect(s.players[0].ships.length).toBe(1); |
| 165 | + expect(s.players[0].ships[0].type).toBe('corvette'); |
| 166 | + expect(s.players[0].targetBody).toBe('Venus'); |
| 167 | + expect(s.players[1].ships.length).toBe(1); |
| 168 | + expect(s.players[1].ships[0].type).toBe('corvette'); |
| 169 | + expect(s.players[1].targetBody).toBe('Mars'); |
| 170 | + }); |
| 171 | + |
| 172 | + it('escape has 3 transports vs 2 enforcers', () => { |
| 173 | + const s = SCENARIOS.escape; |
| 174 | + expect(s.players[0].ships.length).toBe(3); |
| 175 | + expect(s.players[0].ships.every(sh => sh.type === 'transport')).toBe(true); |
| 176 | + expect(s.players[0].escapeWins).toBe(true); |
| 177 | + expect(s.players[1].ships.length).toBe(2); |
| 178 | + expect(s.rules?.hiddenIdentityInspection).toBe(true); |
| 179 | + expect(s.rules?.escapeEdge).toBe('north'); |
| 180 | + }); |
| 181 | + |
| 182 | + it('fleet-building scenarios have startingCredits and empty ship lists', () => { |
| 183 | + for (const name of ['interplanetaryWar', 'fleetAction']) { |
| 184 | + const s = SCENARIOS[name]; |
| 185 | + expect(s.startingCredits).toBeDefined(); |
| 186 | + expect(s.availableShipTypes).toBeDefined(); |
| 187 | + expect(s.availableShipTypes!.length).toBeGreaterThan(0); |
| 188 | + for (const p of s.players) { |
| 189 | + expect(p.ships.length).toBe(0); |
| 190 | + } |
| 191 | + } |
| 192 | + }); |
| 193 | + |
| 194 | + it('convoy has a tanker with frigate escort', () => { |
| 195 | + const s = SCENARIOS.convoy; |
| 196 | + const shipTypes = s.players[0].ships.map(sh => sh.type); |
| 197 | + expect(shipTypes).toContain('tanker'); |
| 198 | + expect(shipTypes).toContain('frigate'); |
| 199 | + }); |
| 200 | +}); |
0 commit comments