This commit is contained in:
Scott Anderson
2025-08-24 21:32:32 -04:00
parent eaefecb00f
commit 809d60ff58
95 changed files with 1385 additions and 1424 deletions
+1 -1
View File
@@ -2,9 +2,9 @@ import { Cluster, TrainStation } from "../../../src/core/game/TrainStation";
const createMockStation = (id: string): jest.Mocked<TrainStation> => {
return {
getCluster: jest.fn(() => null),
id,
setCluster: jest.fn(),
getCluster: jest.fn(() => null),
} as any;
};
+1 -1
View File
@@ -21,8 +21,8 @@ describe("GameImpl", () => {
beforeEach(async () => {
game = await setup("ocean_and_land", {
infiniteGold: true,
instantBuild: true,
infiniteTroops: true,
instantBuild: true,
});
const attackerInfo = new PlayerInfo(
"attacker dude",
+12 -12
View File
@@ -11,17 +11,17 @@ const createMockStation = (unitId: number): any => {
const cluster = new Cluster();
const railroads = new Set<Railroad>();
return {
addRailroad: jest.fn(),
clearRailroads: jest.fn(),
getCluster: jest.fn(() => cluster),
getRailroads: jest.fn(() => railroads),
neighbors: jest.fn(() => []),
setCluster: jest.fn(),
tile: jest.fn(),
unit: {
id: unitId,
setTrainStation: jest.fn(),
},
tile: jest.fn(),
neighbors: jest.fn(() => []),
getCluster: jest.fn(() => cluster),
setCluster: jest.fn(),
addRailroad: jest.fn(),
getRailroads: jest.fn(() => railroads),
clearRailroads: jest.fn(),
};
};
@@ -55,22 +55,22 @@ describe("RailNetworkImpl", () => {
beforeEach(() => {
stationManager = {
addStation: jest.fn(),
removeStation: jest.fn(),
findStation: jest.fn(),
getAll: jest.fn(() => new Set()),
removeStation: jest.fn(),
};
pathService = {
findTilePath: jest.fn(() => [0]),
findStationsPath: jest.fn(() => [0]),
findTilePath: jest.fn(() => [0]),
};
game = {
nearbyUnits: jest.fn(() => []),
addExecution: jest.fn(),
config: () => ({
railroadMaxSize: () => 100,
trainStationMaxRange: () => 80,
trainStationMinRange: () => 10,
railroadMaxSize: () => 100,
}),
nearbyUnits: jest.fn(() => []),
};
network = new RailNetworkImpl(game, stationManager, pathService);
@@ -153,7 +153,7 @@ describe("RailNetworkImpl", () => {
neighborStation.getCluster = jest.fn(() => cluster);
cluster.has = jest.fn(() => false);
const neighborUnit = { unit: neighborStation.unit, distSquared: 20 };
const neighborUnit = { distSquared: 20, unit: neighborStation.unit };
game.nearbyUnits.mockReturnValue([neighborUnit]);
stationManager.findStation.mockReturnValue(neighborStation);
+9 -9
View File
@@ -14,34 +14,34 @@ describe("TrainStation", () => {
beforeEach(() => {
game = {
ticks: jest.fn().mockReturnValue(123),
addExecution: jest.fn(),
addUpdate: jest.fn(),
config: jest.fn().mockReturnValue({
trainGold: (isFriendly: boolean) =>
isFriendly ? BigInt(1000) : BigInt(500),
}),
addUpdate: jest.fn(),
addExecution: jest.fn(),
ticks: jest.fn().mockReturnValue(123),
} as any;
player = {
addGold: jest.fn(),
id: 1,
canTrade: jest.fn().mockReturnValue(true),
id: 1,
isFriendly: jest.fn().mockReturnValue(false),
} as any;
unit = {
owner: jest.fn().mockReturnValue(player),
isActive: jest.fn().mockReturnValue(true),
level: jest.fn().mockReturnValue(1),
owner: jest.fn().mockReturnValue(player),
tile: jest.fn().mockReturnValue({ x: 0, y: 0 }),
type: jest.fn(),
isActive: jest.fn().mockReturnValue(true),
} as any;
trainExecution = {
level: jest.fn(),
loadCargo: jest.fn(),
owner: jest.fn().mockReturnValue(player),
level: jest.fn(),
} as any;
});
@@ -82,7 +82,7 @@ describe("TrainStation", () => {
it("adds and retrieves neighbors", () => {
const stationA = new TrainStation(game, unit);
const stationB = new TrainStation(game, unit);
const railRoad = { from: stationA, to: stationB, tiles: [] } as any;
const railRoad = { from: stationA, tiles: [], to: stationB } as any;
stationA.addRailroad(railRoad);
@@ -96,8 +96,8 @@ describe("TrainStation", () => {
const railRoad = {
from: stationA,
to: stationB,
tiles: [{ x: 1, y: 1 }],
to: stationB,
} as any;
stationA.addRailroad(railRoad);