import { assertEquals } from "https://deno.land/std@0.212.0/assert/mod.ts";
import { MinHeap, nextCrucibleStates, nextUltraCrucibleStates, Coord, Dir } from "./solver.ts";

Deno.test("MinHeap", () => {
    const minHeap = new MinHeap<number>((a, b) => a - b);
    minHeap.add(1);
    minHeap.add(3);
    minHeap.add(2);
    
    assertEquals([minHeap.pop(), minHeap.pop() , minHeap.pop()], [1, 2, 3]);
});

Deno.test("MinHeap2", () => {
    const minHeap = new MinHeap<number>((a, b) => a - b);
    minHeap.add(2);
    minHeap.add(3);
    minHeap.add(4);
    minHeap.add(5);
    minHeap.add(1);
    
    assertEquals([minHeap.pop(), minHeap.pop() , minHeap.pop()], [1, 2, 3]);
});

Deno.test("nextStates", () => {
    const pos = [1, 1] as Coord;
    const prevDir = "down" as Dir;
    const step = 1;

    const ret = nextCrucibleStates(pos, prevDir, step);

    assertEquals(ret, [
        { pos: [0, 1], prevDir: "left", dist: 1 },
        { pos: [2, 1], prevDir: "right", dist: 1 },
        { pos: [1, 2], prevDir: "down", dist: 2 },
    ]);

    assertEquals(
        nextCrucibleStates([3, 1], "left", 3),
        [
            { pos: [3, 0], prevDir: "up", dist: 1 },
            { pos: [3, 2], prevDir: "down", dist: 1 },
        ]
    )
});

Deno.test("nextUltraCrucibleStates", () => {
    assertEquals(
        nextUltraCrucibleStates([1, 1], "right", 1),
        [
            { pos: [2, 1], prevDir: "right", dist: 2 },
        ]
    );
    assertEquals(
        nextUltraCrucibleStates([2, 1], "right", 2),
        [
            { pos: [3, 1], prevDir: "right", dist: 3 },
        ]
    );
    assertEquals(
        nextUltraCrucibleStates([3, 1], "right", 3),
        [
            { pos: [4, 1], prevDir: "right", dist: 4 },
        ]
    );
    assertEquals(
        nextUltraCrucibleStates([4, 1], "right", 4),
        [
            { pos: [5, 1], prevDir: "right", dist: 5 },
        ]
    );
    assertEquals(
        nextUltraCrucibleStates([5, 1], "right", 5),
        [
            { pos: [6, 1], prevDir: "right", dist: 6 },
            { pos: [5, 0], prevDir: "up", dist: 1 },
            { pos: [5, 2], prevDir: "down", dist: 1 },
        ]
    );
});