Skip to content

Commit

Permalink
fix(word generation): time mode tests causing errors when repeated
Browse files Browse the repository at this point in the history
  • Loading branch information
Miodec committed Apr 30, 2024
1 parent 7cfd434 commit 302d1ce
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions frontend/src/ts/test/words-generator.ts
Expand Up @@ -698,11 +698,30 @@ export async function getNextWord(
const repeated = previousGetNextWordReturns[wordIndex];

if (repeated === undefined) {
throw new WordGenError("Repeated word is undefined");
}
// if the repeated word is undefined, that means we are out of words from the previous test
// we need to either throw, or revert to random generation
// reverting should only happen in certain cases

let continueRandomGeneration = false;

if (
Config.mode === "time" ||
(Config.mode === "custom" && CustomText.getLimitMode() === "time")
) {
continueRandomGeneration = true;
}

console.debug("Repeated word: ", repeated);
return repeated;
if (!continueRandomGeneration) {
throw new WordGenError("Repeated word is undefined");
} else {
console.debug(
"Repeated word is undefined but random generation is allowed - getting random word"
);
}
} else {
console.debug("Repeated word: ", repeated);
return repeated;
}
}

const funboxFrequency = getFunboxWordsFrequency() ?? "normal";
Expand Down

0 comments on commit 302d1ce

Please sign in to comment.