Skip to content

Commit

Permalink
Fix simple simulator tests
Browse files Browse the repository at this point in the history
  • Loading branch information
delasy committed Nov 4, 2024
1 parent 0c2b440 commit 3d9e6b6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
8 changes: 5 additions & 3 deletions simulator/ZombieSurvival.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test("fails on invalid map", () => {
[" ", " ", " ", " ", " ", " ", " ", " ", " ", " "],
[" ", " ", " ", " ", " ", " ", " ", " ", " ", " "],
]),
).toThrowError("Map has no player");
).toThrowError("Single player map has no player");

expect(
() =>
Expand All @@ -33,7 +33,7 @@ test("fails on invalid map", () => {
[" ", " ", " ", " ", " ", " ", " ", " ", " ", " "],
[" ", " ", " ", " ", " ", " ", " ", " ", " ", " "],
]),
).toThrowError("Map contains multiple players");
).toThrowError("Single player map contains multiple players");

expect(
() =>
Expand Down Expand Up @@ -64,7 +64,9 @@ test("fails on impossible to beat map", () => {
[" ", " ", " ", " ", " ", " ", " ", " ", " ", " "],
]);

expect(() => game.step()).toThrowError("Unable to solve game");
expect(() => game.step()).toThrowError(
"Unable to find path for the next move",
);
});

test("works with different boards sizes", () => {
Expand Down
6 changes: 3 additions & 3 deletions simulator/ZombieSurvival.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { entityAt } from "../lib/entityAt";
import { allDirections, move } from "./Direction";
import { type Entity } from "./Entity";
import { type Position } from "./Position";
Expand All @@ -6,7 +7,6 @@ import { Landmine } from "./entities/Landmine";
import { Player } from "./entities/Player";
import { Rock } from "./entities/Rock";
import { Zombie } from "./entities/Zombie";
import { entityAt } from "@/lib/entityAt";

export interface ZombieSurvivalOptions {
multiplayer?: boolean;
Expand All @@ -32,9 +32,9 @@ export class ZombieSurvival {

for (let y = 0; y < this.boardHeight; y++) {
for (let x = 0; x < this.boardWidth; x++) {
const code = map[y][x].toLowerCase();
const code = map[y][x];

switch (code) {
switch (code.toLowerCase()) {
case "b": {
this.entities.push(new Box({ x, y }));
break;
Expand Down
2 changes: 1 addition & 1 deletion simulator/entities/Player.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { closestEntity } from "../../lib/closestEntity";
import { Entity, EntityType } from "../Entity";
import { type Position } from "../Position";
import { type ZombieSurvival } from "../ZombieSurvival";
import { closestEntity } from "@/lib/closestEntity";

export class Player extends Entity {
public static Destructible = true;
Expand Down
2 changes: 1 addition & 1 deletion simulator/entities/Zombie.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { entityAt } from "../../lib/entityAt";
import { type Direction, allDirections, move } from "../Direction";
import { Entity, EntityType } from "../Entity";
import { type Position } from "../Position";
import { type ZombieSurvival } from "../ZombieSurvival";
import { entityAt } from "@/lib/entityAt";

export class Zombie extends Entity {
public static Destructible = true;
Expand Down

0 comments on commit 3d9e6b6

Please sign in to comment.