Skip to content

Commit 24ee41f

Browse files
committed
Adding tests for "Equivalent resistance, circuit building".
1 parent 05a9f12 commit 24ee41f

File tree

9 files changed

+138
-0
lines changed

9 files changed

+138
-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 "Walk on a die".
1010
- Tests for "Dolbear's law".
1111
- Tests for "ISBN check digit".
12+
- Tests for "Equivalent resistance, circuit building".
1213

1314
### Changed
1415
- Using "__dirname" for input / output paths.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* The "Equivalent resistance, circuit building" puzzle.
3+
*/
4+
function execute(readline) {
5+
const N = parseInt(readline());
6+
for (let i = 0; i < N; i++) {
7+
var inputs = readline().split(' ');
8+
const name = inputs[0];
9+
const R = parseInt(inputs[1]);
10+
}
11+
const circuit = readline();
12+
13+
// Write an answer using console.log()
14+
// To debug: console.error('Debug messages...');
15+
16+
console.log('Equivalent Resistance');
17+
}
18+
19+
export { execute };
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import { assert } from 'chai';
2+
import sinon from 'sinon';
3+
import File from '../../../../File.js';
4+
import { execute } from '../../../../../lib/community/training/easy/equivalentResistanceCircuitBuilding/equivalentResistanceCircuitBuilding.js';
5+
6+
const __dirname = new URL('.', import.meta.url).pathname;
7+
8+
/**
9+
* Tests for the "Equivalent resistance, circuit building" puzzle.
10+
*/
11+
suite('Equivalent resistance, circuit building', function() {
12+
const sandbox = sinon.createSandbox();
13+
14+
setup(function () {
15+
sandbox.stub(console, "log");
16+
});
17+
18+
teardown(function () {
19+
sandbox.restore();
20+
});
21+
22+
23+
test('Series', function() {
24+
let inputFile = new File(__dirname + 'input/01 - series.txt');
25+
26+
execute(inputFile.readline.bind(inputFile));
27+
28+
assert.strictEqual(
29+
console.log.getCall(0).args[0],
30+
"30.0"
31+
);
32+
});
33+
34+
test('Parallel', function() {
35+
let inputFile = new File(__dirname + 'input/02 - parallel.txt');
36+
37+
execute(inputFile.readline.bind(inputFile));
38+
39+
assert.strictEqual(
40+
console.log.getCall(0).args[0],
41+
11.1
42+
);
43+
});
44+
45+
test('Combined (example diagram)', function() {
46+
let inputFile = new File(__dirname + 'input/03 - combined (example diagram).txt');
47+
48+
execute(inputFile.readline.bind(inputFile));
49+
50+
assert.strictEqual(
51+
console.log.getCall(0).args[0],
52+
10.7
53+
);
54+
});
55+
56+
test('Complex', function() {
57+
let inputFile = new File(__dirname + 'input/04 - complex.txt');
58+
59+
execute(inputFile.readline.bind(inputFile));
60+
61+
assert.strictEqual(
62+
console.log.getCall(0).args[0],
63+
2.4
64+
);
65+
});
66+
67+
test('More complex', function() {
68+
let inputFile = new File(__dirname + 'input/05 - more complex.txt');
69+
70+
execute(inputFile.readline.bind(inputFile));
71+
72+
assert.strictEqual(
73+
console.log.getCall(0).args[0],
74+
"45.0"
75+
);
76+
});
77+
78+
test('5-pointed star', function() {
79+
let inputFile = new File(__dirname + 'input/06 - 5-pointed star.txt');
80+
81+
execute(inputFile.readline.bind(inputFile));
82+
83+
assert.strictEqual(
84+
console.log.getCall(0).args[0],
85+
"91.0"
86+
);
87+
});
88+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2
2+
A 20
3+
B 10
4+
( A B )
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2
2+
C 20
3+
D 25
4+
[ C D ]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
A 24
3+
B 8
4+
C 48
5+
[ ( A B ) [ C A ] ]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
7
2+
Alfa 1
3+
Bravo 1
4+
Charlie 12
5+
Delta 4
6+
Echo 2
7+
Foxtrot 10
8+
Golf 8
9+
( Alfa [ Charlie Delta ( Bravo [ Echo ( Foxtrot Golf ) ] ) ] )
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
Alef 30
3+
Bet 20
4+
Vet 10
5+
( Alef [ ( Bet Bet Bet ) ( Vet [ ( Vet Vet ) ( Vet [ Bet Bet ] ) ] ) ] )
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1
2+
Star 78
3+
[ ( [ Star ( Star Star ) ] [ Star ( Star Star ) ] Star ) ( [ Star ( Star Star ) ] [ Star ( Star Star ) ] Star ) ]

0 commit comments

Comments
 (0)