Skip to content

Commit 433d691

Browse files
committed
Adding tests for "Simple fraction to mixed
number".
1 parent 315ea17 commit 433d691

18 files changed

+168
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3535
- Tests for "Plight of the fellowship of the ring".
3636
- Tests for "DDCG Mapper".
3737
- Tests for "Queneau numbers".
38+
- Tests for "Simple fraction to mixed number".
3839

3940
## [1.15.0] - 2022-11-30
4041
### Added
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* The "Simple fraction to mixed number" puzzle.
3+
* @see {@link https://www.codingame.com/ide/puzzle/simple-fraction-to-mixed-number}
4+
*/
5+
function execute(readline) {
6+
const N = parseInt(readline());
7+
for (let i = 0; i < N; i++) {
8+
const xY = readline();
9+
}
10+
for (let i = 0; i < N; i++) {
11+
12+
// Write an answer using console.log()
13+
// To debug: console.error('Debug messages...');
14+
15+
console.log('answer');
16+
}
17+
}
18+
19+
export { execute };
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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/medium/simpleFractionToMixedNumber/simpleFractionToMixedNumber.js';
6+
7+
const __dirname = new URL('.', import.meta.url).pathname;
8+
9+
suite("Simple fraction to mixed number", 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("Both integer and fractional parts", function() {
22+
let inputFile = new File(__dirname + 'input/01 - both integer and fractional parts.txt');
23+
24+
execute(inputFile.readline.bind(inputFile));
25+
26+
assertOutputAnswer(__dirname + 'output/01 - both integer and fractional parts.txt');
27+
});
28+
29+
test("Integer part only", function() {
30+
let inputFile = new File(__dirname + 'input/02 - integer part only.txt');
31+
32+
execute(inputFile.readline.bind(inputFile));
33+
34+
assertOutputAnswer(__dirname + 'output/02 - integer part only.txt');
35+
});
36+
37+
test("Fractional part only", function() {
38+
let inputFile = new File(__dirname + 'input/03 - fractional part only.txt');
39+
40+
execute(inputFile.readline.bind(inputFile));
41+
42+
assertOutputAnswer(__dirname + 'output/03 - fractional part only.txt');
43+
});
44+
45+
test("Zero", function() {
46+
let inputFile = new File(__dirname + 'input/04 - zero.txt');
47+
48+
execute(inputFile.readline.bind(inputFile));
49+
50+
assertOutputAnswer(__dirname + 'output/04 - zero.txt');
51+
});
52+
53+
test("Division by zero", function() {
54+
let inputFile = new File(__dirname + 'input/05 - division by zero.txt');
55+
56+
execute(inputFile.readline.bind(inputFile));
57+
58+
assert.strictEqual(
59+
console.log.getCall(0).args[0],
60+
"DIVISION BY ZERO"
61+
);
62+
});
63+
64+
test("Sign handling", function() {
65+
let inputFile = new File(__dirname + 'input/06 - sign handling.txt');
66+
67+
execute(inputFile.readline.bind(inputFile));
68+
69+
assertOutputAnswer(__dirname + 'output/06 - sign handling.txt');
70+
});
71+
72+
test("Some more sign handling", function() {
73+
let inputFile = new File(__dirname + 'input/07 - some more sign handling.txt');
74+
75+
execute(inputFile.readline.bind(inputFile));
76+
77+
assertOutputAnswer(__dirname + 'output/07 - some more sign handling.txt');
78+
});
79+
80+
test("Several random cases", function() {
81+
let inputFile = new File(__dirname + 'input/08 - several random cases.txt');
82+
83+
execute(inputFile.readline.bind(inputFile));
84+
85+
assertOutputAnswer(__dirname + 'output/08 - several random cases.txt');
86+
});
87+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
42/9
3+
71/23
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
3
2+
6/3
3+
28/4
4+
105/35
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
4/6
3+
10/78
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
0/91
3+
-0/287
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1
2+
3/0
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
-5/20
3+
20/-5
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
-10/-7
3+
21/-6

0 commit comments

Comments
 (0)