Skip to content

Commit 32dae1b

Browse files
committed
test: pin the first-flip carry boundary (decimal/traditional/binary)
Per review on #600: the rollover tests only pinned the far end (999_999 / 1024**2 - 1), not the first value whose mantissa rounds up to base. Add the carry boundary for all three formatters so the fix's behavior at the rollover point is locked down.
1 parent 97c5fea commit 32dae1b

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

tests/test_filesize.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,26 @@ def test_decimal(self):
4646
self.assertEqual(filesize.decimal(1200 * 1000), "1.2 MB")
4747

4848
def test_rollover_decimal(self):
49+
# First value whose mantissa rounds up to base — the carry boundary
50+
self.assertEqual(filesize.decimal(999_949), "999.9 kB")
51+
self.assertEqual(filesize.decimal(999_950), "1.0 MB")
4952
# Mantissa rounds up to base — must carry to the next suffix
5053
self.assertEqual(filesize.decimal(999_999), "1.0 MB")
5154
self.assertEqual(filesize.decimal(999_999_999), "1.0 GB")
5255
self.assertEqual(filesize.decimal(999_999_999_999), "1.0 TB")
5356

5457
def test_rollover_traditional(self):
58+
# First-flip carry boundary: 1,023.95 KB rounds up to 1,024.0 KB -> 1.0 MB
59+
self.assertEqual(filesize.traditional(1_048_524), "1,023.9 KB")
60+
self.assertEqual(filesize.traditional(1_048_525), "1.0 MB")
5561
# 1024**2 - 1 bytes is 1023.999 KB, which rounds to 1,024.0 KB
5662
self.assertEqual(filesize.traditional(1024**2 - 1), "1.0 MB")
5763
self.assertEqual(filesize.traditional(1024**3 - 1), "1.0 GB")
5864

5965
def test_rollover_binary(self):
66+
# First-flip carry boundary: 1,023.95 KiB rounds up to 1,024.0 KiB -> 1.0 MiB
67+
self.assertEqual(filesize.binary(1_048_524), "1,023.9 KiB")
68+
self.assertEqual(filesize.binary(1_048_525), "1.0 MiB")
6069
self.assertEqual(filesize.binary(1024**2 - 1), "1.0 MiB")
6170
self.assertEqual(filesize.binary(1024**3 - 1), "1.0 GiB")
6271

0 commit comments

Comments
 (0)