Skip to content

Commit c8fc9e4

Browse files
committed
Adding tests for "Bit count to limit".
1 parent b6e90b2 commit c8fc9e4

File tree

8 files changed

+94
-0
lines changed

8 files changed

+94
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2929
- Tests for "Battleship".
3030
- Tests for "Texas holdem".
3131
- Tests for "Solid integer".
32+
- Tests for "Bit count to limit".
3233

3334
## [1.15.0] - 2022-11-30
3435
### Added
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* The "Bit count to limit" puzzle.
3+
* @see {@link https://www.codingame.com/ide/puzzle/bit-count-to-limit}
4+
*/
5+
function execute(readline) {
6+
const n = parseInt(readline());
7+
8+
// Write an answer using console.log()
9+
// To debug: console.error('Debug messages...');
10+
11+
console.log('Number of 1s');
12+
}
13+
14+
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/medium/bitCountToLimit/bitCountToLimit.js';
5+
6+
const __dirname = new URL('.', import.meta.url).pathname;
7+
8+
suite("Bit count to limit", 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("Simple one", function() {
21+
let inputFile = new File(__dirname + 'input/01 - simple one.txt');
22+
23+
execute(inputFile.readline.bind(inputFile));
24+
25+
assert.strictEqual(
26+
console.log.getCall(0).args[0],
27+
7
28+
);
29+
});
30+
31+
test("A bit more", function() {
32+
let inputFile = new File(__dirname + 'input/02 - a bit more.txt');
33+
34+
execute(inputFile.readline.bind(inputFile));
35+
36+
assert.strictEqual(
37+
console.log.getCall(0).args[0],
38+
81
39+
);
40+
});
41+
42+
test("And > 100 ?", function() {
43+
let inputFile = new File(__dirname + 'input/03 - and > 100 ?.txt');
44+
45+
execute(inputFile.readline.bind(inputFile));
46+
47+
assert.strictEqual(
48+
console.log.getCall(0).args[0],
49+
408
50+
);
51+
});
52+
53+
test("Million ?", function() {
54+
let inputFile = new File(__dirname + 'input/04 - million ?.txt');
55+
56+
execute(inputFile.readline.bind(inputFile));
57+
58+
assert.strictEqual(
59+
console.log.getCall(0).args[0],
60+
10485761
61+
);
62+
});
63+
64+
test("Did you get the trick ?", function() {
65+
let inputFile = new File(__dirname + 'input/05 - did you get the trick ?.txt');
66+
67+
execute(inputFile.readline.bind(inputFile));
68+
69+
assert.strictEqual(
70+
console.log.getCall(0).args[0],
71+
1811939329
72+
);
73+
});
74+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
32
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
120
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1048576
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
134217728

0 commit comments

Comments
 (0)