Skip to content

Commit e569b1e

Browse files
committed
test(2022): add tests for javascript solutions
1 parent af57c8c commit e569b1e

File tree

7 files changed

+1357
-13
lines changed

7 files changed

+1357
-13
lines changed

.github/workflows/run_tests.yml

+23
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,29 @@ on:
66
- master
77

88
jobs:
9+
javascript:
10+
name: Test JavaScript solutions
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
year: ['2022']
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v3
19+
- name: Setup Node
20+
uses: actions/setup-node@v3
21+
with:
22+
node-version: 18
23+
- name: Run tests
24+
run: |
25+
cd javascript/$YEAR
26+
npm ci
27+
npm test
28+
env:
29+
YEAR: ${{ matrix.year }}
30+
CI: true
31+
932
rescript:
1033
name: Test ReScript solutions
1134
runs-on: ubuntu-latest
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { vi, expect, test } from 'vitest'
2+
import { part1, part2 } from '../day01.mjs'
3+
4+
test('part 1', () => {
5+
expect(part1).toEqual(69528)
6+
})
7+
8+
test('part 2', () => {
9+
expect(part2).toEqual(206152)
10+
})
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { vi, expect, test } from 'vitest'
2+
import { part1, part2 } from '../day02.mjs'
3+
4+
test('part 1', () => {
5+
expect(part1).toEqual(13809)
6+
})
7+
8+
test('part 2', () => {
9+
expect(part2).toEqual(12316)
10+
})

javascript/2022/day01.mjs

+2-5
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,5 @@ const parsedInput = input
1818
.slice()
1919
.sort(sortDESC)
2020

21-
const part1 = parsedInput.at(0)
22-
const part2 = parsedInput.slice(0, 3).reduce(sum, 0)
23-
24-
console.log('Part 1:', part1)
25-
console.log('Part 2:', part2)
21+
export const part1 = parsedInput.at(0)
22+
export const part2 = parsedInput.slice(0, 3).reduce(sum, 0)

javascript/2022/day02.mjs

+2-5
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const outcome = {
4040
Z: 'win',
4141
}
4242

43-
const part1 = pipe(
43+
export const part1 = pipe(
4444
map(([p1, p2]) => [player1[p1], player2[p2]]),
4545
map(([p1, p2]) => {
4646
if (p1 === p2) return scores.draw + scores[p2]
@@ -54,7 +54,7 @@ const part1 = pipe(
5454
reduce(add, 0)
5555
)(parsedInput)
5656

57-
const part2 = pipe(
57+
export const part2 = pipe(
5858
map(([p1, p2]) => [player1[p1], outcome[p2]]),
5959
map(([p1, p2]) => {
6060
if (p1 === 'rock' && p2 === 'loss') return scores.loss + scores.scissors
@@ -69,6 +69,3 @@ const part2 = pipe(
6969
}),
7070
reduce(add, 0)
7171
)(parsedInput)
72-
73-
console.log('Part 1:', part1)
74-
console.log('Part 2:', part2)

0 commit comments

Comments
 (0)