Skip to content

Commit

Permalink
test: node:test
Browse files Browse the repository at this point in the history
Migrate from `vitest` to `node:test`
  • Loading branch information
marcobiedermann committed Nov 29, 2024
1 parent b91a99c commit 3e30206
Show file tree
Hide file tree
Showing 56 changed files with 439 additions and 2,312 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v22
v23
35 changes: 18 additions & 17 deletions 2015/day/1/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
import { describe, expect, it } from 'vitest';
import { part1, part2 } from '.';
import { getInput } from '../../../utils/file';
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { getInput } from '../../../utils/file.ts';
import { part1, part2 } from './index.ts';

const input = await getInput(__dirname);
const input = await getInput(import.meta.dirname);

describe('2015', () => {
describe('Day 1', () => {
describe('Part 1', () => {
it('should return floor number', () => {
expect(part1('(())')).toBe(0);
expect(part1('()()')).toBe(0);
expect(part1('(((')).toBe(3);
expect(part1('(()(()(')).toBe(3);
expect(part1('))(((((')).toBe(3);
expect(part1('())')).toBe(-1);
expect(part1('))(')).toBe(-1);
expect(part1(')))')).toBe(-3);
expect(part1(')())())')).toBe(-3);
expect(part1(input)).toBe(280);
assert.strictEqual(part1('(())'), 0);
assert.strictEqual(part1('()()'), 0);
assert.strictEqual(part1('((('), 3);
assert.strictEqual(part1('(()(()('), 3);
assert.strictEqual(part1('))((((('), 3);
assert.strictEqual(part1('())'), -1);
assert.strictEqual(part1('))('), -1);
assert.strictEqual(part1(')))'), -3);
assert.strictEqual(part1(')())())'), -3);
assert.strictEqual(part1(input), 280);
});
});

describe('Part 2', () => {
it('should return index of the first character to enter the basement', () => {
expect(part2(')')).toBe(1);
expect(part2('()())')).toBe(5);
expect(part2(input)).toBe(1797);
assert.strictEqual(part2(')'), 1);
assert.strictEqual(part2('()())'), 5);
assert.strictEqual(part2(input), 1797);
});
});
});
Expand Down
13 changes: 5 additions & 8 deletions 2015/day/10/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import { describe, expect, it } from 'vitest';
import { part1, part2 } from '.';
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { part1, part2 } from './index.ts';

const input = '1113122113';

describe('Day 10', () => {
describe('Part 1', () => {
it('should process 40 iterations', () => {
expect.assertions(1);

expect(part1(input)).toStrictEqual(360154);
assert.strictEqual(part1(input), 360154);
});
});

describe('Part 2', () => {
it('should process 50 iterations', () => {
expect.assertions(1);

expect(part2(input)).toStrictEqual(5103798);
assert.strictEqual(part2(input), 5103798);
});
});
});
11 changes: 5 additions & 6 deletions 2015/day/12/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import { describe, expect, it } from 'vitest';
import { part1 } from '.';
import { describe, it } from 'node:test';
import { part1 } from './index.ts';

const input = await readFile(`${__dirname}/input`, 'utf-8');
const input = await readFile(`${import.meta.dirname}/input`, 'utf-8');

describe('Day 12', () => {
describe('Part 1', () => {
it('should sum up app numbers in JSON object', () => {
expect.assertions(1);

expect(part1(input)).toStrictEqual(119433);
assert.strictEqual(part1(input), 119433);
});
});
});
11 changes: 5 additions & 6 deletions 2015/day/14/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import { describe, expect, it } from 'vitest';
import { part1 } from '.';
import { describe, it } from 'node:test';
import { part1 } from './index.ts';

const input = (await readFile(`${__dirname}/input`, 'utf-8')).split('\n');
const input = (await readFile(`${import.meta.dirname}/input`, 'utf-8')).split('\n');

describe('Day 14', () => {
describe('Part 1', () => {
it('should return the max distance', () => {
expect.assertions(1);

expect(part1(input)).toStrictEqual(2660);
assert.strictEqual(part1(input), 2660);
});
});
});
9 changes: 4 additions & 5 deletions 2015/day/15/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { describe, expect, it } from 'vitest';
import { part1 } from '.';
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { part1 } from './index.ts';

describe('Day 15', () => {
describe('Part 1', () => {
it('should', () => {
expect.assertions(1);

expect(part1()).toStrictEqual(0);
assert.strictEqual(part1(), 0);
});
});
});
11 changes: 5 additions & 6 deletions 2015/day/16/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import { describe, expect, it } from 'vitest';
import { part1 } from '.';
import { describe, it } from 'node:test';
import { part1 } from './index.ts';

const input = (await readFile(`${__dirname}/input`, 'utf-8')).split('\n');
const input = (await readFile(`${import.meta.dirname}/input`, 'utf-8')).split('\n');

describe('Day 16', () => {
describe('Part 1', () => {
it('should find the number of the Sue that got you the gift ', () => {
expect.assertions(1);

expect(part1(input)).toStrictEqual(373);
assert.strictEqual(part1(input), 373);
});
});
});
23 changes: 12 additions & 11 deletions 2015/day/2/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import { describe, expect, it } from 'vitest';
import { part1, part2 } from '.';
import { getInput } from '../../../utils/file';
import { NEWLINE } from '../../../utils/string';
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { getInput } from '../../../utils/file.ts';
import { NEWLINE } from '../../../utils/string.ts';
import { part1, part2 } from './index.ts';

const input = (await getInput(__dirname)).split(NEWLINE);
const input = (await getInput(import.meta.dirname)).split(NEWLINE);

describe('2015', () => {
describe('Day 1', () => {
describe('Part 1', () => {
it('should return total square feet of wrapping paper', () => {
expect(part1(['2x3x4'])).toBe(58);
expect(part1(['1x1x10'])).toBe(43);
expect(part1(input)).toBe(1598415);
assert.strictEqual(part1(['2x3x4']), 58);
assert.strictEqual(part1(['1x1x10']), 43);
assert.strictEqual(part1(input), 1598415);
});
});

describe('Part 2', () => {
it('should return total feet of ribbon', () => {
expect(part2(['2x3x4'])).toBe(34);
expect(part2(['1x1x10'])).toBe(14);
expect(part2(input)).toBe(3812909);
assert.strictEqual(part2(['2x3x4']), 34);
assert.strictEqual(part2(['1x1x10']), 14);
assert.strictEqual(part2(input), 3812909);
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion 2015/day/2/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RADIX, sum } from '../../../utils/math';
import { RADIX, sum } from '../../../utils/math.ts';

function getArea(length: number, width: number): number {
return length * width;
Expand Down
25 changes: 13 additions & 12 deletions 2015/day/3/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import { describe, expect, it } from 'vitest';
import { part1, part2 } from '.';
import { getInput } from '../../../utils/file';
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { getInput } from '../../../utils/file.ts';
import { part1, part2 } from './index.ts';

const input = await getInput(__dirname);
const input = await getInput(import.meta.dirname);

describe('2015', () => {
describe('Day 3', () => {
describe('Part 1', () => {
it('should return number of unique locations visited', () => {
expect(part1('>')).toBe(2);
expect(part1('^>v<')).toBe(4);
expect(part1('^v^v^v^v^v')).toBe(2);
expect(part1(input)).toBe(2081);
assert.strictEqual(part1('>'), 2);
assert.strictEqual(part1('^>v<'), 4);
assert.strictEqual(part1('^v^v^v^v^v'), 2);
assert.strictEqual(part1(input), 2081);
});
});

describe('Part 2', () => {
it('should return number of unique locations visited by santa and robo-santa', () => {
expect(part2('^v')).toBe(3);
expect(part2('^>v<')).toBe(3);
expect(part2('^v^v^v^v^v')).toBe(11);
expect(part2(input)).toBe(2341);
assert.strictEqual(part2('^v'), 3);
assert.strictEqual(part2('^>v<'), 3);
assert.strictEqual(part2('^v^v^v^v^v'), 11);
assert.strictEqual(part2(input), 2341);
});
});
});
Expand Down
13 changes: 7 additions & 6 deletions 2015/day/4/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import { describe, expect, it } from 'vitest';
import { part1, part2 } from '.';
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { part1, part2 } from './index.ts';

const input = 'ckczppom';

describe('2015', () => {
describe('Day 4', () => {
describe('Part 1', () => {
it('should find a hash which starts with five zeros', () => {
expect(part1('abcdef')).toBe(609043);
expect(part1('pqrstuv')).toBe(1048970);
expect(part1(input)).toBe(117946);
assert.strictEqual(part1('abcdef'), 609043);
assert.strictEqual(part1('pqrstuv'), 1048970);
assert.strictEqual(part1(input), 117946);
});
});

describe('Part 2', () => {
it('should find a hash which starts with six zeros', () => {
expect(part2(input)).toBe(3938038);
assert.strictEqual(part2(input), 3938038);
});
});
});
Expand Down
23 changes: 13 additions & 10 deletions 2015/day/5/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
import { describe, expect, it } from 'vitest';
import { part1, part2 } from '.';
import { getInput } from '../../../utils/file';
import { NEWLINE } from '../../../utils/string';
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { getInput } from '../../../utils/file.ts';
import { NEWLINE } from '../../../utils/string.ts';
import { part1, part2 } from './index.ts';

const input = (await getInput(__dirname)).split(NEWLINE);
const input = (await getInput(import.meta.dirname)).split(NEWLINE);

describe('2015', () => {
describe('Day 5', () => {
describe('Part 1', () => {
it('should filter out nice words', () => {
expect(
assert.strictEqual(
part1([
'ugknbfddgicrmopn',
'aaa',
'jchzalrnumimnmhp',
'haegwjzuvuyypxyu',
'dvszwmarrgswjxmb',
]),
).toBe(2);
expect(part1(input)).toBe(255);
2,
);
assert.strictEqual(part1(input), 255);
});
});

describe('Part 2', () => {
it('should filter out nice words', () => {
expect(part2(['qjhvhtzxzqqjkmpb', 'xxyxx', 'uurcxstgmygtbstg', 'ieodomkazucvgmuy'])).toBe(
assert.strictEqual(
part2(['qjhvhtzxzqqjkmpb', 'xxyxx', 'uurcxstgmygtbstg', 'ieodomkazucvgmuy']),
2,
);
expect(part2(input)).toBe(55);
assert.strictEqual(part2(input), 55);
});
});
});
Expand Down
15 changes: 8 additions & 7 deletions 2015/day/6/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import { describe, expect, it } from 'vitest';
import { part1, part2 } from '.';
import { getInput } from '../../../utils/file';
import { NEWLINE } from '../../../utils/string';
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { getInput } from '../../../utils/file.ts';
import { NEWLINE } from '../../../utils/string.ts';
import { part1, part2 } from './index.ts';

const input = (await getInput(__dirname)).split(NEWLINE);
const input = (await getInput(import.meta.dirname)).split(NEWLINE);

describe('2015', () => {
describe('Day 6', () => {
describe('Part 1', () => {
it('should could could lit lights', () => {
expect(part1(input)).toBe(377891);
assert.strictEqual(part1(input), 377891);
});
});

describe('Part 2', () => {
it('should return the total brightness', () => {
expect(part2(input)).toBe(14110788);
assert.strictEqual(part2(input), 14110788);
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion 2015/day/6/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RADIX, sum } from '../../../utils/math';
import { RADIX, sum } from '../../../utils/math.ts';

const BASE = 1000;

Expand Down
15 changes: 8 additions & 7 deletions 2015/day/8/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { describe, expect, it } from 'vitest';
import { part1 } from '.';
import { getInput } from '../../../utils/file';
import { NEWLINE } from '../../../utils/string';
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { getInput } from '../../../utils/file.ts';
import { NEWLINE } from '../../../utils/string.ts';
import { part1 } from './index.ts';

const input = (await getInput(__dirname)).split(NEWLINE);
const input = (await getInput(import.meta.dirname)).split(NEWLINE);

describe('2015', () => {
describe('Day 8', () => {
describe('Part 1', () => {
it('should return the number of characters', () => {
expect(part1(['""', '"abc"', '"aaa\\"aaa"', '"\\x27"'])).toBe(12);
expect(part1(input)).toBe(1350);
assert.strictEqual(part1(['""', '"abc"', '"aaa\\"aaa"', '"\\x27"']), 12);
assert.strictEqual(part1(input), 1350);
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion 2015/day/8/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { sum } from '../../../utils/math';
import { sum } from '../../../utils/math.ts';

function mapString(str: string): number {
const { length: totalCharacters } = str;
Expand Down
Loading

0 comments on commit 3e30206

Please sign in to comment.