import { Cell, getBitsNumbers, getReflectionIndex, correctReflection, popcount } from "./solver.ts"; import { assertEquals } from "https://deno.land/std@0.212.0/assert/mod.ts"; Deno.test("getBitsNumbers", () => { const cells = ["#", ".", "#", ".", "#", "#"] as Cell[]; const ret = getBitsNumbers(cells); assertEquals(ret, 0b101011); }); Deno.test("getBitsNumbers long line", () => { const maxLength = 30; const cells = new Array(maxLength).fill("#") as Cell[]; const ret = getBitsNumbers(cells); assertEquals(ret, Math.pow(2, maxLength) - 1); }); Deno.test("getReflectionIndex", () => { const arr = [1, 2, 3, 4, 4, 3]; const ret = getReflectionIndex(arr); assertEquals(ret, 4); }); Deno.test("correctReflection", () => { const arr = [0b000, 0b111, 0b110]; const ret = correctReflection(arr); assertEquals(ret, 2); }); Deno.test("popcount", () => { const arr = [0b000, 0b111, 0b110, 0b11101, 0b11110, 0b11111]; const ret = arr.map(x => popcount(x)); assertEquals(ret, [0, 3, 2, 4,4, 5]); })