Skip to content

Commit 55a5047

Browse files
committed
Adding tests for "Telephone numbers".
1 parent d418431 commit 55a5047

File tree

8 files changed

+10109
-0
lines changed

8 files changed

+10109
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
- Tests for "Network cabling".
1010
- Tests for "Scrabble".
1111
- Tests for "Stock exchange losses".
12+
- Tests for "Telephone numbers".
1213

1314
## [1.2.0] - 2022-03-02
1415
### Added
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* The "Telephone numbers" puzzle.
3+
*/
4+
function execute(readline) {
5+
const N = parseInt(readline());
6+
for (let i = 0; i < N; i++) {
7+
const telephone = readline();
8+
}
9+
10+
// Write an answer using console.log()
11+
// To debug: console.error('Debug messages...');
12+
13+
14+
// The number of elements (referencing a number) stored in the structure.
15+
console.log('number');
16+
}
17+
18+
export { execute };
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { assert } from 'chai';
2+
import sinon from 'sinon';
3+
import File from '../../../File.js';
4+
import { execute } from '../../../../lib/training/medium/telephoneNumbers/telephoneNumbers.js';
5+
6+
/**
7+
* Tests for the "Telephone numbers" puzzle.
8+
*/
9+
suite('Telephone numbers', function() {
10+
const sandbox = sinon.createSandbox();
11+
12+
setup(function () {
13+
sandbox.stub(console, "log");
14+
});
15+
16+
teardown(function () {
17+
sandbox.restore();
18+
});
19+
20+
21+
test('A telephone number', function() {
22+
let inputFile = new File('./test/training/medium/telephoneNumbers/input/01 - a telephone number.txt');
23+
24+
execute(inputFile.readline.bind(inputFile));
25+
26+
assert.strictEqual(
27+
console.log.getCall(0).args[0],
28+
10
29+
);
30+
});
31+
32+
test('Numbers with a different base', function() {
33+
let inputFile = new File('./test/training/medium/telephoneNumbers/input/02 - numbers with a different base.txt');
34+
35+
execute(inputFile.readline.bind(inputFile));
36+
37+
assert.strictEqual(
38+
console.log.getCall(0).args[0],
39+
20
40+
);
41+
});
42+
43+
test('Number included in another', function() {
44+
let inputFile = new File('./test/training/medium/telephoneNumbers/input/03 - number included in another.txt');
45+
46+
execute(inputFile.readline.bind(inputFile));
47+
48+
assert.strictEqual(
49+
console.log.getCall(0).args[0],
50+
10
51+
);
52+
});
53+
54+
test('Numbers with a common part', function() {
55+
let inputFile = new File('./test/training/medium/telephoneNumbers/input/04 - numbers with a common part.txt');
56+
57+
execute(inputFile.readline.bind(inputFile));
58+
59+
assert.strictEqual(
60+
console.log.getCall(0).args[0],
61+
28
62+
);
63+
});
64+
65+
test('Long list of numbers', function() {
66+
let inputFile = new File('./test/training/medium/telephoneNumbers/input/05 - long list of numbers.txt');
67+
68+
execute(inputFile.readline.bind(inputFile));
69+
70+
assert.strictEqual(
71+
console.log.getCall(0).args[0],
72+
45512
73+
);
74+
});
75+
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1
2+
0467123456
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
0123456789
3+
1123456789
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
0123456789
3+
0123
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
5
2+
0412578440
3+
0412199803
4+
0468892011
5+
112
6+
15

0 commit comments

Comments
 (0)