| 1 |
import { test } from 'node:test'; |
| 2 |
import assert from 'node:assert/strict'; |
| 3 |
import { formatSpeed, formatEta } from './s3.logic.ts'; |
| 4 |
|
| 5 |
test('formatSpeed switches from KB/s to MB/s at 1 MiB/s', () => { |
| 6 |
assert.equal(formatSpeed(500 * 1024), '500 KB/s'); |
| 7 |
assert.equal(formatSpeed(2.4 * 1024 * 1024), '2.4 MB/s'); |
| 8 |
}); |
| 9 |
|
| 10 |
test('formatEta uses seconds under a minute, m+s above', () => { |
| 11 |
assert.equal(formatEta(45), '45s'); |
| 12 |
assert.equal(formatEta(125), '2m 5s'); |
| 13 |
assert.equal(formatEta(0.2), '1s'); // ceil rounds up |
| 14 |
}); |
| 15 |
|
| 16 |
test('formatEta rounds once, so the remainder cannot reach a minute', () => { |
| 17 |
// The previous spelling read 125 as "3m 5s", rounding the minutes up and |
| 18 |
// then adding the remainder it had already absorbed. Rounding to whole |
| 19 |
// seconds first is what stops both that and a "1m 60s" from 119.5. |
| 20 |
assert.equal(formatEta(119.5), '2m 0s'); |
| 21 |
assert.equal(formatEta(59.5), '1m 0s'); |
| 22 |
assert.equal(formatEta(3600), '60m 0s'); |
| 23 |
}); |
| 24 |
|