Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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))
Ejemplo n.º 3
0
 def test_bigger(self):
     max_bits = 5
     number = 0b101001
     with self.assertRaises(OverflowError):
         normalize(number, max_bits)
Ejemplo n.º 4
0
 def test_equal(self):
     max_bits = 5
     number = 0b10100
     self.assertEqual(normalize(number, max_bits), 0b10100)