Skip to content

Commit cf077d8

Browse files
test(2023-01): add a check for failed answer
1 parent 42fd519 commit cf077d8

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

2023/day-01/checksum.test.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
/* eslint-env mocha */
22
const { expect } = require('chai')
33
const { checksumSet, checksumUnSanitizedSet, checksumLine, sanitizeLine } = require('./checksum')
4+
const fs = require('fs')
5+
const path = require('path')
6+
const filePath = path.join(__dirname, 'input.txt')
7+
const { inputToArray } = require('../../2018/inputParser')
48

59
describe('--- Day 1: Trebuchet?! ---', () => {
610
describe('Part 1', () => {
@@ -45,7 +49,7 @@ describe('--- Day 1: Trebuchet?! ---', () => {
4549
expect(sanitizeLine('eightwothree')).to.equal('8wo3')
4650
})
4751
})
48-
describe('checksumUnsanitizedSet', () => {
52+
describe('checksumUnSanitizedSet', () => {
4953
it('calculates the checksum for a set of lines by summing the checksum of each sanitized line', () => {
5054
const set = [
5155
'two1nine',
@@ -59,5 +63,18 @@ describe('--- Day 1: Trebuchet?! ---', () => {
5963
expect(checksumUnSanitizedSet(set)).to.equal(281)
6064
})
6165
})
66+
describe('integeration', () => {
67+
it('53853 is too low for part 2', (done) => {
68+
let data
69+
fs.readFile(filePath, { encoding: 'utf8' }, (err, initData) => {
70+
if (err) throw err
71+
initData = inputToArray(initData.trim())
72+
// Deep copy to ensure we aren't mutating the original data
73+
data = JSON.parse(JSON.stringify(initData))
74+
expect(checksumUnSanitizedSet(data)).to.be.greaterThan(53853)
75+
done()
76+
})
77+
})
78+
})
6279
})
6380
})

0 commit comments

Comments
 (0)