def test_zero_start(self): fraction = normalize(0b000101) >> 3 yk, t = partition(fraction, 4) self.assertTrue(yk.positive) self.assertEqual(yk.whole, 1) self.assertEqual(yk.fraction, normalize(0b0001) >> 3) self.assertTrue(t.positive) self.assertEqual(t.whole, 0) self.assertEqual(t.fraction, normalize(1) >> 1)
def test_one_zero(self): fraction = normalize(0b101001) yk, t = partition(fraction, 4) self.assertTrue(yk.positive) self.assertEqual(yk.whole, 1) self.assertEqual(yk.fraction, normalize(0b1011)) self.assertFalse(t.positive) self.assertEqual(t.whole, 0) self.assertEqual(t.fraction, -normalize(0b11))
def test_bigger(self): max_bits = 5 number = 0b101001 with self.assertRaises(OverflowError): normalize(number, max_bits)
def test_equal(self): max_bits = 5 number = 0b10100 self.assertEqual(normalize(number, max_bits), 0b10100)