Skip to content

Commit 9ffd114

Browse files
committed
Adding tests for "The electrician
apprentice".
1 parent d7e9d32 commit 9ffd114

File tree

15 files changed

+249
-0
lines changed

15 files changed

+249
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
- Tests for "A child's play".
1818
- Tests for "Sum of spiral's diagonals".
1919
- Tests for "Brackets, extreme edition".
20+
- Tests for "The electrician apprentice".
2021

2122
## [1.6.0] - 2022-03-11
2223
### Added
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* The "The electrician apprentice" puzzle.
3+
*/
4+
function execute(readline) {
5+
const C = parseInt(readline());
6+
for (let i = 0; i < C; i++) {
7+
const WIRING = readline();
8+
}
9+
const A = parseInt(readline());
10+
for (let i = 0; i < A; i++) {
11+
const SWITCH = readline();
12+
}
13+
for (let i = 0; i < C; i++) {
14+
15+
// Write an answer using console.log()
16+
// To debug: console.error('Debug messages...');
17+
18+
console.log('ANSWER');
19+
}
20+
}
21+
22+
export { execute };
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import { assert } from 'chai';
2+
import sinon from 'sinon';
3+
import File from '../../../../File.js';
4+
import { assertOutputAnswer } from '../../../../assertOutputAnswer.js';
5+
import { execute } from '../../../../../lib/community/training/easy/theElectricianApprentice/theElectricianApprentice.js';
6+
7+
const __dirname = new URL('.', import.meta.url).pathname;
8+
9+
suite("The electrician apprentice", 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("1 switch 1 light", function() {
22+
let inputFile = new File(__dirname + 'input/01 - 1 switch 1 light.txt');
23+
24+
execute(inputFile.readline.bind(inputFile));
25+
26+
assert.strictEqual(
27+
console.log.getCall(0).args[0],
28+
"LIGHT is ON"
29+
);
30+
});
31+
32+
test("2 parallel switches 1 light", function() {
33+
let inputFile = new File(__dirname + 'input/02 - 2 parallel switches 1 light.txt');
34+
35+
execute(inputFile.readline.bind(inputFile));
36+
37+
assert.strictEqual(
38+
console.log.getCall(0).args[0],
39+
"LIGHT is ON"
40+
);
41+
});
42+
43+
test("2 series switches 1 light", function() {
44+
let inputFile = new File(__dirname + 'input/03 - 2 series switches 1 light.txt');
45+
46+
execute(inputFile.readline.bind(inputFile));
47+
48+
assert.strictEqual(
49+
console.log.getCall(0).args[0],
50+
"LIGHT is OFF"
51+
);
52+
});
53+
54+
test("Two lights", function() {
55+
let inputFile = new File(__dirname + 'input/04 - two lights.txt');
56+
57+
execute(inputFile.readline.bind(inputFile));
58+
59+
assertOutputAnswer(__dirname + 'output/04 - two lights.txt');
60+
});
61+
62+
test("Series and parallel", function() {
63+
let inputFile = new File(__dirname + 'input/05 - series and parallel.txt');
64+
65+
execute(inputFile.readline.bind(inputFile));
66+
67+
assert.strictEqual(
68+
console.log.getCall(0).args[0],
69+
"LIGHT is ON"
70+
);
71+
});
72+
73+
test("Mixed", function() {
74+
let inputFile = new File(__dirname + 'input/06 - mixed.txt');
75+
76+
execute(inputFile.readline.bind(inputFile));
77+
78+
assertOutputAnswer(__dirname + 'output/06 - mixed.txt');
79+
});
80+
81+
test("Weird Home", function() {
82+
let inputFile = new File(__dirname + 'input/07 - weird home.txt');
83+
84+
execute(inputFile.readline.bind(inputFile));
85+
86+
assertOutputAnswer(__dirname + 'output/07 - weird home.txt');
87+
});
88+
89+
test("Regular Home", function() {
90+
let inputFile = new File(__dirname + 'input/08 - regular home.txt');
91+
92+
execute(inputFile.readline.bind(inputFile));
93+
94+
assertOutputAnswer(__dirname + 'output/08 - regular home.txt');
95+
});
96+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1
2+
LIGHT - A1
3+
1
4+
A1
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1
2+
LIGHT = A1 A2
3+
1
4+
A2
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
1
2+
LIGHT - A1 A2
3+
3
4+
A1
5+
A2
6+
A1
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2
2+
LIGHT1 - A1
3+
LIGHT2 - B1
4+
2
5+
A1
6+
B1
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
1
2+
LIGHT - A1 = A2 A3
3+
6
4+
A1
5+
A1
6+
A2
7+
A2
8+
A3
9+
A1
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2
2+
LIGHT1 - A1 = A2 A3
3+
LIGHT2 - B1 = B2 B3 = B4 B5
4+
6
5+
A1
6+
B1
7+
B2
8+
A3
9+
B5
10+
B4
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
6
2+
TV = A1 A2 - A3
3+
BOX = A1 A2 = A3 A4
4+
CONSOLE = A1 A2
5+
LIGHTS = B1 B2
6+
OVEN - KITCHEN = C1 C2 C3 - C4
7+
DISHWASHER - KITCHEN D1 D2 = D3 D4
8+
19
9+
A1
10+
B1
11+
A3
12+
C2
13+
C4
14+
A4
15+
A4
16+
A4
17+
A4
18+
D1
19+
KITCHEN
20+
D2
21+
A4
22+
A2
23+
KITCHEN
24+
D4
25+
A3
26+
C4
27+
KITCHEN

0 commit comments

Comments
 (0)