Skip to content

Commit 1ea9bff

Browse files
committed
Adding tests for "Scrabble".
1 parent 9b6a843 commit 1ea9bff

12 files changed

+51044
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased]
88
### Added
99
- Tests for "Network cabling".
10+
- Tests for "Scrabble".
1011

1112
## [1.2.0] - 2022-03-02
1213
### Added
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* The "Scrabble" puzzle.
3+
*/
4+
function execute(readline) {
5+
const N = parseInt(readline());
6+
for (let i = 0; i < N; i++) {
7+
const W = readline();
8+
}
9+
const LETTERS = readline();
10+
11+
// Write an answer using console.log()
12+
// To debug: console.error('Debug messages...');
13+
14+
console.log('invalid word');
15+
}
16+
17+
export { execute };
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import { assert } from 'chai';
2+
import sinon from 'sinon';
3+
import File from '../../../File.js';
4+
import { execute } from '../../../../lib/training/medium/scrabble/scrabble.js';
5+
6+
/**
7+
* Tests for the "Scrabble" puzzle.
8+
*/
9+
suite('Scrabble', 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('Only one word', function() {
22+
let inputFile = new File('./test/training/medium/scrabble/input/01 - only one word.txt');
23+
24+
execute(inputFile.readline.bind(inputFile));
25+
26+
assert.strictEqual(
27+
console.log.getCall(0).args[0],
28+
'which'
29+
);
30+
});
31+
32+
test('2 words with the same value', function() {
33+
let inputFile = new File('./test/training/medium/scrabble/input/02 - 2 words with the same value.txt');
34+
35+
execute(inputFile.readline.bind(inputFile));
36+
37+
assert.strictEqual(
38+
console.log.getCall(0).args[0],
39+
'potsie'
40+
);
41+
});
42+
43+
test('2 words with different values', function() {
44+
let inputFile = new File('./test/training/medium/scrabble/input/03 - 2 words with different values.txt');
45+
46+
execute(inputFile.readline.bind(inputFile));
47+
48+
assert.strictEqual(
49+
console.log.getCall(0).args[0],
50+
'powers'
51+
);
52+
});
53+
54+
test('Many possibilities', function() {
55+
let inputFile = new File('./test/training/medium/scrabble/input/04 - many possibilities.txt');
56+
57+
execute(inputFile.readline.bind(inputFile));
58+
59+
assert.strictEqual(
60+
console.log.getCall(0).args[0],
61+
'waster'
62+
);
63+
});
64+
65+
test('Value better than size', function() {
66+
let inputFile = new File('./test/training/medium/scrabble/input/05 - value better than size.txt');
67+
68+
execute(inputFile.readline.bind(inputFile));
69+
70+
assert.strictEqual(
71+
console.log.getCall(0).args[0],
72+
'tween'
73+
);
74+
});
75+
76+
test('Valid word', function() {
77+
let inputFile = new File('./test/training/medium/scrabble/input/06 - valid word.txt');
78+
79+
execute(inputFile.readline.bind(inputFile));
80+
81+
assert.strictEqual(
82+
console.log.getCall(0).args[0],
83+
'aeiou'
84+
);
85+
});
86+
87+
test('Large dictionary 1', function() {
88+
let inputFile = new File('./test/training/medium/scrabble/input/07 - large dictionary 1.txt');
89+
90+
execute(inputFile.readline.bind(inputFile));
91+
92+
assert.strictEqual(
93+
console.log.getCall(0).args[0],
94+
'satire'
95+
);
96+
});
97+
98+
test('Large dictionary 2', function() {
99+
let inputFile = new File('./test/training/medium/scrabble/input/08 - large dictionary 2.txt');
100+
101+
execute(inputFile.readline.bind(inputFile));
102+
103+
assert.strictEqual(
104+
console.log.getCall(0).args[0],
105+
'pastern'
106+
);
107+
});
108+
109+
test('Cannot use letter twice', function() {
110+
let inputFile = new File('./test/training/medium/scrabble/input/09 - cannot use letter twice.txt');
111+
112+
execute(inputFile.readline.bind(inputFile));
113+
114+
assert.strictEqual(
115+
console.log.getCall(0).args[0],
116+
'powers'
117+
);
118+
});
119+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
5
2+
because
3+
first
4+
these
5+
could
6+
which
7+
hicquwh
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
10
2+
some
3+
first
4+
potsie
5+
day
6+
could
7+
postie
8+
from
9+
have
10+
back
11+
this
12+
sopitez
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
10
2+
after
3+
repots
4+
user
5+
powers
6+
these
7+
time
8+
know
9+
from
10+
could
11+
people
12+
tsropwe
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
10
2+
arrest
3+
rarest
4+
raster
5+
raters
6+
sartre
7+
starer
8+
waster
9+
waters
10+
wrest
11+
wrase
12+
arwtsre
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
5
2+
entire
3+
tween
4+
soft
5+
would
6+
test
7+
etiewrn
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
5
2+
qzyoq
3+
azejuy
4+
kqjsdh
5+
aeiou
6+
qsjkdh
7+
qzaeiou

0 commit comments

Comments
 (0)