From 00bdb27bd9926117ffbf5da8012e2a5c3418357c Mon Sep 17 00:00:00 2001 From: yiwen101 Date: Sun, 1 Oct 2023 17:29:01 +0800 Subject: [PATCH] add test for corrrectness of urls, and run and passed the test --- javascript/searchRewriteTest.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/javascript/searchRewriteTest.js b/javascript/searchRewriteTest.js index 94e86f573..e2a23ffd8 100644 --- a/javascript/searchRewriteTest.js +++ b/javascript/searchRewriteTest.js @@ -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); @@ -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)); }