Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/js/aoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,31 @@
/**
* Day 1
*/
function computeResult(contents) {
return getSumOfTopElves(contents, 1);
}

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

/**
* Day 2
*/
function getScore(strategy)} {
var score = 0;
return score;
}

function getWeaponValue(score, opponent) {
return 1;
}

function getItemValue(item) {
var value = 0;
return value;
}

/**
* Day 3
Expand Down Expand Up @@ -164,3 +185,19 @@ function getArrayInterval(start, end) {
}
return result;
}

/**
* --- Day 8: Get Visible trees ---
*/
function getVisibleTrees(forest) {
visibleTrees = 0;
return visibleTrees
};

/**
* --- Day 9: Get tail position ---
*/
function getNumberTailPositions() {
var count = 0;
return count;
}
63 changes: 61 additions & 2 deletions 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 Expand Up @@ -38,7 +98,6 @@ CrZsJsPPZsGzwwsLwLmpwMDw`;
test('the sum of badge\'s priorities from the input will return 70', () => {
chai.assert.equal(70, getBadgeSum(input));
});

});


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));
});
});
16 changes: 16 additions & 0 deletions src/js/test/day_9.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
mocha.setup('tdd');

suite('Day nine of Advent of Code', () => {
const testData = `R 4
U 4
L 3
D 1
R 4
D 1
L 5
R 2`;

test('The tail covered 13 positions', () => {
chai.assert.equal(13, getNumberTailPositions(testData));
});
});
3 changes: 2 additions & 1 deletion src/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/chai/4.3.7/chai.min.js"></script>
<script src="js/aoc.js"></script>
<script src="js/test.js"></script>
<script src="js/test/day_8.js"></script>

<script class="mocha-exec">

mocha.run();
</script>
</body>

</html>
</html>