Skip to content

Commit ae8d1fc

Browse files
committed
Adding tests for "Rearrange string to two
numbers".
1 parent 433d691 commit ae8d1fc

21 files changed

+251
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ 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]
7+
## [1.16.0] - 2022-12-31
88
### Added
99
- Tests for "Sticky keyboard".
1010
- Tests for "Bingo!".
@@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3636
- Tests for "DDCG Mapper".
3737
- Tests for "Queneau numbers".
3838
- Tests for "Simple fraction to mixed number".
39+
- Tests for "Rearrange string to two numbers".
3940

4041
## [1.15.0] - 2022-11-30
4142
### Added
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* The "Rearrange string to two numbers" puzzle.
3+
* @see {@link https://www.codingame.com/ide/puzzle/rearrange-string-to-two-numbers}
4+
*/
5+
function execute(readline) {
6+
const S = readline();
7+
8+
// Write an answer using console.log()
9+
// To debug: console.error('Debug messages...');
10+
11+
console.log('-1 -1');
12+
}
13+
14+
export { execute };
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
import { assert } from 'chai';
2+
import sinon from 'sinon';
3+
import File from '../../../../File.js';
4+
import { execute } from '../../../../../lib/community/training/medium/rearrangeStringToTwoNumbers/rearrangeStringToTwoNumbers.js';
5+
6+
const __dirname = new URL('.', import.meta.url).pathname;
7+
8+
suite("Rearrange string to two numbers", function() {
9+
const sandbox = sinon.createSandbox();
10+
11+
setup(function () {
12+
sandbox.stub(console, "log");
13+
});
14+
15+
teardown(function () {
16+
sandbox.restore();
17+
});
18+
19+
20+
test("Two digits", function() {
21+
let inputFile = new File(__dirname + 'input/01 - two digits.txt');
22+
23+
execute(inputFile.readline.bind(inputFile));
24+
25+
assert.strictEqual(
26+
console.log.getCall(0).args[0],
27+
"2 7"
28+
);
29+
});
30+
31+
test("Too many digits", function() {
32+
let inputFile = new File(__dirname + 'input/02 - too many digits.txt');
33+
34+
execute(inputFile.readline.bind(inputFile));
35+
36+
assert.strictEqual(
37+
console.log.getCall(0).args[0],
38+
"-1 -1"
39+
);
40+
});
41+
42+
test("Maximum B", function() {
43+
let inputFile = new File(__dirname + 'input/03 - maximum B.txt');
44+
45+
execute(inputFile.readline.bind(inputFile));
46+
47+
assert.strictEqual(
48+
console.log.getCall(0).args[0],
49+
"400005555567778999 1000000000000000000"
50+
);
51+
});
52+
53+
test("Too many 0's", function() {
54+
let inputFile = new File(__dirname + 'input/04 - too many 0s.txt');
55+
56+
execute(inputFile.readline.bind(inputFile));
57+
58+
assert.strictEqual(
59+
console.log.getCall(0).args[0],
60+
"-1 -1"
61+
);
62+
});
63+
64+
test("Maximum B with 0", function() {
65+
let inputFile = new File(__dirname + 'input/05 - maximum B with 0.txt');
66+
67+
execute(inputFile.readline.bind(inputFile));
68+
69+
assert.strictEqual(
70+
console.log.getCall(0).args[0],
71+
"0 1000000000000000000"
72+
);
73+
});
74+
75+
test("Small A maximum B", function() {
76+
let inputFile = new File(__dirname + 'input/06 - small A maximum B.txt');
77+
78+
execute(inputFile.readline.bind(inputFile));
79+
80+
assert.strictEqual(
81+
console.log.getCall(0).args[0],
82+
"4 1000000000000000000"
83+
);
84+
});
85+
86+
test("Small A big B", function() {
87+
let inputFile = new File(__dirname + 'input/07 - small A big B.txt');
88+
89+
execute(inputFile.readline.bind(inputFile));
90+
91+
assert.strictEqual(
92+
console.log.getCall(0).args[0],
93+
"20 200223334577788999"
94+
);
95+
});
96+
97+
test("Too many 0's", function() {
98+
let inputFile = new File(__dirname + 'input/08 - too many 0s - 2.txt');
99+
100+
execute(inputFile.readline.bind(inputFile));
101+
102+
assert.strictEqual(
103+
console.log.getCall(0).args[0],
104+
"-1 -1"
105+
);
106+
});
107+
108+
test("Too few digits", function() {
109+
let inputFile = new File(__dirname + 'input/09 - too few digits.txt');
110+
111+
execute(inputFile.readline.bind(inputFile));
112+
113+
assert.strictEqual(
114+
console.log.getCall(0).args[0],
115+
"-1 -1"
116+
);
117+
});
118+
119+
test("Too many digits", function() {
120+
let inputFile = new File(__dirname + 'input/10 - too many digits.txt');
121+
122+
execute(inputFile.readline.bind(inputFile));
123+
124+
assert.strictEqual(
125+
console.log.getCall(0).args[0],
126+
"-1 -1"
127+
);
128+
});
129+
130+
test("Zero", function() {
131+
let inputFile = new File(__dirname + 'input/11 - zero.txt');
132+
133+
execute(inputFile.readline.bind(inputFile));
134+
135+
assert.strictEqual(
136+
console.log.getCall(0).args[0],
137+
"0 400004566667788899"
138+
);
139+
});
140+
141+
test("Maximum", function() {
142+
let inputFile = new File(__dirname + 'input/12 - maximum.txt');
143+
144+
execute(inputFile.readline.bind(inputFile));
145+
146+
assert.strictEqual(
147+
console.log.getCall(0).args[0],
148+
"1000000000000000000 1000000000000000000"
149+
);
150+
});
151+
152+
test("Big with 0's", function() {
153+
let inputFile = new File(__dirname + 'input/13 - big with 0s.txt');
154+
155+
execute(inputFile.readline.bind(inputFile));
156+
157+
assert.strictEqual(
158+
console.log.getCall(0).args[0],
159+
"200000222233333345 566777777888999999"
160+
);
161+
});
162+
163+
test("Big", function() {
164+
let inputFile = new File(__dirname + 'input/14 - big.txt');
165+
166+
execute(inputFile.readline.bind(inputFile));
167+
168+
assert.strictEqual(
169+
console.log.getCall(0).args[0],
170+
"111112222333355566 777778888889999999"
171+
);
172+
});
173+
174+
test("Internal zeros", function() {
175+
let inputFile = new File(__dirname + 'input/15 - internal zeros.txt');
176+
177+
execute(inputFile.readline.bind(inputFile));
178+
179+
assert.strictEqual(
180+
console.log.getCall(0).args[0],
181+
"100022233334444 45555555666668899"
182+
);
183+
});
184+
185+
test("Small A big B", function() {
186+
let inputFile = new File(__dirname + 'input/16 - small A big B.txt');
187+
188+
execute(inputFile.readline.bind(inputFile));
189+
190+
assert.strictEqual(
191+
console.log.getCall(0).args[0],
192+
"5 555566666667778899"
193+
);
194+
});
195+
196+
test("Small A big B", function() {
197+
let inputFile = new File(__dirname + 'input/17 - small A big B - 2.txt');
198+
199+
execute(inputFile.readline.bind(inputFile));
200+
201+
assert.strictEqual(
202+
console.log.getCall(0).args[0],
203+
"4 44455566667788"
204+
);
205+
});
206+
207+
test("Two digits", function() {
208+
let inputFile = new File(__dirname + 'input/18 - two digits.txt');
209+
210+
execute(inputFile.readline.bind(inputFile));
211+
212+
assert.strictEqual(
213+
console.log.getCall(0).args[0],
214+
"9 9"
215+
);
216+
});
217+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
72
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8784688955737839773875997657797875797
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0800795705000904561000705000000905000
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0000000000100000000000
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
10000000000000000000
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
00000004000000000001
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
79380248390522737902

0 commit comments

Comments
 (0)