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) )
def test_bigint(self): from System import Int64, Boolean, Char, Double, Single, IConvertible from System.Numerics import BigInteger self.assertEqual( BigInteger.Add( big(1), 99999999999999999999999999999999999999999999999999999999999), BigInteger.Subtract( 100000000000000000000000000000000000000000000000000000000001, big(1))) self.assertEqual(BigInteger.Multiply(big(400), big(500)), BigInteger.Divide(big(1000000), big(5))) self.assertEqual(BigInteger.Multiply(big(400), big(8)), big(400) << big(3)) self.assertEqual(BigInteger.Divide(big(400), big(8)), big(400) >> big(3)) self.assertEqual((big(400) << big(100)) >> big(100), big(400)) self.assertEqual((-12345678987654321 << big(100)) >> big(100), -12345678987654321) self.assertRaises(ValueError, lambda x, y: x >> y, big(400), -big(100)) self.assertRaises(ValueError, lambda x, y: x << y, big(400), -big(100)) self.assertRaises(ValueError, lambda x, y: x >> y, -12345678987654321, -big(100)) self.assertRaises(ValueError, lambda x, y: x << y, -12345678987654321, -big(100)) self.assertEqual( ~(~big( -123456781234567812345678123456781234567812345678123456781234567812345678 )), -123456781234567812345678123456781234567812345678123456781234567812345678 ) self.assertEqual( ~big( -1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678 ), -(-1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678 + big(1))) self.assertTrue( big(-1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678 ) ^ (~big( -1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678 )), -big(1)) self.assertEqual( big(0xff00ff00) & (big(0x00ff00ff) | big(0xaabbaabb)), big(0xaa00aa00)) self.assertEqual( big(-9999999999999999999999999999999999999999) % 1000000000000000000, -(9999999999999999999999999999999999999999 % big(-1000000000000000000))) self.assertEqual(Int64(big(0x7fffffffffffffff)), 9223372036854775807) self.assertRaises(OverflowError, Int64, big(0x8000000000000000)) self.assertEqual(Boolean(big(-0)), False) self.assertEqual(Boolean(big(int(-1212321.3213))), True) self.assertEqual(Boolean(big(1212321384892342394723947)), True) self.assertEqual(Char(big(0)), Char.MinValue) self.assertEqual(Char(big(65)), IConvertible.ToChar('A', self.p)) self.assertEqual(Char(big(0xffff)), Char.MaxValue) self.assertRaises(OverflowError, Char, big(-1)) self.assertEqual(Double(big(100)), 100.0) self.assertEqual(Single(big(100)), 100.0) self.assertEqual(Single(big(100)), IConvertible.ToSingle(int(100.1213123), self.p)) self.assertTrue(big(100) != 100.32) self.assertEqual(big(100), 100.0) self.assertTrue(100.32 != big(100)) self.assertEqual(100.0, big(100))