Skip to content

Commit b695955

Browse files
fix: add comma and period to specials funbox (monkeytypegame#6870) (@radouane-tamouss) (monkeytypegame#6887)
fix: add comma and period to specials funbox (monkeytypegame#6870) (@radouane-tamouss) - Add missing ',' and '.' characters to specials array in getSpecials() - Add comprehensive tests for getSpecials() function - Fixes issue where comma and period never appeared in specials funbox Closes monkeytypegame#6870 ### Description This PR fixes issue monkeytypegame#6870 where the "specials" funbox was missing comma (,) and period (.) characters. Users reported that these common punctuation marks never appeared when using the specials funbox, making it impossible to practice typing them in that mode. **Changes made:** 1. Added ',' and '.' to the `specials` array in the `getSpecials()` function 2. Added comprehensive unit tests to verify the fix works correctly and prevent future regressions 3. Tests ensure all special characters (including comma and period) can be generated **Testing:** - Added unit tests that specifically verify comma and period are included - Tests run multiple iterations to account for randomness in character generation - Verified all existing functionality remains unchanged ### Checks - [x] Check if any open issues are related to this PR; if so, be sure to tag them below. - [x] Make sure the PR title follows the Conventional Commits standard. (https://www.conventionalcommits.org for more info) - [x] Make sure to include your GitHub username prefixed with @ inside parentheses at the end of the PR title. Closes monkeytypegame#6870
1 parent 057fdf3 commit b695955

File tree

2 files changed

+67
-32
lines changed

2 files changed

+67
-32
lines changed

frontend/__tests__/utils/generate.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,31 @@ describe("hexadecimal", () => {
1414
expect(hex).toMatch(/^[0-9a-f]+$/);
1515
});
1616
});
17+
18+
describe("specials", () => {
19+
it("should generate valid special character strings", () => {
20+
let foundComma = false;
21+
let foundPeriod = false;
22+
const expectedSpecials = generate.__testing.specials;
23+
24+
// Generate 1000 special "words" and check each
25+
for (let i = 0; i < 1000; i++) {
26+
const specials = generate.getSpecials();
27+
28+
// Check min/max length (1-7 as per implementation)
29+
expect(specials.length).toBeGreaterThanOrEqual(1);
30+
expect(specials.length).toBeLessThanOrEqual(7);
31+
32+
// Check that every character is from the expected specials array
33+
for (const char of specials) {
34+
expect(expectedSpecials).toContain(char);
35+
if (char === ",") foundComma = true;
36+
if (char === ".") foundPeriod = true;
37+
}
38+
}
39+
40+
// Ensure comma and period were found during the test
41+
expect(foundComma).toBe(true);
42+
expect(foundPeriod).toBe(true);
43+
});
44+
});

frontend/src/ts/utils/generate.ts

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -128,41 +128,44 @@ export function getASCII(): string {
128128
* Generates a random string of special characters.
129129
* @returns The generated string of special characters.
130130
*/
131+
const specials = [
132+
"`",
133+
"~",
134+
"!",
135+
"@",
136+
"#",
137+
"$",
138+
"%",
139+
"^",
140+
"&",
141+
"*",
142+
"(",
143+
")",
144+
"-",
145+
"_",
146+
"=",
147+
"+",
148+
"{",
149+
"}",
150+
"[",
151+
"]",
152+
"'",
153+
'"',
154+
"/",
155+
"\\",
156+
"|",
157+
"?",
158+
";",
159+
":",
160+
">",
161+
"<",
162+
",",
163+
".",
164+
];
165+
131166
export function getSpecials(): string {
132167
const randLen = randomIntFromRange(1, 7);
133168
let ret = "";
134-
const specials = [
135-
"`",
136-
"~",
137-
"!",
138-
"@",
139-
"#",
140-
"$",
141-
"%",
142-
"^",
143-
"&",
144-
"*",
145-
"(",
146-
")",
147-
"-",
148-
"_",
149-
"=",
150-
"+",
151-
"{",
152-
"}",
153-
"[",
154-
"]",
155-
"'",
156-
'"',
157-
"/",
158-
"\\",
159-
"|",
160-
"?",
161-
";",
162-
":",
163-
">",
164-
"<",
165-
];
166169
for (let i = 0; i < randLen; i++) {
167170
ret += Arrays.randomElementFromArray(specials);
168171
}
@@ -188,3 +191,7 @@ export function getNumbers(len: number): string {
188191
}
189192
return ret;
190193
}
194+
195+
export const __testing = {
196+
specials,
197+
};

0 commit comments

Comments
 (0)