Skip to content

Commit 5066f8a

Browse files
committed
Adding tests for "Create the longest
sequence of 1s".
1 parent 8f658b0 commit 5066f8a

File tree

18 files changed

+213
-0
lines changed

18 files changed

+213
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
- Tests for "The electrician apprentice".
2121
- Tests for "Sudoku validator".
2222
- Tests for "Mountain map".
23+
- Tests for "Create the longest sequence of 1s".
2324

2425
## [1.6.0] - 2022-03-11
2526
### Added
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* The "Create the longest sequence of 1s" puzzle.
3+
*/
4+
function execute(readline) {
5+
const b = readline();
6+
7+
// Write an answer using console.log()
8+
// To debug: console.error('Debug messages...');
9+
10+
console.log('answer');
11+
}
12+
13+
export { execute };
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
import { assert } from 'chai';
2+
import sinon from 'sinon';
3+
import File from '../../../../File.js';
4+
import { execute } from '../../../../../lib/community/training/easy/createTheLongestSequenceOf1s/createTheLongestSequenceOf1s.js';
5+
6+
const __dirname = new URL('.', import.meta.url).pathname;
7+
8+
suite("Create the longest sequence of 1s", 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("2 bits", function() {
21+
let inputFile = new File(__dirname + 'input/01 - 2 bits.txt');
22+
23+
execute(inputFile.readline.bind(inputFile));
24+
25+
assert.strictEqual(
26+
console.log.getCall(0).args[0],
27+
1
28+
);
29+
});
30+
31+
test("5 bits", function() {
32+
let inputFile = new File(__dirname + 'input/02 - 5 bits.txt');
33+
34+
execute(inputFile.readline.bind(inputFile));
35+
36+
assert.strictEqual(
37+
console.log.getCall(0).args[0],
38+
3
39+
);
40+
});
41+
42+
test("11 bits", function() {
43+
let inputFile = new File(__dirname + 'input/03 - 11 bits.txt');
44+
45+
execute(inputFile.readline.bind(inputFile));
46+
47+
assert.strictEqual(
48+
console.log.getCall(0).args[0],
49+
8
50+
);
51+
});
52+
53+
test("50 bits", function() {
54+
let inputFile = new File(__dirname + 'input/04 - 50 bits.txt');
55+
56+
execute(inputFile.readline.bind(inputFile));
57+
58+
assert.strictEqual(
59+
console.log.getCall(0).args[0],
60+
8
61+
);
62+
});
63+
64+
test("100 bits", function() {
65+
let inputFile = new File(__dirname + 'input/05 - 100 bits.txt');
66+
67+
execute(inputFile.readline.bind(inputFile));
68+
69+
assert.strictEqual(
70+
console.log.getCall(0).args[0],
71+
13
72+
);
73+
});
74+
75+
test("999 bits", function() {
76+
let inputFile = new File(__dirname + 'input/06 - 999 bits.txt');
77+
78+
execute(inputFile.readline.bind(inputFile));
79+
80+
assert.strictEqual(
81+
console.log.getCall(0).args[0],
82+
23
83+
);
84+
});
85+
86+
test("32 bits", function() {
87+
let inputFile = new File(__dirname + 'input/07 - 32 bits.txt');
88+
89+
execute(inputFile.readline.bind(inputFile));
90+
91+
assert.strictEqual(
92+
console.log.getCall(0).args[0],
93+
6
94+
);
95+
});
96+
97+
test("20 bits", function() {
98+
let inputFile = new File(__dirname + 'input/08 - 20 bits.txt');
99+
100+
execute(inputFile.readline.bind(inputFile));
101+
102+
assert.strictEqual(
103+
console.log.getCall(0).args[0],
104+
5
105+
);
106+
});
107+
108+
test("Whole string", function() {
109+
let inputFile = new File(__dirname + 'input/09 - whole string.txt');
110+
111+
execute(inputFile.readline.bind(inputFile));
112+
113+
assert.strictEqual(
114+
console.log.getCall(0).args[0],
115+
15
116+
);
117+
});
118+
119+
test("All zeros", function() {
120+
let inputFile = new File(__dirname + 'input/10 - all zeros.txt');
121+
122+
execute(inputFile.readline.bind(inputFile));
123+
124+
assert.strictEqual(
125+
console.log.getCall(0).args[0],
126+
1
127+
);
128+
});
129+
130+
test("Gaps", function() {
131+
let inputFile = new File(__dirname + 'input/11 - gaps.txt');
132+
133+
execute(inputFile.readline.bind(inputFile));
134+
135+
assert.strictEqual(
136+
console.log.getCall(0).args[0],
137+
4
138+
);
139+
});
140+
141+
test("Random 100", function() {
142+
let inputFile = new File(__dirname + 'input/12 - random 100.txt');
143+
144+
execute(inputFile.readline.bind(inputFile));
145+
146+
assert.strictEqual(
147+
console.log.getCall(0).args[0],
148+
7
149+
);
150+
});
151+
152+
test("Random 32", function() {
153+
let inputFile = new File(__dirname + 'input/13 - random 32.txt');
154+
155+
execute(inputFile.readline.bind(inputFile));
156+
157+
assert.strictEqual(
158+
console.log.getCall(0).args[0],
159+
10
160+
);
161+
});
162+
163+
test("Gaps 2", function() {
164+
let inputFile = new File(__dirname + 'input/14 - gaps 2.txt');
165+
166+
execute(inputFile.readline.bind(inputFile));
167+
168+
assert.strictEqual(
169+
console.log.getCall(0).args[0],
170+
5
171+
);
172+
});
173+
174+
test("Steps", function() {
175+
let inputFile = new File(__dirname + 'input/15 - steps.txt');
176+
177+
execute(inputFile.readline.bind(inputFile));
178+
179+
assert.strictEqual(
180+
console.log.getCall(0).args[0],
181+
12
182+
);
183+
});
184+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
00
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
01010
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
11011101111
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
01110100110011000101001100011110010010101011111011
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1011010111110110111001001110111011000001011010110011101101111101111111011100011001101011011110001010
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
010001100101101100111010110010111000111010011101100000001110100100000111011100110001011100011011110011010111110101100000110001011010011011000000011000101001011101101110011100000110101100001001111011000000001000110011000001111110000010111001111000100010100001100011111001111011110101000010001101101001000000001010000101010101101011101000000010101110111010100001000010011100010110111111111010001000110010010110100110011101001110001000101001111111111111011111111101110110000001001110010010110100001101010010010101011010010001111001000010100110110100011000110100101111001011111100101110001010100100010010111100101110111011010100110011010001101011000000111110011010010100010010100111000010111000100110010100110111010101111001110111011011000100110100100101010110110001000100111110000111001110100110101100011010001101001101100010110100110110011101000000111001010101100011010111110100000100000011111110000111101001001110001000100101011011000000111100000111110010011000101001001100000110110111010111011110100
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
10000000011100000000011111000001

0 commit comments

Comments
 (0)