From 354660ff7e700d85bd4ed4c936428f24a85e9d72 Mon Sep 17 00:00:00 2001 From: Tiago Ilieve Date: Thu, 10 Oct 2024 14:39:19 -0300 Subject: [PATCH] human: add tests --- human/index.html | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/human/index.html b/human/index.html index d5e7967..9ae0e2e 100644 --- a/human/index.html +++ b/human/index.html @@ -65,6 +65,31 @@

Human-Readable Bytes Conversion

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;