Last active
April 8, 2021 22:51
-
-
Save LuisSaybe/e2f34314faf40edee946f8b1869b566d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getRandom(items) { | |
return items[Math.floor(Math.random() * items.length)]; | |
} | |
function assertEqual(a, b) { | |
if (JSON.stringify(a) !== JSON.stringify(b)) { | |
console.error(`${JSON.stringify(a)} does not equal ${JSON.stringify(b)}`); | |
} | |
} | |
function getUniqueRandoms(items, count) { | |
return [...new Set(getRandoms(items, count))]; | |
} | |
function getRandoms(items, count) { | |
const result = new Array(count); | |
for (let i = 0; i < count; i++) { | |
result[i] = getRandom(items); | |
} | |
return result; | |
} | |
function getRandomStrings(items, length, count) { | |
return Array.from(new Array(count)).map(() => randomString(items, length)); | |
} | |
function randomString(items, count) { | |
return Array.from(new Array(count)).map(() => getRandom(items)).join(''); | |
} | |
function getRandomsArray(items, length) { | |
return getRandoms(items, length).join(''); | |
} | |
function randomInts(length, min, max) { | |
return Array.from(new Array(length)).map(() => randomInt(min, max)); | |
} | |
function randomInt(min, max) { | |
return Math.floor(Math.random() * (max - min + 1) + min); | |
} | |
function getCommandTestCase() { | |
const commands = ["LRUCache"] | |
const data = [[randomInt(1, 10 ** 2)]]; | |
for (let i = 0 ; i < randomInt(0, 10 ** 3); i++) { | |
if (getRandom([true, false])) { | |
commands.push("put"); | |
data.push([randomInt(0, 10), randomInt(0, 10)]) | |
} else { | |
commands.push("get"); | |
data.push([randomInt(0, 10)]) | |
} | |
} | |
return [commands, data].map(JSON.stringify).join('\n') | |
} | |
function getTestCase() { | |
const matrix = []; | |
const letters = "abc"; | |
const length = 3; | |
for (let i = 0 ; i < length; i++) { | |
matrix.push(getRandoms(letters, length)); | |
} | |
const array = [...new Set(getRandomStrings(letters, 4, 10 ** 2))]; | |
return JSON.stringify(matrix) + '\n' + JSON.stringify(array); | |
} | |
function getTestCases() { | |
return Array.from(new Array(10 ** 3)).map(getTestCase).join('\n') | |
} | |
getTestCases() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment