-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add script to create new day files with templates for solution …
…and tests
- Loading branch information
1 parent
451b121
commit 34c3059
Showing
3 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { promises as fs } from "fs"; | ||
import path from "path"; | ||
|
||
const createNewDay = async (day: number) => { | ||
const dayString = day.toString().padStart(2, "0"); | ||
const inputPath = `./inputs/${dayString}.txt`; | ||
const solutionPath = `./src/${dayString}.ts`; | ||
const testPath = `./test/${dayString}.test.ts`; | ||
|
||
const templateDayPath = path.resolve(__dirname, "./template/day.txt"); | ||
const templateDayContent = await fs.readFile(templateDayPath, "utf-8"); | ||
await fs.writeFile(solutionPath, templateDayContent); | ||
|
||
const templateTestPath = path.resolve(__dirname, "./template/test.txt"); | ||
const templateTestContent = await fs.readFile(templateTestPath, "utf-8"); | ||
const updatedTestContent = templateTestContent.replace(/{{day}}/g, dayString); | ||
await fs.writeFile(testPath, updatedTestContent); | ||
|
||
await fs.writeFile(inputPath, ""); | ||
}; | ||
|
||
const dayArg = process.argv[2]; | ||
if (!dayArg) { | ||
console.error("Please provide a day number as an argument."); | ||
process.exit(1); | ||
} | ||
|
||
const day = parseInt(dayArg, 10); | ||
if (isNaN(day) || day < 1 || day > 25) { | ||
console.error("Please provide a valid day number between 1 and 25."); | ||
process.exit(1); | ||
} | ||
|
||
createNewDay(day); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
function solution(input: string): { part1: string; part2: string } { | ||
let result1 = 0; | ||
let result2 = 0; | ||
|
||
const lines = input.split("\n"); | ||
|
||
return { | ||
part1: result1.toString(), | ||
part2: result2.toString(), | ||
}; | ||
} | ||
|
||
export default solution; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { expect, test, describe } from "bun:test"; | ||
import solution from "../src/{{day}}"; | ||
|
||
const EXAMPLE_1 = `1 2 3 4`; | ||
const RESULT_1 = "2"; | ||
|
||
const EXAMPLE_2 = EXAMPLE_1; | ||
const RESULT_2 = "31"; | ||
|
||
describe("Day 2", () => { | ||
test("Part 1", () => { | ||
const result = solution(EXAMPLE_1); | ||
expect(result.part1).toBe(RESULT_1); | ||
}); | ||
|
||
test.skip("Part 2", () => { | ||
const result = solution(EXAMPLE_2); | ||
expect(result.part2).toBe(RESULT_2); | ||
}); | ||
}); |