🚿 refactor + clean up
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { realistic as grid } from "../__fixtures__/grid";
|
||||
import { snake3 } from "../__fixtures__/snake";
|
||||
import { realistic as grid } from "@snk/types/__fixtures__/grid";
|
||||
import { snake3 } from "@snk/types/__fixtures__/snake";
|
||||
import { performance } from "perf_hooks";
|
||||
import { getAvailableRoutes } from "../getAvailableRoutes";
|
||||
import { getBestRoute } from "../getBestRoute";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { getBestRoute } from "../getBestRoute";
|
||||
import { Color, createEmptyGrid, setColor } from "../grid";
|
||||
import { createSnake, snakeToCells } from "../snake";
|
||||
import { Color, createEmptyGrid, setColor } from "@snk/types/grid";
|
||||
import { createSnakeFromCells, snakeToCells } from "@snk/types/snake";
|
||||
|
||||
it("should find best route", () => {
|
||||
const snk0 = [
|
||||
@@ -11,7 +11,7 @@ it("should find best route", () => {
|
||||
const grid = createEmptyGrid(5, 5);
|
||||
setColor(grid, 3, 3, 1 as Color);
|
||||
|
||||
const chain = getBestRoute(grid, createSnake(snk0))!;
|
||||
const chain = getBestRoute(grid, createSnakeFromCells(snk0))!;
|
||||
|
||||
expect(snakeToCells(chain[0])[1]).toEqual({ x: 0, y: 0 });
|
||||
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
import { createEmptyGrid, setColor, getColor, isInside, Color } from "../grid";
|
||||
|
||||
it("should set / get cell", () => {
|
||||
const grid = createEmptyGrid(2, 3);
|
||||
|
||||
expect(getColor(grid, 0, 1)).toBe(0);
|
||||
|
||||
setColor(grid, 0, 1, 1 as Color);
|
||||
|
||||
expect(getColor(grid, 0, 1)).toBe(1);
|
||||
});
|
||||
|
||||
test.each([
|
||||
[0, 1, true],
|
||||
[1, 2, true],
|
||||
|
||||
[-1, 1, false],
|
||||
[0, -1, false],
|
||||
[2, 1, false],
|
||||
[0, 3, false],
|
||||
])("isInside", (x, y, output) => {
|
||||
const grid = createEmptyGrid(2, 3);
|
||||
|
||||
expect(isInside(grid, x, y)).toBe(output);
|
||||
});
|
||||
@@ -1,43 +0,0 @@
|
||||
import {
|
||||
createSnake,
|
||||
nextSnake,
|
||||
snakeToCells,
|
||||
snakeWillSelfCollide,
|
||||
} from "../snake";
|
||||
|
||||
it("should convert to point", () => {
|
||||
const snk0 = [
|
||||
{ x: 1, y: -1 },
|
||||
{ x: 1, y: 0 },
|
||||
{ x: 0, y: 0 },
|
||||
];
|
||||
|
||||
expect(snakeToCells(createSnake(snk0))).toEqual(snk0);
|
||||
});
|
||||
|
||||
it("should return next snake", () => {
|
||||
const snk0 = [
|
||||
{ x: 1, y: 1 },
|
||||
{ x: 1, y: 0 },
|
||||
{ x: 0, y: 0 },
|
||||
];
|
||||
|
||||
const snk1 = [
|
||||
{ x: 2, y: 1 },
|
||||
{ x: 1, y: 1 },
|
||||
{ x: 1, y: 0 },
|
||||
];
|
||||
|
||||
expect(snakeToCells(nextSnake(createSnake(snk0), 1, 0))).toEqual(snk1);
|
||||
});
|
||||
|
||||
it("should test snake collision", () => {
|
||||
const snk0 = [
|
||||
{ x: 1, y: 1 },
|
||||
{ x: 1, y: 0 },
|
||||
{ x: 0, y: 0 },
|
||||
];
|
||||
|
||||
expect(snakeWillSelfCollide(createSnake(snk0), 1, 0)).toBe(false);
|
||||
expect(snakeWillSelfCollide(createSnake(snk0), 0, -1)).toBe(true);
|
||||
});
|
||||
Reference in New Issue
Block a user