def test_basic(self): self.assertEqual("0", hr(0)) self.assertEqual("1 B", hr(1)) self.assertEqual("1 K", hr(2 ** 10)) self.assertEqual("1 M", hr(2 ** 20)) self.assertEqual("1 G", hr(2 ** 30)) self.assertEqual(">9000", hr(2 ** 100))
def test_no_exponent(self): for i in range(2 ** 10, 2 ** 20, 512): self.assertTrue('e' not in hr(i), "%d => %s" % (i, hr(i)))
def test_small(self): self.assertEqual("1000 B", hr(1000)) self.assertEqual("1.66 M", hr(1.66 * 2 ** 20)) self.assertEqual("1.46 K", hr(1500)) self.assertEqual("1.5 K", hr(2 ** 10 + 2 ** 9)) self.assertEqual("1.5 K", hr(2 ** 10 + 2 ** 9 - 1))
def test_big(self): self.assertEqual("1023 G", hr(2 ** 30 * 1023)) self.assertEqual("1024 G", hr(2 ** 40 - 1)) self.assertEqual("1 T", hr(2 ** 40))