Skip to content

Commit

Permalink
human: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
myhro committed Oct 10, 2024
1 parent 9044305 commit 354660f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions human/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,31 @@ <h1>Human-Readable Bytes Conversion</h1>
const parsedValue = parseInt(pastedData, 10);
updateOutput(parsedValue);
});

function runTests() {
const testCases = [
{ number: 810, human: '810 Bytes' },
{ number: 4582, human: '4.47 KB' },
{ number: 26830, human: '26.2 KB' },
{ number: 473638, human: '462.54 KB' },
{ number: 5417973, human: '5.17 MB' },
{ number: 13630656, human: '13 MB' },
{ number: 84853185, human: '80.92 MB' },
{ number: 6203355136, human: '5.78 GB' },
];

testCases.forEach(testCase => {
let result = bytesToHumanReadable(testCase.number);

if (result !== testCase.human) {
console.error(`Test failed for number: ${testCase.number}. Expected: ${testCase.human}, but got: ${result}`);
} else {
console.log(`Test passed for number: ${testCase.number}`);
}
});
}

window.onload = runTests;
</script>
</body>
</html>

0 comments on commit 354660f

Please sign in to comment.