def test_abs(self): a = IntNum(-1) b = IntNum(0) c = IntNum(1) self.assertEquals(abs(a), abs(c)) self.assertEquals(abs(a) - abs(c), abs(b))
def test_xor(self): a = IntNum(-234) b = IntNum(432) c = a ^ b self.assertEquals(a, -234) self.assertEquals(b, 432) self.assertEquals(c, -234 ^ 432)
def test_ixor(self): a = IntNum(-234) b = IntNum(432) a ^= b b ^= a a ^= b self.assertEquals(a, 432) self.assertEquals(b, -234)
def test_exceptions(self): self.assertRaises(ZeroDivisionError, IntNum(1).__div__, 0) IntNum(1) / 1 # make sure the above error is cleared try: IntNum(1) / 0 except ZeroDivisionError, err: self.assertEquals('divide by zero', str(err))
def test_cmp(self): a = IntNum(-1) b = IntNum(0) c = IntNum(1) self.assert_(a < b < c) self.assert_(a <= b <= c) self.assert_(c >= b >= a) self.assert_(c > b > a) self.assert_(a != b != c)
def test_to_from(self): for i in self.legal_values: self.assertEquals(i, int(IntNum(i))) self.assertEquals(i, long(IntNum(i)))