Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Every test of the Advent Of Code #5

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
12 changes: 10 additions & 2 deletions src/js/aoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
/**
* Day 1
*/
function computeResult(contents) {
return getSumOfTopElves(contents, 1);
}

function getSumOfTopElves(contents, n) {
var globalResult = 0;
return globalResult;
}

/**
* Day 2
Expand Down Expand Up @@ -178,7 +186,6 @@ function getArrayInterval(start, end) {
return result;
}


/**
* --- Day 7 : Directory size ---
*/
Expand Down Expand Up @@ -256,6 +263,7 @@ function getVisibleTrees(forest) {
/**
* --- Day 9: Get tail position ---
*/

function getNumberTailPositions(motionList) {
var position = [0, 0];
var tailPositions = [];
Expand Down Expand Up @@ -361,4 +369,4 @@ function isRelated(positionHead, positionTail) {
}
}
return false;
}
}
62 changes: 61 additions & 1 deletion src/js/test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,68 @@
mocha.setup('tdd');

suite('Day One of Advent of Code', () => {
suite('Day one of Advent of Code', () => {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this test in a day_1 file.

var contentTestInput = `
1000
2000
3000

4000

5000
6000

7000
8000
9000

10000`;

test('The elf with the most calories carry 24000 calories', () => {
chai.expect(getSumOfTopElves(contentTestInput, 1)).to.eql(24000);
});

test('The sum of the Calories carried by the top three elves is 45000', () => {
chai.expect(getSumOfTopElves(contentTestInput, 3)).to.eql(45000);
});
});

suite('Day two of Advent of Code', () => {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this test in a day_2.js file

var strategy = `A Y
B X
C Z
`;

test('the rock scissor paper score based on the strategy will return 15', () => {
chai.assert.equal(12, getScore(strategy));
});

test('the detailed score should work', () => {
chai.assert.equal(7, getScore('C Z'));
chai.assert.equal(4, getScore('A Y'));
chai.assert.equal(1, getScore('B X'));
chai.assert.equal(3, getScore('A X'));
});

test('the rock is valued to 1', () => {
chai.assert.equal(1, getItemValue('A'));
});
test('the paper is valued to 2', () => {
chai.assert.equal(2, getItemValue('B'));
});
test('the scissor is valued to 3', () => {
chai.assert.equal(3, getItemValue('C'));
});

test('ho no, i lose', () => {
chai.assert.equal(0, getResultScore('X'));
});
test('this was close', () => {
chai.assert.equal(3, getResultScore('Y'));
});
test('yeah I win', () => {
chai.assert.equal(6, getResultScore('Z'));
});

suite('Day Two of Advent of Code', () => {
});

Expand Down
13 changes: 13 additions & 0 deletions src/js/test/day_8.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
mocha.setup('tdd');

suite('Day eight of Advent of Code', () => {
const testData = `30373
25512
65332
33549
35390`;

test('There\'s 21 tree visible from outside the grid', () => {
chai.assert.equal(21, getVisibleTrees(testData));
});
});
2 changes: 0 additions & 2 deletions src/js/test/day_9.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,4 @@ R 2`;
chai.assert.isFalse(iNeedToMoveTail(data[0], data[1]));
});
});


});
1 change: 1 addition & 0 deletions src/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<script src="js/aoc.js"></script>
<script src="js/test.js"></script>
<script src="js/test/day_7.js"></script>
<script src="js/test/day_8.js"></script>
<script src="js/test/day_9.js"></script>

brice marked this conversation as resolved.
Show resolved Hide resolved
<script class="mocha-exec">
Expand Down