def testExceptions(self): """ Test throwing exception. """ with self.assertRaises(BasesError): Nats.convert_from_int(-32, 2) with self.assertRaises(BasesError): Nats.convert_from_int(32, -2) with self.assertRaises(BasesError): Nats.convert([1], 1, 2) with self.assertRaises(BasesError): Nats.convert([1], 2, 1) with self.assertRaises(BasesError): Nats.convert_to_int([1], 1) with self.assertRaises(BasesError): Nats.convert_to_int([-1], 2) with self.assertRaises(BasesError): Nats.carry_in([-1], 1, 2) with self.assertRaises(BasesError): Nats.carry_in([1], -1, 2) with self.assertRaises(BasesError): Nats.carry_in([1], 1, 1) with self.assertRaises(BasesError): Nats.roundTo([1], 0, 2, RoundingMethods.ROUND_DOWN) with self.assertRaises(BasesError): Nats.roundTo([3], 2, 2, RoundingMethods.ROUND_DOWN) with self.assertRaises(BasesError): Nats.roundTo([1], 2, 2, None)
def test_from_other(self, nat, to_base): """Test roundtrip from number in arbitrary base.""" (subject, from_base) = nat result = Nats.convert(subject, from_base, to_base) self.assertEqual( Nats.convert_to_int(result, to_base), Nats.convert_to_int(subject, from_base), )
def test_exceptions(self): """Test throwing exception.""" with self.assertRaises(BasesError): Nats.convert_from_int(-32, 2) with self.assertRaises(BasesError): Nats.convert_from_int(32, -2) with self.assertRaises(BasesError): Nats.convert([1], 1, 2) with self.assertRaises(BasesError): Nats.convert([1], 2, 1) with self.assertRaises(BasesError): Nats.convert_to_int([1], 1) with self.assertRaises(BasesError): Nats.convert_to_int([-1], 2) with self.assertRaises(BasesError): Nats.carry_in([-1], 1, 2) with self.assertRaises(BasesError): Nats.carry_in([1], -1, 2) with self.assertRaises(BasesError): Nats.carry_in([1], 1, 1)
def testFromOther(self, nat, to_base): """ Test roundtrip from number in arbitrary base. """ (subject, from_base) = nat result = Nats.convert(subject, from_base, to_base) assert Nats.convert_to_int(result, to_base) == \ Nats.convert_to_int(subject, from_base)