Close door after walking through again, and add more test coverage
This commit is contained in:
54
src/core/__tests__/terrain.test.ts
Normal file
54
src/core/__tests__/terrain.test.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user