Skip to content

Commit 701055e

Browse files
committed
Adding tests for "Blowing fuse".
1 parent aed1040 commit 701055e

File tree

13 files changed

+130
-0
lines changed

13 files changed

+130
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [Unreleased]
8+
### Added
9+
- Tests for "Blowing fuse".
10+
711
## [1.4.0] - 2022-03-03
812
### Added
913
- Tests for "Blunder - episode 2".
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* The "Blowing fuse" puzzle.
3+
*/
4+
function execute(readline) {
5+
var inputs = readline().split(' ');
6+
const n = parseInt(inputs[0]);
7+
const m = parseInt(inputs[1]);
8+
const c = parseInt(inputs[2]);
9+
var inputs = readline().split(' ');
10+
for (let i = 0; i < n; i++) {
11+
const nx = parseInt(inputs[i]);
12+
}
13+
var inputs = readline().split(' ');
14+
for (let i = 0; i < m; i++) {
15+
const mx = parseInt(inputs[i]);
16+
}
17+
18+
// Write an answer using console.log()
19+
// To debug: console.error('Debug messages...');
20+
21+
console.log('Fuse was not blown.');
22+
console.log('Maximal consumed current was XX A.');
23+
}
24+
25+
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 { assertOutputAnswer } from '../../../../assertOutputAnswer.js';
5+
import { execute } from '../../../../../lib/community/training/easy/blowingFuse/blowingFuse.js';
6+
7+
/**
8+
* Tests for the "Blowing fuse" puzzle.
9+
*/
10+
suite('Blowing fuse', function() {
11+
const sandbox = sinon.createSandbox();
12+
13+
setup(function () {
14+
sandbox.stub(console, "log");
15+
});
16+
17+
teardown(function () {
18+
sandbox.restore();
19+
});
20+
21+
22+
test('Blown', function() {
23+
let inputFile = new File('./test/community/training/easy/blowingFuse/input/01 - blown.txt');
24+
25+
execute(inputFile.readline.bind(inputFile));
26+
27+
assert.strictEqual(
28+
console.log.getCall(0).args[0],
29+
"Fuse was blown."
30+
);
31+
});
32+
33+
test('Not blown', function() {
34+
let inputFile = new File('./test/community/training/easy/blowingFuse/input/02 - not blown.txt');
35+
36+
execute(inputFile.readline.bind(inputFile));
37+
38+
assertOutputAnswer('./test/community/training/easy/blowingFuse/output/02 - not blown.txt');
39+
});
40+
41+
test('Single device', function() {
42+
let inputFile = new File('./test/community/training/easy/blowingFuse/input/03 - single device.txt');
43+
44+
execute(inputFile.readline.bind(inputFile));
45+
46+
assert.strictEqual(
47+
console.log.getCall(0).args[0],
48+
"Fuse was blown."
49+
);
50+
});
51+
52+
test('More devices', function() {
53+
let inputFile = new File('./test/community/training/easy/blowingFuse/input/04 - more device.txt');
54+
55+
execute(inputFile.readline.bind(inputFile));
56+
57+
assertOutputAnswer('./test/community/training/easy/blowingFuse/output/04 - more device.txt');
58+
});
59+
60+
test('More clicks, more devices', function() {
61+
let inputFile = new File('./test/community/training/easy/blowingFuse/input/05 - more clicks, more devices.txt');
62+
63+
execute(inputFile.readline.bind(inputFile));
64+
65+
assertOutputAnswer('./test/community/training/easy/blowingFuse/output/05 - more clicks, more devices.txt');
66+
});
67+
68+
test('Power hungry', function() {
69+
let inputFile = new File('./test/community/training/easy/blowingFuse/input/06 - power hungry.txt');
70+
71+
execute(inputFile.readline.bind(inputFile));
72+
73+
assertOutputAnswer('./test/community/training/easy/blowingFuse/output/06 - power hungry.txt');
74+
});
75+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
5 2 10
2+
11 6 11 10 10
3+
3 3
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
5 8 82
2+
18 20 3 1 20
3+
2 4 3 3 5 4 2 3
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1 10 1
2+
9
3+
1 1 1 1 1 1 1 1 1 1
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
6 24 71
2+
10 10 14 14 14 15
3+
4 3 3 5 4 1 5 5 5 4 1 5 5 4 2 3 3 3 1 6 2 1 5 5
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
11 20 72
2+
11 10 13 19 15 9 20 10 16 12 5
3+
6 8 3 4 8 6 10 3 6 5 2 4 10 2 6 6 4 2 4 5
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
20 20 200
2+
3 12 5 8 15 12 12 10 11 16 10 19 17 15 11 9 17 6 14 5
3+
1 3 5 7 5 9 2 4 6 8 10 11 13 15 2 17 12 14 16 18
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fuse was not blown.
2+
Maximal consumed current was 41 A.

0 commit comments

Comments
 (0)