Close door after walking through again, and add more test coverage

This commit is contained in:
Peter Stockings
2026-01-05 22:14:10 +11:00
parent b35cf5a964
commit b3954a6408
10 changed files with 445 additions and 33 deletions

View File

@@ -0,0 +1,54 @@
import { describe, it, expect } from 'vitest';
import {
TileType,
isBlocking,
isDestructible,
blocksSight,
getDestructionResult,
isDestructibleByWalk
} from '../terrain';
describe('Terrain', () => {
describe('Tile Definitions', () => {
it('should correctly identify blocking tiles', () => {
expect(isBlocking(TileType.WALL)).toBe(true);
expect(isBlocking(TileType.WALL_DECO)).toBe(true);
expect(isBlocking(TileType.WATER)).toBe(true);
expect(isBlocking(TileType.EMPTY)).toBe(false);
expect(isBlocking(TileType.GRASS)).toBe(false);
expect(isBlocking(TileType.EXIT)).toBe(false);
});
it('should correctly identify destructible tiles', () => {
expect(isDestructible(TileType.GRASS)).toBe(true);
expect(isDestructible(TileType.DOOR_CLOSED)).toBe(true);
expect(isDestructible(TileType.WALL)).toBe(false);
expect(isDestructible(TileType.EMPTY)).toBe(false);
});
it('should correctly identify tiles blocking sight', () => {
expect(blocksSight(TileType.WALL)).toBe(true);
expect(blocksSight(TileType.WALL_DECO)).toBe(true);
expect(blocksSight(TileType.DOOR_CLOSED)).toBe(true);
expect(blocksSight(TileType.GRASS)).toBe(true); // Grass blocks vision in this game logic
expect(blocksSight(TileType.EMPTY)).toBe(false);
expect(blocksSight(TileType.EXIT)).toBe(false);
});
it('should return correct destruction result', () => {
expect(getDestructionResult(TileType.GRASS)).toBe(TileType.GRASS_SAPLINGS);
expect(getDestructionResult(TileType.DOOR_CLOSED)).toBe(TileType.DOOR_OPEN);
expect(getDestructionResult(TileType.WALL)).toBeUndefined();
});
it('should correctly identify tiles destructible by walk', () => {
expect(isDestructibleByWalk(TileType.GRASS)).toBe(true);
expect(isDestructibleByWalk(TileType.DOOR_CLOSED)).toBe(true);
expect(isDestructibleByWalk(TileType.WALL)).toBe(false);
});
});
});