def test_long_log(self): """logon big ints should work""" self.assertEqual(round(math.log10(10 ** 1000), 5), 1000.0) self.assertEqual(round(math.log(10 ** 1000), 5), 2302.58509) self.assertEqual(round(math.log10(18446744073709551615), 5), 19.26592) self.assertEqual(round(math.log(18446744073709551615), 5), 44.36142) self.assertEqual(round(math.log10(18446744073709551616), 5), 19.26592) self.assertEqual(round(math.log(18446744073709551616), 5), 44.36142) self.assertEqual(round(math.log10(18446744073709551614), 5), 19.26592) self.assertEqual(round(math.log(18446744073709551614), 5), 44.36142) # log in a new base self.assertEqual(round(math.log(2 ** 1000, 2), 5), 1000.0) self.assertRaises(ValueError, math.log, long(0)) self.assertRaises(ValueError, math.log, long(-1)) self.assertEqual(math.log(long(2), 1e666), 0.0) self.assertRaises(ValueError, math.log, long(2), -1e666) self.assertRaises(ZeroDivisionError, math.log, long(2), 1.0) #Make sure that an object is converted to float before being passed into log funcs class N(object): def __float__(self): return 10.0 def __long__(self): return 100 self.assertEqual(round(math.log10(N()), 5),1.0) self.assertEqual(round(math.log(N()), 5),2.30259)
def test_hex_conversions(self): # Test hex conversions. CPython 2.5 uses capital L, lowercase letters a...f) s = hex(long(27)) # 0x1b self.assertTrue(s == "0x1b", "27: Expect lowercase digits. Received: %s." % (s)) s = hex(-long(27)) self.assertTrue(s == "-0x1b", "-27: Expect lowercase digits. Received: %s." % (s))
def test_functionality(self): objects = [ None, True, False, '', 'a', 'abc', -3, 0, 10, 254, -255, 256, 257, 65534, 65535, -65536, 3.1415926, long(0), -1234567890123456789, 2**33, [], [[]], [[], []], ['abc'], [1, 2], tuple(), (), ( (), (), ), (1, ), (1, 2, 3), {}, { 'abc': {} }, { 1: 2 }, { 1: 2, 4: '4', 5: None }, 0 + 1j, 2 - 3.23j, set(), set(['abc', -5]), set([1, (2.1, long(3)), frozenset([5]), 'x']), frozenset(), frozenset(['abc', -5]), frozenset([1, (2.1, long(3)), frozenset([5]), 'x']) ] if is_cli: import System objects.extend([ System.Single.Parse('-2345678'), System.Int64.Parse('2345678'), ]) # dumps / loads for x in objects: s = marshal.dumps(x) x2 = marshal.loads(s) self.assertEqual(x, x2) # on 64-bit the order in set/frozenset isn't the same after dumps/loads if (is_64 or is_osx) and isinstance(x, (set, frozenset)): continue s2 = marshal.dumps(x2) self.assertEqual(s, s2) # dump / load for x in objects: with open(self.tfn, 'wb') as f: marshal.dump(x, f) with open(self.tfn, 'rb') as f: x2 = marshal.load(f) self.assertEqual(x, x2)
def test_more_complex(self): self.assertEqual((12+3j)/long(3), (4+1j)) self.assertEqual(3j - long(5), -5+3j) if is_cli: self.assertEqual(3j - Int64(), 3j) self.assertRaises(TypeError, (lambda:3j-[])) if is_cli: self.assertEqual(pow(5j, Int64()), (1+0j)) self.assertEqual(pow(5j, long(0)), (1+0j)) self.assertRaises(TypeError, (lambda:pow(5j, []))) if is_cli: self.assertEqual(5j * Int64(), 0) self.assertEqual(5j * long(3), 15j) self.assertRaises(TypeError, (lambda:(5j*[])))
def test_cp34770(self): # Entries added with Int64/UInt64 should be findable with Python long from System import Int64, UInt64 i64 = Int64(1110766100758387874) u64 = UInt64(9223372036854775808) m = {} m[i64] = 'a' self.assertEqual(m[long(1110766100758387874)], 'a') m[u64] = 'b' self.assertEqual(m[long(9223372036854775808)], 'b')
def test_cp9350(self): for i in [1, long(1)]: a = array.array('B', [0]) * i self.assertEqual(a, array.array('B', [0])) for i in [2, long(2)]: a = array.array('B', [0]) * i self.assertEqual(a, array.array('B', [0, 0])) for i in [2**8, long(2**8)]: a = array.array('B', [1]) * i self.assertEqual(a, array.array('B', [1] * 2**8))
def test_negated_comparisons(self): self.assertTrue(not (20 == False)) self.assertTrue(not (20 == None)) self.assertTrue(not (False == 20)) self.assertTrue(not (None == 20)) self.assertTrue(not (20 == 'a')) self.assertTrue(not ('a' == 20)) self.assertTrue(not (2.5 == None)) self.assertTrue(not (20 == (2,3))) self.assertEqual(long(1234793454934), 1234793454934) self.assertEqual(4 ** -2, 0.0625) self.assertEqual(long(4) ** -2, 0.0625)
def test_time_replace(self): # cp35075 t = datetime.time().replace(microsecond=long(1000)) self.assertEqual(t.microsecond, 1000) self.assertRaises(ValueError, datetime.time().replace, microsecond=long(10000000)) self.assertRaises(OverflowError, datetime.time().replace, microsecond=long(1000000000000)) self.assertRaises(TypeError, datetime.time().replace, microsecond=1000.1)
def test_date_replace(self): # cp35075 d = datetime.date.today().replace(year=long(2000)) self.assertEqual(d.year, 2000) self.assertRaises(ValueError, datetime.date.today().replace, year=long(10000000)) self.assertRaises(OverflowError, datetime.date.today().replace, year=long(1000000000000)) self.assertRaises(TypeError, datetime.date.today().replace, year=1000.1)
def test_conversions(self): success = False try: nstr("Hi") except NameError: success = True self.assertEqual(success, True) success = False try: zip2([1, 2, 3], [4, 5, 6]) except NameError: success = True self.assertEqual(success, True) self.assertEqual(bytes(), b"") self.assertEqual(str(), u"") self.assertEqual(oct(long(0)), "0o0") self.assertEqual(hex(12297829382473034410), "0xaaaaaaaaaaaaaaaa") #10581 self.assertEqual(hex(-long(1)), "-0x1") self.assertEqual(long("-01"), -1) self.assertEqual(int(" 1 "), 1) with self.assertRaises(ValueError): int(" - 1 ") with self.assertRaises(ValueError): long(" - 1 ") for f in [long, int]: self.assertRaises(ValueError, f, 'p') self.assertRaises(ValueError, f, 't') self.assertRaises(ValueError, f, 'a') self.assertRaises(ValueError, f, '3.2') self.assertRaises(ValueError, f, '0x0R') self.assertRaises(ValueError, f, '09', 8) self.assertRaises(ValueError, f, '0A') self.assertRaises(ValueError, f, '0x0G') self.assertRaises(ValueError, int, '1l') self.assertEqual( int(1e100), 10000000000000000159028911097599180468360808563945281389781327557747838772170381060813469985856815104 ) self.assertEqual( int(-1e100), -10000000000000000159028911097599180468360808563945281389781327557747838772170381060813469985856815104 ) self.assertEqual(pow(2, 3), 8)
def test_trunc(self): import sys, math test_values = [ -1, 0, 1, long(-1), long(0), long(1), -1.0, 0.0, 1.0, sys.maxsize + 0.5, -sys.maxsize - 0.5, 9876543210, -9876543210, -1e100, 1e100 ] for value in test_values: self.assertEqual(long(value), math.trunc(value)) self.assertTrue(isinstance(math.trunc(value), int))
def test_big_1(self): from System import SByte, Byte, Int16, UInt16, Int32, UInt32, Int64, UInt64 from System.Numerics import BigInteger for (a, m, t, x) in [(7, "ToSByte", SByte, 2), (8, "ToByte", Byte, 0), (15, "ToInt16", Int16, 2), (16, "ToUInt16", UInt16, 0), (31, "ToInt32", Int32, 2), (32, "ToUInt32", UInt32, 0), (63, "ToInt64", Int64, 2), (64, "ToUInt64", UInt64, 0)]: b = BigInteger(-x**a) left = getattr(b, m)(self.p) right = t.MinValue self.assertEqual(left, right) b = BigInteger(2**a - 1) left = getattr(b, m)(self.p) right = t.MaxValue self.assertEqual(left, right) b = BigInteger(long(0)) left = getattr(b, m)(self.p) right = t.MaxValue - t.MaxValue self.assertEqual(left, 0) self.assertRaises(OverflowError, getattr(BigInteger(2**a), m), self.p) self.assertRaises(OverflowError, getattr(BigInteger(-1 - x**a), m), self.p)
def test_neg_type___clrtype__(self): ''' Tests out negative type.__clrtype__ cases. ''' import System #Number of params self.assertRaisesMessage( TypeError, "__clrtype__() takes exactly 1 argument (0 given)", type.__clrtype__) self.assertRaisesMessage( TypeError, "__clrtype__() takes exactly 1 argument (2 given)", type.__clrtype__, None, None) self.assertRaisesMessage( TypeError, "__clrtype__() takes exactly 1 argument (3 given)", type.__clrtype__, None, None, None) #Wrong param type self.assertRaisesPartialMessage(TypeError, ", got NoneType", type.__clrtype__, None) self.assertRaisesPartialMessage(TypeError, ", got float", type.__clrtype__, 3.14) for x in [ None, [], (None, ), Exception("message"), 3.14, long(3), 0, 5j, "string", u"string", True, System, _os, os, lambda: 3.14 ]: self.assertRaises(TypeError, type.__clrtype__, x) #Shouldn't be able to set __clrtype__ to something else self.assertRaisesMessage( AttributeError, "attribute '__clrtype__' of 'type' object is read-only", setattr, type, "__clrtype__", None)
def test_big_2(self): from System import Int32, UInt32, Int64, UInt64 from System.Numerics import BigInteger for (a, m, t, x) in [(31, "ToInt32", Int32, 2), (32, "ToUInt32", UInt32, 0), (63, "ToInt64", Int64, 2), (64, "ToUInt64", UInt64, 0)]: b = BigInteger(-x**a) left = getattr(b, m)() right = t.MinValue self.assertEqual(left, right) b = BigInteger(2**a - 1) left = getattr(b, m)() right = t.MaxValue self.assertEqual(left, right) b = BigInteger(long(0)) left = getattr(b, m)() right = t.MaxValue - t.MaxValue self.assertEqual(left, right) self.assertRaises(OverflowError, getattr(BigInteger(2**a), m)) self.assertRaises(OverflowError, getattr(BigInteger(-1 - x**a), m))
def test_complex(self): from System.Numerics import BigInteger, Complex self.assertEqual( Complex.Add(Complex(BigInteger(long(9999)), -1234), Complex.Conjugate(Complex(9999, -1234))), Complex.Multiply.Overloads[complex, complex](BigInteger(long(9999)), 2)) self.assertEqual( Complex.Add(Complex(99999.99e-200, 12345.88e+100), Complex.Negate(Complex(99999.99e-200, 12345.88e+100))), Complex.Subtract(Complex(99999.99e-200, 12345.88e+100), Complex(99999.99e-200, 12345.88e+100))) self.assertEqual(Complex.Divide(4 + 2j, 2), (2 + 1j)) self.assertTrue( not hasattr(Complex, "Mod") ) #IP 1.x had limited support for modulo which has been removed
def test_pep19546(self): ''' Just a small sanity test. CPython's test_int.py covers this PEP quite well. ''' #Octal self.assertEqual(0O21, 17) self.assertEqual(0O21, 0o21) self.assertEqual(0o0, 0) self.assertEqual(-0o1, -1) self.assertEqual(0o17777777776, 2147483646) self.assertEqual(0o17777777777, 2147483647) self.assertEqual(0o20000000000, 2147483648) self.assertEqual(-0o17777777777, -2147483647) self.assertEqual(-0o20000000000, -2147483648) self.assertEqual(-0o20000000001, -2147483649) #Binary self.assertEqual(0B11, 3) self.assertEqual(0B11, 0b11) self.assertEqual(0b0, 0) self.assertEqual(-0b1, -1) self.assertEqual(0b1111111111111111111111111111110, 2147483646) self.assertEqual(0b1111111111111111111111111111111, 2147483647) self.assertEqual(0b10000000000000000000000000000000, 2147483648) self.assertEqual(-0b1111111111111111111111111111111, -2147483647) self.assertEqual(-0b10000000000000000000000000000000, -2147483648) self.assertEqual(-0b10000000000000000000000000000001, -2147483649) #bin and oct test_cases = [ (0B11, "0b11", "0o3"), (2147483648, "0b10000000000000000000000000000000", "0o20000000000"), (long(-2147483649), "-0b10000000000000000000000000000001", "-0o20000000001"), (long(-1), "-0b1", "-0o1"), (-0b10000000000000000000000000000000, "-0b10000000000000000000000000000000", "-0o20000000000"), (-0o17777777777, "-0b1111111111111111111111111111111", "-0o17777777777"), (0o17777777777, "0b1111111111111111111111111111111", "0o17777777777"), ] for val, bin_exp, oct_exp in test_cases: self.assertEqual(bin(val), bin_exp) self.assertEqual(oct(val), oct_exp)
def test_neg_clrtype_returns_nonsense_values(self): ''' The __clrtype__ implementation returns invalid values. ''' global called import System for x, expected_msg in [ [[], "expected Type, got list"], [(None, ), "expected Type, got tuple"], [True, "expected Type, got bool"], [False, "expected Type, got bool"], [3.14, "expected Type, got float"], ["a string", "expected Type, got str"], [System.UInt16(32), "expected Type, got UInt16"], [long(1), "expected Type, got long"], ]: called = False class MyType(type): def __clrtype__(self): global called called = True return x try: class X(object, metaclass=MyType): pass Fail( "Arbitrary return values of __clrtype__ should not be allowed: " + str(x)) except TypeError as e: self.assertEqual(str(e), expected_msg) finally: self.assertEqual(called, True) #http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=23244 called = False class MyType(type): def __clrtype__(self): global called called = True return None try: class X(object, metaclass=MyType): pass Fail("Arbitrary return values of __clrtype__ are not allowed: ", +str(x)) except ValueError as e: self.assertEqual(str(e), "__clrtype__ must return a type, not None") finally: self.assertEqual(called, True)
def test_kwargs_primitives(self): if sys.version_info >= (3,7): # starting with 3.7 these are no longer valid keyword arguments with self.assertRaises(TypeError): int(x=1) with self.assertRaises(TypeError): float(x=2) with self.assertRaises(TypeError): long(x=3) with self.assertRaises(TypeError): tuple(sequence=range(3)) with self.assertRaises(TypeError): list(sequence=(0,1)) else: self.assertEqual(int(x=1), 1) self.assertEqual(float(x=2), 2.0) self.assertEqual(long(x=3), 3) self.assertEqual(tuple(sequence=range(3)), (0,1,2)) self.assertEqual(list(sequence=(0,1)), [0,1]) self.assertEqual(complex(imag=4, real=3), 3 + 4j) self.assertEqual(str(object=5), '5') self.assertEqual(str(object=b'a', errors='strict'), 'a')
def test_zero_division(self): self.assertRaises(ZeroDivisionError, (lambda: (0 ** -1))) self.assertRaises(ZeroDivisionError, (lambda: (0.0 ** -1))) self.assertRaises(ZeroDivisionError, (lambda: (0 ** -1.0))) self.assertRaises(ZeroDivisionError, (lambda: (0.0 ** -1.0))) self.assertRaises(ZeroDivisionError, (lambda: (False ** -1))) self.assertRaises(ZeroDivisionError, (lambda: (long(0) ** -(2 ** 65)))) self.assertRaises(ZeroDivisionError, (lambda: (0j ** -1))) self.assertRaises(ZeroDivisionError, (lambda: (0j ** 1j)))
def test_abs(self): self.assertRaises(TypeError, abs, None) #long integer passed to abs self.assertEqual(long(22), abs(long(22))) self.assertEqual(long(22), abs(-long(22))) #bool passed to abs self.assertEqual(1, abs(True)) self.assertEqual(0, abs(False)) #__abs__ defined on user type class myclass: def __abs__(self): return "myabs" c = myclass() self.assertEqual("myabs", abs(c))
def test__bool__(self): class ClassWithBool: def __init__(self, val): self.val = val def __bool__(self): return self.val class ClassWithLen: def __init__(self, val): self.val = val def __len__(self): return self.val class MyIndex: def __init__(self, val): self.val = val def __index__(self): return self.val class MyLong(long): pass bool_cases = [ (True, True), (False, False), (MyIndex(0), TypeError), ] len_cases = [ (1, True), (0, False), (0.0, TypeError), (-1, ValueError), (1 << 64, OverflowError), ] cases = [] cases += [(ClassWithBool(x), y) for x, y in bool_cases] cases += [(ClassWithLen(x), y) for x, y in len_cases] cases += [(ClassWithLen(long(x)), y) for x, y in len_cases if isinstance(x, int)] cases += [(ClassWithLen(MyLong(x)), y) for x, y in len_cases if isinstance(x, int)] cases += [(ClassWithLen(MyIndex(x)), y) for x, y in len_cases] for val, res in cases: if type(res) == type: with self.assertRaises(res): bool(val) with self.assertRaises(res): not val else: self.assertEqual(bool(val), res) self.assertEqual(not val, not res)
def test_extensible_math(self): operators = ['__add__', '__sub__', '__pow__', '__mul__', '__div__', '__floordiv__', '__truediv__', '__mod__'] opSymbol = ['+', '-', '**', '*', '/', '//', '/', '%'] types = [] for baseType in [(int, (100,2)), (long, (long(100), long(2))), (float, (100.0, 2.0))]: # (complex, (100+0j, 2+0j)) - cpython doesn't call reverse ops for complex ? class prototype(baseType[0]): for op in operators: exec('''def %s(self, other): global opCalled opCalled.append('%s') return super(self.__class__, self).%s(other) def %s(self, other): global opCalled opCalled.append('%s') return super(self.__class__, self).%s(other)''' % (op, op, op, op[:2] + 'r' + op[2:], op[:2] + 'r' + op[2:], op[:2] + 'r' + op[2:])) types.append( (prototype, baseType[1]) ) global opCalled opCalled = [] for op in opSymbol: for typeInfo in types: ex = typeInfo[0](typeInfo[1][0]) ey = typeInfo[0](typeInfo[1][1]) nx = typeInfo[0].__bases__[0](typeInfo[1][0]) ny = typeInfo[0].__bases__[0](typeInfo[1][1]) #print 'nx %s ey' % op, type(nx), type(ey) res1 = eval('nx %s ey' % op) res2 = eval('nx %s ny' % op) self.assertEqual(res1, res2) self.assertEqual(len(opCalled), 1) opCalled = [] #print 'ex %s ny' % op, type(ex), type(ny) res1 = eval('ex %s ny' % op) res2 = eval('nx %s ny' % op) self.assertEqual(res1, res2) self.assertEqual(len(opCalled), 1) opCalled = []
def test_array___init__(self): ''' TODO: revist! ''' #--I for x in [ 0, 1, 2, (2**8)-2, (2**8)-1, (2**8), (2**8)+1, (2**8)+2, (2**16)-2, (2**16)-1, (2**16), (2**16)+1, (2**16)+2, (2**32)-2, (2**32)-1, ]: temp_array1 = array.array('I', [x]) self.assertEqual(temp_array1[0], x) temp_array1 = array.array('I', [x, x]) self.assertEqual(temp_array1[0], x) self.assertEqual(temp_array1[1], x) for x in [ (2**32), (2**32)+1, (2**32)+2 ]: self.assertRaises(OverflowError, array.array, 'I', [x]) #--u a = array.array('u', "stuff") a[1:0] = a b = array.array('u', "stuff"[:1] + "stuff" + "stuff"[1:]) self.assertEqual(a, b) #--L a = array.array('L', b"\x12\x34\x45\x67") self.assertEqual(1, len(a)) self.assertEqual(1732588562, a[0]) #--B a = array.array('B', [0]) * long(2) self.assertEqual(2, len(a)) self.assertEqual("array('B', [0, 0])", str(a)) #--b self.assertEqual(array.array('b', b'foo'), array.array('b', [102, 111, 111])) #--H self.assertEqual(array.array('H', b'foof'), array.array('H', [28518, 26223])) self.assertEqual(array.array('H', bytearray(b'foof')), array.array('H', [28518, 26223])) self.assertEqual(array.array('H', array.array('b', b'foof')), array.array('H', [102, 111, 111, 102])) self.assertEqual(array.array('H', memoryview(b'foof')), array.array('H', [102, 111, 111, 102])) self.assertEqual(array.array('H', memoryview(b"foof").cast('h')), array.array('H', [28518, 26223])) self.assertEqual(array.array('H', memoryview(b"f.o.")[::2]), array.array('H', [102, 111])) self.assertEqual(array.array('H', memoryview(b"fo\0\0of\0\0").cast('I')), array.array('H', [28518, 26223])) self.assertRaisesRegex(ValueError, "^bytes length not a multiple of item size$", array.array, 'H', b'foo') with self.assertRaisesRegex(NotImplementedError, "^multi-dimensional sub-views are not implemented$"): array.array('H', memoryview(bytes(range(16))).cast('H', (4,2))) with self.assertRaisesRegex(TypeError, "^invalid indexing of 0-dim memory$"): array.array('H', memoryview(b"xy").cast('H', ()))
def test_complex(self): # Complex tests self.assertTrue((2+4j)/(1+1j) == (3+1j)) self.assertTrue((2+10j)/4.0 == (0.5+2.5j)) self.assertEqual(1j ** 2, (-1.0+0j)) self.assertEqual(pow(1j, 2), (-1.0+0j)) self.assertEqual(1+0j, 1) self.assertEqual(1+0j, 1.0) self.assertEqual(1+0j, long(1)) self.assertEqual((1+1j)/long(1), (1+1j)) self.assertEqual((1j) + long(1), (1+1j)) self.assertEqual(0j ** 0, 1) self.assertEqual(0j ** 0j, 1) self.assertEqual(pow(0j, 0), 1) self.assertEqual(pow(0j, 0j), 1) if is_cli: self.assertEqual((1j) + Int64(), 1j) self.assertRaises(TypeError, (lambda:(1+1j)+[])) self.assertRaises(TypeError, lambda : type(2j).__dict__['real'].__set__, 2j, 0)
def test_wacky_contains(self): for retval in [None, 0, [], (), 0.0, long(0), {}]: class x(tuple): def __contains__(self, other): return retval self.assertEqual('abc' in x(), False) class x2(tuple): def __contans__(self, other): pass self.assertEqual('abc' in x2(), False)
def test_array___init__(self): ''' TODO: revist! ''' #--I for x in [ 0, 1, 2, (2**8) - 2, (2**8) - 1, (2**8), (2**8) + 1, (2**8) + 2, (2**16) - 2, (2**16) - 1, (2**16), (2**16) + 1, (2**16) + 2, (2**32) - 2, (2**32) - 1, ]: temp_array1 = array.array('I', [x]) self.assertEqual(temp_array1[0], x) temp_array1 = array.array('I', [x, x]) self.assertEqual(temp_array1[0], x) self.assertEqual(temp_array1[1], x) for x in [(2**32), (2**32) + 1, (2**32) + 2]: self.assertRaises(OverflowError, array.array, 'I', [x]) #--u a = array.array('u', "stuff") a[1:0] = a b = array.array('u', "stuff"[:1] + "stuff" + "stuff"[1:]) self.assertEqual(a, b) #--L a = array.array('L', b"\x12\x34\x45\x67") self.assertEqual(1, len(a)) self.assertEqual(1732588562, a[0]) #--B a = array.array('B', [0]) * long(2) self.assertEqual(2, len(a)) self.assertEqual("array('B', [0, 0])", str(a)) #--b self.assertEqual(array.array('b', b'foo'), array.array('b', [102, 111, 111]))
def test_extensible_types_hashing(self): """extensible types should hash the same as non-extensibles, and unary operators should work too""" for x, y in ( (int, 2), (str, 'abc'), (float, 2.0), (long, long(2)), (complex, 2+0j) ): class foo(x): pass self.assertEqual(hash(foo(y)), hash(y)) if x != str: self.assertEqual(-foo(y), -y) self.assertEqual(+foo(y), +y) if x != complex and x != float: self.assertEqual(~foo(y), ~y)
def setUp(self): super(IronMathTest, self).setUp() import clr from System import IFormatProvider class myFormatProvider(IFormatProvider): def ToString(): pass self.p = myFormatProvider() clr.AddReference(long(1).GetType().Assembly) self.load_iron_python_test()
def test_log(self): import math zeros = [-1, -1.0, long(-1), 0, 0.0, long(0)] nonzeros = [2, 2.0, long(2)] ones = [1, 1.0, long(1)] if is_cli: # https://github.com/IronLanguages/ironpython3/issues/52 self.assertNotEqual(type(zeros[0]), type(zeros[2])) else: self.assertEqual(type(zeros[0]), type(zeros[2])) for z0 in zeros: self.assertRaises(ValueError, math.log, z0) self.assertRaises(ValueError, math.log10, z0) for z in zeros: self.assertRaises(ValueError, math.log, z0, z) for n in nonzeros + ones: self.assertRaises(ValueError, math.log, z0, n) self.assertRaises(ValueError, math.log, n, z0) for one in ones: for n in nonzeros: self.assertRaises(ZeroDivisionError, math.log, n, one)
def test_arg_Derived_Number(self): from IronPythonTest.BinderTest import COverloads_Derived_Number target = COverloads_Derived_Number() for (arg, mapping, funcTypeError, funcOverflowError) in [ ( None, _merge(_first('M106 '), _second('M102 M103 ')), 'M100 M101 M104 M105 ', '', ), ( True, _merge(_first('M100 M103 '), _second('M104 M105 M106 ')), 'M101 M102 ', '', ), ( -100, _merge(_first('M100 '), _second('M104 M105 M106 ')), 'M101 M102 M103 ', '', ), ( long(200), _merge(_first('M106 M105 '), _second('M100 M102 M101 ')), 'M103 M104 ', '', ), ( Byte10, _merge(_first('M103 '), _second('M100 M105 M106 ')), 'M101 M102 M104 ', '', ), ( 12.34, _merge(_first('M104 M105 M106 '), _second('M101 M102 M100 ')), 'M103 ', '', ), ]: self._try_arg(target, arg, mapping, funcTypeError, funcOverflowError)