Skip to content

Commit

Permalink
add test for corrrectness of urls, and run and passed the test
Browse files Browse the repository at this point in the history
  • Loading branch information
yiwen101 committed Oct 1, 2023
1 parent 81497cd commit 00bdb27
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion javascript/searchRewriteTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ const writeFailureMessage = (key, searchResult) => {
failedTests.push(`${key}: result is ${searchResult}, expected occuer number is: ${indexSearchTestCase[key]}`);
}

export function testIndexSearch() {
export async function testIndexSearch() {
for (const [key, value] of Object.entries(indexSearchTestCase)) {
const result = search(key, indexTrie);
//console.log(result);
Expand All @@ -246,6 +246,27 @@ export function testIndexSearch() {
console.log(autoComplete("||", indexTrie));
console.log(search("|| (logical disjunction)", indexTrie));

async function testURLs() {
console.log("Testing urls");
for (const [key, urlArray] of Object.entries(urls)) {
for (const url of urlArray) {
try {
const response = await fetch(url);

if (!response.ok) {
console.log(key + ": " + url + " is not working");
}

} catch (error) {
console.error(key + ": " + url + " is not working");
}
}
}
console.log("Done testing urls");
}

await testURLs();

fs.writeFileSync("failedTests.txt", failedTests.join("\n"));
fs.writeFileSync("urls.txt", JSON.stringify(urls));
}
Expand Down

0 comments on commit 00bdb27

Please sign in to comment.