當前位置: 首頁>>代碼示例>>Python>>正文


Python System.Int64方法代碼示例

本文整理匯總了Python中System.Int64方法的典型用法代碼示例。如果您正苦於以下問題:Python System.Int64方法的具體用法?Python System.Int64怎麽用?Python System.Int64使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System的用法示例。


在下文中一共展示了System.Int64方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_complex

# 需要導入模塊: import System [as 別名]
# 或者: from System import Int64 [as 別名]
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) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:22,代碼來源:test_math.py

示例2: test_z_cli_tests

# 需要導入模塊: import System [as 別名]
# 或者: from System import Int64 [as 別名]
def test_z_cli_tests(self):    # runs last to prevent tainting the module w/ CLR names
        import clr
        import System
        self.load_iron_python_test()
        from IronPythonTest import WriteOnly
        if is_netcoreapp:
            clr.AddReference("System.IO.Compression")

        with stdout_trapper() as output:
            help(WriteOnly)
            help(System.IO.Compression)
            help(System.Int64)
        
        x = self.run_help(System.String.Format)
        self.assertTrue(x.find('Format(format: str, arg0: object) -> str') != -1)
        
        x = self.run_help('u.u'.Split('u'))
        # requires std lib
        self.assertTrue('Help on Array[str] object' in x, x)

        # https://github.com/IronLanguages/ironpython2/issues/359
        if not is_mono:
            from System.IO import MemoryStream
            x_class = self.run_help(MemoryStream.Write)

            x_instance = self.run_help(MemoryStream().Write)

            self.assertEqual(x_class, x_instance.replace("built-in function Write", "method_descriptor"))

        #http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=11883
        self.assertEqual(dir(System).count('Action'), 1)
        with stdout_trapper() as output: 
            help(System.Action)
        
        self.assertEqual(dir(System).count('Action'), 1) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:37,代碼來源:test_help.py

示例3: test_more_complex

# 需要導入模塊: import System [as 別名]
# 或者: from System import Int64 [as 別名]
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*[]))) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:13,代碼來源:test_math.py

示例4: test_cp13401

# 需要導入模塊: import System [as 別名]
# 或者: from System import Int64 [as 別名]
def test_cp13401(self):
        import System
        import copy
        
        #A few special cases
        self.assertEqual(System.Char.MinValue, copy.copy(System.Char.MinValue))
        self.assertTrue(System.Char.MinValue != copy.copy(System.Char.MaxValue))
        self.assertEqual(System.StringSplitOptions.None, copy.copy(System.StringSplitOptions.None))
        self.assertEqual(System.StringSplitOptions.RemoveEmptyEntries, copy.copy(System.StringSplitOptions.RemoveEmptyEntries))
        self.assertTrue(System.StringSplitOptions.None != copy.copy(System.StringSplitOptions.RemoveEmptyEntries))
        
        #Normal cases
        test_dict = {   System.Byte : [System.Byte.MinValue, System.Byte.MinValue+1, System.Byte.MaxValue, System.Byte.MaxValue-1],
                        System.Char : [],
                        System.Boolean : [True, False],
                        System.SByte   : [System.SByte.MinValue, System.SByte.MinValue+1, System.SByte.MaxValue, System.SByte.MaxValue-1],
                        System.UInt32  : [System.UInt32.MinValue, System.UInt32.MinValue+1, System.UInt32.MaxValue, System.UInt32.MaxValue-1],
                        System.Int64   : [System.Int64.MinValue, System.Int64.MinValue+1, System.Int64.MaxValue, System.Int64.MaxValue-1],
                        System.Double  : [0.00, 3.14],
                        }
        
        for key in test_dict.keys():
            temp_type = key
            self.assertTrue(hasattr(temp_type, "__reduce_ex__"), 
                "%s has no attribute '%s'" % (str(temp_type), "__reduce_ex__"))
        
            for temp_value in test_dict[key]:
                x = temp_type(temp_value)
                x_copy = copy.copy(x)
                self.assertEqual(x, x_copy)
                self.assertEqual(x, temp_value) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:33,代碼來源:test_stdmodules.py

示例5: get_values

# 需要導入模塊: import System [as 別名]
# 或者: from System import Int64 [as 別名]
def get_values(values, itypes, ftypes):
    """
    This will return structure of values converted to variety of types as a list of tuples:
    [ ...
    ( python_value, [ all_values ] ),
    ... ]

    all_values: Byte, UInt16, UInt32, UInt64, SByte, Int16, Int32, Int64, Single, Double, myint, mylong, myfloat
    """
    all = []
    for v in values:
        sv  = str(v)
        py  = int(v)
        clr = get_clr_values(sv, itypes)
        clr.append(long(py))
        clr.append(myint(py))
        clr.append(mylong(py))
        all.append( (py, clr) )

        py  = long(v)
        clr = get_clr_values(sv, itypes)
        clr.append(py)
        clr.append(myint(py))
        clr.append(mylong(py))
        all.append( (py, clr) )

        py  = float(v)
        clr = get_clr_values(sv, ftypes)
        clr.append(myfloat(py))
        all.append( (py, clr) )

        for imag in [0j, 1j, -1j]:
            py = complex(v + imag)
            all.append( (py, [ py, mycomplex(py) ] ) )

    all.append( (True, [ True ] ))
    all.append( (False, [ False ] ))

    return all 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:41,代碼來源:test_numtypes.py

示例6: validate_constructors

# 需要導入模塊: import System [as 別名]
# 或者: from System import Int64 [as 別名]
def validate_constructors(self, values):
        types = [Byte, UInt16, UInt32, UInt64, SByte, Int16, Int32, Int64]
        total = 0
        for value in values:
            for first in types:
                v1 = first(value)
                for second in types:
                    v2 = first(second((value)))
                total += 1
        return total 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:12,代碼來源:test_numtypes.py

示例7: test_cp34770

# 需要導入模塊: import System [as 別名]
# 或者: from System import Int64 [as 別名]
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') 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:14,代碼來源:test_dict.py

示例8: test_primitive_inheritance

# 需要導入模塊: import System [as 別名]
# 或者: from System import Int64 [as 別名]
def test_primitive_inheritance(self):
        import System
        
        def InheritFromType(t):
            class InheritedType(t): pass
            return InheritedType
        
        self.assertRaises(TypeError, InheritFromType, System.Int64)
        self.assertRaises(TypeError, InheritFromType, System.Boolean)
        
        # isinstance
        
        self.assertTrue(isinstance(System.Int64(), System.Int64) == True)
        self.assertTrue(isinstance(System.Boolean(), System.Boolean) == True)
        
        self.assertTrue(isinstance(1, System.Int64) == False)
        self.assertTrue(isinstance(1, System.Boolean) == False)
        
        class userClass(object): pass
        self.assertTrue(isinstance(userClass(), System.Int64) == False)
        self.assertTrue(isinstance(userClass(), System.Boolean) == False)
        
        # issubclass
        
        self.assertTrue(issubclass(System.Int64, System.Int64) == True)
        self.assertTrue(issubclass(System.Boolean, System.Boolean) == True)
        
        self.assertTrue(issubclass(type(1), System.Int64) == False)
        self.assertTrue(issubclass(type(1), System.Boolean) == False)
        
        self.assertTrue(issubclass(userClass, System.Int64) == False)
        self.assertTrue(issubclass(userClass, System.Boolean) == False) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:34,代碼來源:test_isinstance.py

示例9: test_big_1

# 需要導入模塊: import System [as 別名]
# 或者: from System import Int64 [as 別名]
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) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:33,代碼來源:test_ironmath.py

示例10: test_big_2

# 需要導入模塊: import System [as 別名]
# 或者: from System import Int64 [as 別名]
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)) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:29,代碼來源:test_ironmath.py

示例11: test_nonzero

# 需要導入模塊: import System [as 別名]
# 或者: from System import Int64 [as 別名]
def test_nonzero(self):
        from System import Single, Byte, SByte, Int16, UInt16, Int64, UInt64
        for t in [Single, Byte, SByte, Int16, UInt16, Int64, UInt64]:
            self.assertTrue(hasattr(t, '__nonzero__'))
            if t(0): self.assertUnreachable()
            if not t(1): self.assertUnreachable() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:8,代碼來源:test_cliclass.py

示例12: validate

# 需要導入模塊: import System [as 別名]
# 或者: from System import Int64 [as 別名]
def validate(self, obj, value):
            if isinstance(value, int):
                return value
            if isinstance(value, long):
                # downcast longs that fit in int:
                # note that int(n > sys.maxint) returns a long, so
                # we don't need a condition on this cast
                return int(value)
            if sys.platform == "cli":
                from System import Int64
                if isinstance(value, Int64):
                    return int(value)
            self.error(obj, value) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:15,代碼來源:traitlets.py

示例13: replaceDict

# 需要導入模塊: import System [as 別名]
# 或者: from System import Int64 [as 別名]
def replaceDict(x):
	if hasattr(x,'__iter__'): return map(replaceDict, x)
	if isinstance(x, dsDict): return dict(zip(x.Keys, replaceDict(x.Values)))
	if isinstance(x, Int64): return int(x)
	return x 
開發者ID:dimven,項目名稱:SpringNodes,代碼行數:7,代碼來源:List.ToString.py

示例14: test_z_cli_tests

# 需要導入模塊: import System [as 別名]
# 或者: from System import Int64 [as 別名]
def test_z_cli_tests(self):    # runs last to prevent tainting the module w/ CLR names
        import clr
        import System
        self.load_iron_python_test()
        from IronPythonTest import WriteOnly
        if is_netcoreapp:
            clr.AddReference("System.IO.Compression")

        with stdout_trapper() as output:
            help(WriteOnly)
            help(System.IO.Compression)
            help(System.Int64)
        
        x = self.run_help(System.String.Format)
        self.assertIn('Format(format: str, arg0: object) -> str', x)
        
        x = self.run_help('u.u'.Split('u'))
        # requires std lib
        self.assertTrue('Help on Array[str] object' in x, x)

        #http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=4190
        from System.IO import MemoryStream
        x_class = self.run_help(MemoryStream.Write)

        x_instance = self.run_help(MemoryStream().Write)

        self.assertEqual(x_class, x_instance.replace("built-in function Write", "method_descriptor").replace(" method of {}.MemoryStream instance".format(MemoryStream.__module__), ""))

        #http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=11883
        self.assertEqual(dir(System).count('Action'), 1)
        with stdout_trapper() as output: 
            help(System.Action)
        
        self.assertEqual(dir(System).count('Action'), 1) 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:36,代碼來源:test_help.py

示例15: test_cp13401

# 需要導入模塊: import System [as 別名]
# 或者: from System import Int64 [as 別名]
def test_cp13401(self):
        import System
        import copy
        
        #A few special cases
        StringSplitOptions_None = getattr(System.StringSplitOptions, "None")
        self.assertEqual(System.Char.MinValue, copy.copy(System.Char.MinValue))
        self.assertTrue(System.Char.MinValue != copy.copy(System.Char.MaxValue))
        self.assertEqual(StringSplitOptions_None, copy.copy(StringSplitOptions_None))
        self.assertEqual(System.StringSplitOptions.RemoveEmptyEntries, copy.copy(System.StringSplitOptions.RemoveEmptyEntries))
        self.assertTrue(StringSplitOptions_None != copy.copy(System.StringSplitOptions.RemoveEmptyEntries))
        
        #Normal cases
        test_dict = {   System.Byte : [System.Byte.MinValue, System.Byte.MinValue+1, System.Byte.MaxValue, System.Byte.MaxValue-1],
                        System.Char : [],
                        System.Boolean : [True, False],
                        System.SByte   : [System.SByte.MinValue, System.SByte.MinValue+1, System.SByte.MaxValue, System.SByte.MaxValue-1],
                        System.UInt32  : [System.UInt32.MinValue, System.UInt32.MinValue+1, System.UInt32.MaxValue, System.UInt32.MaxValue-1],
                        System.Int64   : [System.Int64.MinValue, System.Int64.MinValue+1, System.Int64.MaxValue, System.Int64.MaxValue-1],
                        System.Double  : [0.00, 3.14],
                        }
        
        for key in test_dict.keys():
            temp_type = key
            self.assertTrue(hasattr(temp_type, "__reduce_ex__"), 
                "%s has no attribute '%s'" % (str(temp_type), "__reduce_ex__"))
        
            for temp_value in test_dict[key]:
                x = temp_type(temp_value)
                x_copy = copy.copy(x)
                self.assertEqual(x, x_copy)
                self.assertEqual(x, temp_value) 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:34,代碼來源:test_stdmodules.py


注:本文中的System.Int64方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。