Skip to content

Commit 24c5d46

Browse files
committed
Adding tests for "Auto pickup".
1 parent 0168b1c commit 24c5d46

File tree

8 files changed

+100
-0
lines changed

8 files changed

+100
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2525
- Tests for "Zhiwei Sun squares".
2626
- Tests for "Stall tilt".
2727
- Tests for "What's so complex about Mandelbrot?".
28+
- Tests for "Auto pickup".
2829

2930
## [1.9.0] - 2022-06-01
3031
### Added
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* The "Auto pickup" puzzle.
3+
* @see {@link https://www.codingame.com/ide/puzzle/auto-pickup}
4+
*/
5+
function execute(readline) {
6+
const n = parseInt(readline());
7+
const packet = readline();
8+
9+
// Write an answer using console.log()
10+
// To debug: console.error('Debug messages...');
11+
12+
console.log('001[length][item id]');
13+
}
14+
15+
export { execute };
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { assert } from 'chai';
2+
import sinon from 'sinon';
3+
import File from '../../../../File.js';
4+
import { execute } from '../../../../../lib/community/training/easy/autoPickup/autoPickup.js';
5+
6+
const __dirname = new URL('.', import.meta.url).pathname;
7+
8+
suite("Auto pickup", function() {
9+
const sandbox = sinon.createSandbox();
10+
11+
setup(function () {
12+
sandbox.stub(console, "log");
13+
});
14+
15+
teardown(function () {
16+
sandbox.restore();
17+
});
18+
19+
20+
test("just a item drop", function() {
21+
let inputFile = new File(__dirname + 'input/01 - just a item drop.txt');
22+
23+
execute(inputFile.readline.bind(inputFile));
24+
25+
assert.strictEqual(
26+
console.log.getCall(0).args[0],
27+
"001001010"
28+
);
29+
});
30+
31+
test("more than 1 drop", function() {
32+
let inputFile = new File(__dirname + 'input/02 - more than 1 drop.txt');
33+
34+
execute(inputFile.readline.bind(inputFile));
35+
36+
assert.strictEqual(
37+
console.log.getCall(0).args[0],
38+
"00100010001001011"
39+
);
40+
});
41+
42+
test("other packets", function() {
43+
let inputFile = new File(__dirname + 'input/03 - other packets.txt');
44+
45+
execute(inputFile.readline.bind(inputFile));
46+
47+
assert.strictEqual(
48+
console.log.getCall(0).args[0],
49+
"00100011"
50+
);
51+
});
52+
53+
test("In between", function() {
54+
let inputFile = new File(__dirname + 'input/04 - in between.txt');
55+
56+
execute(inputFile.readline.bind(inputFile));
57+
58+
assert.strictEqual(
59+
console.log.getCall(0).args[0],
60+
"001001011"
61+
);
62+
});
63+
64+
test("that is a long one", function() {
65+
let inputFile = new File(__dirname + 'input/05 - that is a long one.txt');
66+
67+
execute(inputFile.readline.bind(inputFile));
68+
69+
assert.strictEqual(
70+
console.log.getCall(0).args[0],
71+
"0010011101001100011100011"
72+
);
73+
});
74+
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
9
2+
101001010
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
17
2+
10100010101001011
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
17
2+
00100101110100011
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
27
2+
111000111010010110010011101
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
63
2+
100100111100001001001011001010100111011110011110101100011100011

0 commit comments

Comments
 (0)