def test_bigint(): AreEqual(BigInteger.Add(1,99999999999999999999999999999999999999999999999999999999999) ,BigInteger.Subtract(100000000000000000000000000000000000000000000000000000000001,1)) AreEqual(BigInteger.Multiply(400,500) , BigInteger.Divide(1000000,5)) AreEqual(BigInteger.Multiply(400,8) , BigInteger.LeftShift(400,3)) AreEqual(BigInteger.Divide(400,8) , BigInteger.RightShift(400,3)) AreEqual(BigInteger.RightShift(BigInteger.LeftShift(400,100),100) , 400) AreEqual(BigInteger.RightShift(BigInteger.LeftShift(-12345678987654321,100),100) , -12345678987654321) if is_net40: AssertError(ValueError, BigInteger.RightShift, 400, -100) AssertError(ValueError, BigInteger.LeftShift, 400, -100) AssertError(ValueError, BigInteger.RightShift, -12345678987654321, -100) AssertError(ValueError, BigInteger.LeftShift, -12345678987654321, -100) else: AreEqual(BigInteger.LeftShift(BigInteger.RightShift(400,-100),-100) , 400) AreEqual(BigInteger.LeftShift(BigInteger.RightShift(-12345678987654321,-100),-100) , -12345678987654321) AreEqual(BigInteger(-123456781234567812345678123456781234567812345678123456781234567812345678).OnesComplement().OnesComplement() , -123456781234567812345678123456781234567812345678123456781234567812345678) AreEqual(BigInteger(-1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678).OnesComplement() , -(-1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678 + 1 )) Assert(BigInteger.Xor(-1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678,BigInteger(-1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678).OnesComplement()) , -1) AreEqual(BigInteger.BitwiseAnd(0xff00ff00,BigInteger.BitwiseOr(0x00ff00ff,0xaabbaabb)) , BigInteger(0xaa00aa00)) AreEqual(BigInteger.Mod(BigInteger(-9999999999999999999999999999999999999999),1000000000000000000) , -BigInteger.Mod(9999999999999999999999999999999999999999,BigInteger(-1000000000000000000))) AreEqual(BigInteger.ToInt64(0x7fffffffffffffff) , 9223372036854775807) AssertError(OverflowError, BigInteger.ToInt64, 0x8000000000000000) AreEqual(BigInteger(-0).ToBoolean(p) , False ) AreEqual(BigInteger(-1212321.3213).ToBoolean(p) , True ) AreEqual(BigInteger(1212321384892342394723947).ToBoolean(p) , True ) AreEqual(BigInteger(0).ToChar(p) , Char.MinValue) AreEqual(BigInteger(65).ToChar(p) , IConvertible.ToChar('A', p)) AreEqual(BigInteger(0xffff).ToChar(p) , Char.MaxValue) AssertError(OverflowError, BigInteger(-1).ToChar, p) AreEqual(BigInteger(100).ToDouble(p) , 100.0) AreEqual(BigInteger(BigInteger(100).ToDouble(p)).ToSingle(p) , BigInteger(100.1213123).ToFloat()) Assert(BigInteger(100) != 100.32) AreEqual(BigInteger(100) , 100.0) Assert( 100.32 != BigInteger(100)) AreEqual(100.0 , BigInteger(100) )
def test_bigint(self): from System import Char, IConvertible from System.Numerics import BigInteger, Complex self.assertEqual(BigInteger.Add(long(1),99999999999999999999999999999999999999999999999999999999999) ,BigInteger.Subtract(100000000000000000000000000000000000000000000000000000000001,long(1))) self.assertEqual(BigInteger.Multiply(long(400),long(500)) , BigInteger.Divide(long(1000000),long(5))) self.assertEqual(BigInteger.Multiply(long(400),long(8)) , BigInteger.LeftShift(long(400),long(3))) self.assertEqual(BigInteger.Divide(long(400),long(8)) , BigInteger.RightShift(long(400),long(3))) self.assertEqual(BigInteger.RightShift(BigInteger.LeftShift(long(400),long(100)),long(100)) , long(400)) self.assertEqual(BigInteger.RightShift(BigInteger.LeftShift(-12345678987654321,long(100)),long(100)) , -12345678987654321) self.assertRaises(ValueError, BigInteger.RightShift, long(400), -long(100)) self.assertRaises(ValueError, BigInteger.LeftShift, long(400), -long(100)) self.assertRaises(ValueError, BigInteger.RightShift, -12345678987654321, -long(100)) self.assertRaises(ValueError, BigInteger.LeftShift, -12345678987654321, -long(100)) self.assertEqual(BigInteger(-123456781234567812345678123456781234567812345678123456781234567812345678).OnesComplement().OnesComplement() , -123456781234567812345678123456781234567812345678123456781234567812345678) self.assertEqual(BigInteger(-1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678).OnesComplement() , -(-1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678 + long(1) )) self.assertTrue(BigInteger.Xor(-1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678,BigInteger(-1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678).OnesComplement()) , -long(1)) self.assertEqual(BigInteger.BitwiseAnd(0xff00ff00,BigInteger.BitwiseOr(0x00ff00ff,0xaabbaabb)) , BigInteger(0xaa00aa00)) self.assertEqual(BigInteger.Mod(BigInteger(-9999999999999999999999999999999999999999),1000000000000000000) , -BigInteger.Mod(9999999999999999999999999999999999999999,BigInteger(-1000000000000000000))) self.assertEqual(BigInteger.ToInt64(0x7fffffffffffffff) , 9223372036854775807) self.assertRaises(OverflowError, BigInteger.ToInt64, 0x8000000000000000) self.assertEqual(BigInteger(-0).ToBoolean(self.p) , False ) self.assertEqual(BigInteger(-1212321.3213).ToBoolean(self.p) , True ) self.assertEqual(BigInteger(1212321384892342394723947).ToBoolean(self.p) , True ) self.assertEqual(BigInteger(long(0)).ToChar(self.p) , Char.MinValue) self.assertEqual(BigInteger(long(65)).ToChar(self.p) , IConvertible.ToChar('A', self.p)) self.assertEqual(BigInteger(0xffff).ToChar(self.p) , Char.MaxValue) self.assertRaises(OverflowError, BigInteger(-1).ToChar, self.p) self.assertEqual(BigInteger(100).ToDouble(self.p) , 100.0) self.assertEqual(BigInteger(BigInteger(100).ToDouble(self.p)).ToSingle(self.p) , BigInteger(100.1213123).ToFloat()) self.assertTrue(BigInteger(100) != 100.32) self.assertEqual(BigInteger(100) , 100.0) self.assertTrue( 100.32 != BigInteger(100)) self.assertEqual(100.0 , BigInteger(100) )