Files
Battle-for-Tismo/tests/terrain_stats_test.js
T
adrien e7ee5dbf0e Added the resource economy, its works and their icons
- Five resources (energy, steel, food, luxury, high-tech) with per-city stores, a world market, delivery and material upkeep.
- Resource-producing tile works built outside cities; every nation opens with the works its economy needs.
- Real game-icons.net art replacing the dummy icons for the new resources and works, with the credits updated.
2026-09-22 05:27:11 +02:00

58 lines
2.4 KiB
JavaScript

import { TestCase } from "./framework/test_case.js";
import { TerrainStats, DEFAULT_MOVEMENT_COST_MULTIPLIER } from "../shared/terrain_stats.js";
import { TERRAIN_TILES } from "../shared/data.js";
export class TerrainStatsTest extends TestCase {
test_authored_values_are_read() {
const stats = new TerrainStats({
"0,0": { populationMultiplier: 0.3, productionMultiplier: 0.5, movementCostMultiplier: 1.5 },
});
this.assertApprox(stats.populationMultiplier({ x: 0, y: 0 }), 0.3);
this.assertApprox(stats.productionMultiplier({ x: 0, y: 0 }), 0.5);
this.assertApprox(stats.movementCostMultiplier({ x: 0, y: 0 }), 1.5);
}
test_unset_values_fall_back() {
const stats = new TerrainStats({ "0,0": {} });
this.assertApprox(stats.populationMultiplier({ x: 0, y: 0 }), 0.0);
this.assertApprox(stats.productionMultiplier({ x: 0, y: 0 }), 0.0);
this.assertApprox(stats.movementCostMultiplier({ x: 0, y: 0 }), DEFAULT_MOVEMENT_COST_MULTIPLIER);
}
test_zero_movement_cost_means_normal() {
const stats = new TerrainStats({ "0,0": { movementCostMultiplier: 0 } });
this.assertApprox(stats.movementCostMultiplier({ x: 0, y: 0 }), DEFAULT_MOVEMENT_COST_MULTIPLIER);
}
test_missing_tile_returns_defaults() {
const stats = new TerrainStats({ "0,0": {} });
this.assertApprox(stats.populationMultiplier({ x: 9, y: 9 }), 0.0);
this.assertApprox(stats.movementCostMultiplier({ x: 9, y: 9 }), DEFAULT_MOVEMENT_COST_MULTIPLIER);
}
test_min_movement_cost_picks_cheapest_used_tile() {
const stats = new TerrainStats({
"0,0": { movementCostMultiplier: 2.0 },
"1,0": { movementCostMultiplier: 0.5 },
"2,0": {},
});
this.assertApprox(stats.minMovementCostMultiplier(), 0.5);
}
test_min_movement_cost_without_tiles_is_default() {
this.assertApprox(new TerrainStats({}).minMovementCostMultiplier(), DEFAULT_MOVEMENT_COST_MULTIPLIER);
}
test_catalogue_exposes_terrain_multipliers() {
const land = TERRAIN_TILES.filter((t) => t.terrainClass === "Land");
this.assertNotEmpty(land);
for (const tile of land) {
this.assertHas(tile, "populationMultiplier");
this.assertHas(tile, "productionMultiplier");
this.assertHas(tile, "movementCostMultiplier");
}
const cheapest = Math.min(...TERRAIN_TILES.map((t) => t.movementCostMultiplier || DEFAULT_MOVEMENT_COST_MULTIPLIER));
this.assertGreaterOrEqual(cheapest, 0);
}
}