Close door after walking through again, and add more test coverage
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { idx, inBounds, isWall, isBlocked } from '../world/world-logic';
|
||||
import { idx, inBounds, isWall, isBlocked, tryDestructTile, isPlayerOnExit } from '../world/world-logic';
|
||||
import { type World, type Tile } from '../../core/types';
|
||||
import { TileType } from '../../core/terrain';
|
||||
|
||||
@@ -114,4 +114,65 @@ describe('World Utilities', () => {
|
||||
expect(isBlocked(world, 10, 10)).toBe(true);
|
||||
});
|
||||
});
|
||||
describe('tryDestructTile', () => {
|
||||
it('should destruct a destructible tile', () => {
|
||||
const tiles = new Array(100).fill(TileType.EMPTY);
|
||||
tiles[0] = TileType.GRASS;
|
||||
const world = createTestWorld(10, 10, tiles);
|
||||
|
||||
const result = tryDestructTile(world, 0, 0);
|
||||
|
||||
expect(result).toBe(true);
|
||||
expect(world.tiles[0]).toBe(TileType.GRASS_SAPLINGS);
|
||||
});
|
||||
|
||||
it('should not destruct a non-destructible tile', () => {
|
||||
const tiles = new Array(100).fill(TileType.EMPTY);
|
||||
tiles[0] = TileType.WALL;
|
||||
const world = createTestWorld(10, 10, tiles);
|
||||
|
||||
const result = tryDestructTile(world, 0, 0);
|
||||
|
||||
expect(result).toBe(false);
|
||||
expect(world.tiles[0]).toBe(TileType.WALL);
|
||||
});
|
||||
|
||||
it('should return false for out of bounds', () => {
|
||||
const world = createTestWorld(10, 10, new Array(100).fill(TileType.EMPTY));
|
||||
expect(tryDestructTile(world, -1, 0)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isPlayerOnExit', () => {
|
||||
it('should return true when player is on exit', () => {
|
||||
const world = createTestWorld(10, 10, new Array(100).fill(TileType.EMPTY));
|
||||
world.exit = { x: 5, y: 5 };
|
||||
world.actors.set(1, {
|
||||
id: 1,
|
||||
pos: { x: 5, y: 5 },
|
||||
isPlayer: true
|
||||
} as any);
|
||||
|
||||
expect(isPlayerOnExit(world, 1)).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false when player is not on exit', () => {
|
||||
const world = createTestWorld(10, 10, new Array(100).fill(TileType.EMPTY));
|
||||
world.exit = { x: 5, y: 5 };
|
||||
world.actors.set(1, {
|
||||
id: 1,
|
||||
pos: { x: 4, y: 4 },
|
||||
isPlayer: true
|
||||
} as any);
|
||||
|
||||
expect(isPlayerOnExit(world, 1)).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false when player does not exist', () => {
|
||||
const world = createTestWorld(10, 10, new Array(100).fill(TileType.EMPTY));
|
||||
world.exit = { x: 5, y: 5 };
|
||||
|
||||
expect(isPlayerOnExit(world, 999)).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user