test_MeasurementUtils_fuzzByteSize.js (1744B)
1 /* Any copyright is dedicated to the Public Domain. 2 https://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 add_task(async function test_minimumFallback() { 7 const fuzzed = MeasurementUtils.fuzzByteSize(250, 1000); 8 Assert.equal( 9 fuzzed, 10 1000, 11 "Should fall back to the `nearest` value when `bytes` are below `nearest`" 12 ); 13 }); 14 15 add_task(async function test_roundUp() { 16 const fuzzed = MeasurementUtils.fuzzByteSize(1500, 1000); 17 Assert.equal( 18 fuzzed, 19 2000, 20 "Should round up to 2000 when `bytes` is 1500 since that is the nearest 1000 bytes" 21 ); 22 }); 23 24 add_task(async function test_roundDown() { 25 const fuzzed = MeasurementUtils.fuzzByteSize(1499, 1000); 26 Assert.equal( 27 fuzzed, 28 1000, 29 "Should round down to 1000 when `bytes` is 1499 since that is the nearest 1000 bytes" 30 ); 31 }); 32 33 add_task(async function test_roundDownSmallerUnit() { 34 const fuzzed = MeasurementUtils.fuzzByteSize(1025, 10); 35 Assert.equal( 36 fuzzed, 37 1030, 38 "Should round 1025 up to 1030 since that is the nearest 10 bytes" 39 ); 40 }); 41 42 add_task(async function test_roundDownSmallerUnit() { 43 const fuzzed = MeasurementUtils.fuzzByteSize(1024, 10); 44 Assert.equal( 45 fuzzed, 46 1020, 47 "Should round 1024 down to 1020 since that is the nearest 10 bytes" 48 ); 49 }); 50 51 add_task(async function test_roundUpBinary() { 52 const fuzzed = MeasurementUtils.fuzzByteSize(1500, 1024); 53 Assert.equal( 54 fuzzed, 55 1024, 56 "Should round 1500 down to 1024 nearest kibibyte value" 57 ); 58 }); 59 60 add_task(async function test_roundDownBinary() { 61 const fuzzed = MeasurementUtils.fuzzByteSize(1800, 1024); 62 Assert.equal( 63 fuzzed, 64 2048, 65 "Should round 1800 up to 2048 since that is the nearest kibibyte value" 66 ); 67 });