From 0bbe734fbcf53cb0ce0bd3f0d9d7a0e4f4e24a91 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Wed, 1 Dec 2021 11:48:34 -0600 Subject: [PATCH] Add test --- 2021/1.test.ts | 24 ++++++++++++++++++++++++ 2021/common.ts | 8 ++++++++ 2 files changed, 32 insertions(+) create mode 100644 2021/1.test.ts diff --git a/2021/1.test.ts b/2021/1.test.ts new file mode 100644 index 0000000..ad6f0b2 --- /dev/null +++ b/2021/1.test.ts @@ -0,0 +1,24 @@ +import { assertEquals } from "https://deno.land/std@0.116.0/testing/asserts.ts"; +import { asyncIterator } from "./common.ts"; +import { part1, part2 } from "./1.ts"; + +const testInput = [ + 199, + 200, + 208, + 210, + 200, + 207, + 240, + 269, + 260, + 263, +]; + +Deno.test("day 1 part 1", async () => { + assertEquals(await part1(asyncIterator(testInput)), 7); +}); + +Deno.test("day 1 part 2", async () => { + assertEquals(await part2(asyncIterator(testInput)), 5); +}); diff --git a/2021/common.ts b/2021/common.ts index f7bae03..274f5f7 100644 --- a/2021/common.ts +++ b/2021/common.ts @@ -76,3 +76,11 @@ export async function inputNumbers( ): Promise> { return readStringsAsNumbers(await inputLines(day)); } + +export async function* asyncIterator( + array: T[], +): AsyncIterableIterator { + for (const v of array) { + yield v; + } +}