本文整理汇总了Python中PyObjCTest.pythonnumber.OC_TestNumber.numberAsUnsignedInt_方法的典型用法代码示例。如果您正苦于以下问题:Python OC_TestNumber.numberAsUnsignedInt_方法的具体用法?Python OC_TestNumber.numberAsUnsignedInt_怎么用?Python OC_TestNumber.numberAsUnsignedInt_使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyObjCTest.pythonnumber.OC_TestNumber
的用法示例。
在下文中一共展示了OC_TestNumber.numberAsUnsignedInt_方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testDoubleConversions
# 需要导入模块: from PyObjCTest.pythonnumber import OC_TestNumber [as 别名]
# 或者: from PyObjCTest.pythonnumber.OC_TestNumber import numberAsUnsignedInt_ [as 别名]
def testDoubleConversions(self):
v = 75.5
self.assertEqual(OC_TestNumber.numberAsBOOL_(v), 1)
self.assertEqual(OC_TestNumber.numberAsChar_(v), 75)
self.assertEqual(OC_TestNumber.numberAsShort_(v), 75)
self.assertEqual(OC_TestNumber.numberAsInt_(v), 75)
self.assertEqual(OC_TestNumber.numberAsLong_(v), 75)
self.assertEqual(OC_TestNumber.numberAsLongLong_(v), 75)
self.assertEqual(OC_TestNumber.numberAsUnsignedChar_(v), 75)
self.assertEqual(OC_TestNumber.numberAsUnsignedShort_(v), 75)
self.assertEqual(OC_TestNumber.numberAsUnsignedInt_(v), 75)
self.assertEqual(OC_TestNumber.numberAsUnsignedLong_(v), 75)
self.assertEqual(OC_TestNumber.numberAsUnsignedLongLong_(v), 75)
self.assertEqual(OC_TestNumber.numberAsFloat_(v), 75.5)
self.assertEqual(OC_TestNumber.numberAsDouble_(v), 75.5)
# Negative values
v = -127.6
self.assertEqual(OC_TestNumber.numberAsBOOL_(v), 1)
self.assertEqual(OC_TestNumber.numberAsChar_(v), -127)
self.assertEqual(OC_TestNumber.numberAsShort_(v), -127)
self.assertEqual(OC_TestNumber.numberAsInt_(v), -127)
self.assertEqual(OC_TestNumber.numberAsLong_(v), -127)
self.assertEqual(OC_TestNumber.numberAsLongLong_(v), -127)
self.assertEqual(OC_TestNumber.numberAsUnsignedChar_(v), 129)
self.assertEqual(OC_TestNumber.numberAsUnsignedShort_(v), 65409)
self.assertEqual(OC_TestNumber.numberAsUnsignedInt_(v), 4294967169)
if sys.maxsize == (2 ** 31) -1:
self.assertEqual(OC_TestNumber.numberAsUnsignedLong_(v), 4294967169)
else:
self.assertEqual(OC_TestNumber.numberAsUnsignedLong_(v), 18446744073709551489)
if sys.byteorder == 'big':
self.assertEqual(OC_TestNumber.numberAsUnsignedLongLong_(v), 4294967169)
else:
self.assertEqual(OC_TestNumber.numberAsUnsignedLongLong_(v), 18446744073709551489)
self.assertEqual(OC_TestNumber.numberAsDouble_(v), -127.6)
# Overflow
v = float(2**64 + 99)
self.assertEqual(OC_TestNumber.numberAsBOOL_(v), 1)
if sys.byteorder == 'big':
self.assertEqual(OC_TestNumber.numberAsChar_(v), -1)
self.assertEqual(OC_TestNumber.numberAsShort_(v), -1)
self.assertEqual(OC_TestNumber.numberAsUnsignedChar_(v), 255)
self.assertEqual(OC_TestNumber.numberAsUnsignedShort_(v), 65535)
else:
self.assertEqual(OC_TestNumber.numberAsChar_(v), 0)
self.assertEqual(OC_TestNumber.numberAsShort_(v), 0)
self.assertEqual(OC_TestNumber.numberAsUnsignedChar_(v), 0)
self.assertEqual(OC_TestNumber.numberAsUnsignedShort_(v), 0)
示例2: testPythonIntConversions
# 需要导入模块: from PyObjCTest.pythonnumber import OC_TestNumber [as 别名]
# 或者: from PyObjCTest.pythonnumber.OC_TestNumber import numberAsUnsignedInt_ [as 别名]
def testPythonIntConversions(self):
# Conversions to other values. Note that values are converted
# using C casts, without any exceptions when converting a
# negative value to an unsigned one and without exceptions for
# overflow.
v = 42
self.assertEqual(OC_TestNumber.numberAsBOOL_(v), 1)
self.assertEqual(OC_TestNumber.numberAsChar_(v), 42)
self.assertEqual(OC_TestNumber.numberAsShort_(v), 42)
self.assertEqual(OC_TestNumber.numberAsInt_(v), 42)
self.assertEqual(OC_TestNumber.numberAsLong_(v), 42)
self.assertEqual(OC_TestNumber.numberAsLongLong_(v), 42)
self.assertEqual(OC_TestNumber.numberAsUnsignedChar_(v), 42)
self.assertEqual(OC_TestNumber.numberAsUnsignedShort_(v), 42)
self.assertEqual(OC_TestNumber.numberAsUnsignedInt_(v), 42)
self.assertEqual(OC_TestNumber.numberAsUnsignedLong_(v), 42)
self.assertEqual(OC_TestNumber.numberAsUnsignedLongLong_(v), 42)
self.assertEqual(OC_TestNumber.numberAsUnsignedLongLong_(v), 42)
self.assertEqual(OC_TestNumber.numberAsFloat_(v), 42.0)
self.assertEqual(OC_TestNumber.numberAsDouble_(v), 42.0)
# Negative values
v = -42
self.assertEqual(OC_TestNumber.numberAsBOOL_(v), 1)
self.assertEqual(OC_TestNumber.numberAsChar_(v), -42)
self.assertEqual(OC_TestNumber.numberAsShort_(v), -42)
self.assertEqual(OC_TestNumber.numberAsInt_(v), -42)
self.assertEqual(OC_TestNumber.numberAsLong_(v), -42)
self.assertEqual(OC_TestNumber.numberAsLongLong_(v), -42)
self.assertEqual(OC_TestNumber.numberAsUnsignedChar_(v), 214)
self.assertEqual(OC_TestNumber.numberAsUnsignedShort_(v), 65494)
self.assertEqual(OC_TestNumber.numberAsUnsignedInt_(v), 4294967254)
if sys.maxsize == (2 ** 31) -1:
self.assertEqual(OC_TestNumber.numberAsUnsignedLong_(v), 4294967254)
else:
self.assertEqual(OC_TestNumber.numberAsUnsignedLong_(v), 18446744073709551574)
self.assertEqual(OC_TestNumber.numberAsUnsignedLongLong_(v), 18446744073709551574)
self.assertEqual(OC_TestNumber.numberAsFloat_(v), -42.0)
self.assertEqual(OC_TestNumber.numberAsDouble_(v), -42.0)
# Overflow
v = 892455
self.assertEqual(OC_TestNumber.numberAsBOOL_(v), 1)
self.assertEqual(OC_TestNumber.numberAsChar_(v), 39)
self.assertEqual(OC_TestNumber.numberAsShort_(v), -25049)
self.assertEqual(OC_TestNumber.numberAsUnsignedChar_(v), 39)
self.assertEqual(OC_TestNumber.numberAsUnsignedShort_(v), 40487)
示例3: testIntConversions
# 需要导入模块: from PyObjCTest.pythonnumber import OC_TestNumber [as 别名]
# 或者: from PyObjCTest.pythonnumber.OC_TestNumber import numberAsUnsignedInt_ [as 别名]
def testIntConversions(self):
v = NSNumber.numberWithInt_(42)
self.assertEqual(v.stringValue(), '42')
self.assertEqual(OC_TestNumber.numberAsBOOL_(v), 1)
self.assertEqual(OC_TestNumber.numberAsChar_(v), 42)
self.assertEqual(OC_TestNumber.numberAsShort_(v), 42)
self.assertEqual(OC_TestNumber.numberAsInt_(v), 42)
self.assertEqual(OC_TestNumber.numberAsLong_(v), 42)
self.assertEqual(OC_TestNumber.numberAsLongLong_(v), 42)
self.assertEqual(OC_TestNumber.numberAsUnsignedChar_(v), 42)
self.assertEqual(OC_TestNumber.numberAsUnsignedShort_(v), 42)
self.assertEqual(OC_TestNumber.numberAsUnsignedInt_(v), 42)
self.assertEqual(OC_TestNumber.numberAsUnsignedLong_(v), 42)
self.assertEqual(OC_TestNumber.numberAsUnsignedLongLong_(v), 42)
self.assertEqual(OC_TestNumber.numberAsFloat_(v), 42.0)
self.assertEqual(OC_TestNumber.numberAsDouble_(v), 42.0)
# Negative values
v = NSNumber.numberWithInt_(-42)
self.assertEqual(v.stringValue(), '-42')
self.assertEqual(OC_TestNumber.numberAsBOOL_(v), 1)
self.assertEqual(OC_TestNumber.numberAsChar_(v), -42)
self.assertEqual(OC_TestNumber.numberAsShort_(v), -42)
self.assertEqual(OC_TestNumber.numberAsInt_(v), -42)
self.assertEqual(OC_TestNumber.numberAsLong_(v), -42)
self.assertEqual(OC_TestNumber.numberAsLongLong_(v), -42)
self.assertEqual(OC_TestNumber.numberAsUnsignedChar_(v), 214)
self.assertEqual(OC_TestNumber.numberAsUnsignedShort_(v), 65494)
self.assertEqual(OC_TestNumber.numberAsUnsignedInt_(v), 4294967254)
if sys.maxsize == (2 ** 31) -1:
self.assertEqual(OC_TestNumber.numberAsUnsignedLong_(v), 4294967254)
else:
self.assertEqual(OC_TestNumber.numberAsUnsignedLong_(v), 18446744073709551574)
self.assertEqual(OC_TestNumber.numberAsUnsignedLongLong_(v), 18446744073709551574)
self.assertEqual(OC_TestNumber.numberAsFloat_(v), -42.0)
self.assertEqual(OC_TestNumber.numberAsDouble_(v), -42.0)
# Overflow
v = NSNumber.numberWithInt_(892455)
self.assertEqual(OC_TestNumber.numberAsBOOL_(v), 1)
self.assertEqual(OC_TestNumber.numberAsChar_(v), 39)
self.assertEqual(OC_TestNumber.numberAsShort_(v), -25049)
self.assertEqual(OC_TestNumber.numberAsUnsignedChar_(v), 39)
self.assertEqual(OC_TestNumber.numberAsUnsignedShort_(v), 40487)
示例4: testShortConversions
# 需要导入模块: from PyObjCTest.pythonnumber import OC_TestNumber [as 别名]
# 或者: from PyObjCTest.pythonnumber.OC_TestNumber import numberAsUnsignedInt_ [as 别名]
def testShortConversions(self):
v = NSNumber.numberWithShort_(42)
self.assertEquals(OC_TestNumber.numberAsBOOL_(v), 1)
self.assertEquals(OC_TestNumber.numberAsChar_(v), 42)
self.assertEquals(OC_TestNumber.numberAsShort_(v), 42)
self.assertEquals(OC_TestNumber.numberAsInt_(v), 42)
self.assertEquals(OC_TestNumber.numberAsLong_(v), 42)
self.assertEquals(OC_TestNumber.numberAsLongLong_(v), 42)
self.assertEquals(OC_TestNumber.numberAsUnsignedChar_(v), 42)
self.assertEquals(OC_TestNumber.numberAsUnsignedShort_(v), 42)
self.assertEquals(OC_TestNumber.numberAsUnsignedInt_(v), 42)
self.assertEquals(OC_TestNumber.numberAsUnsignedLong_(v), 42)
self.assertEquals(OC_TestNumber.numberAsUnsignedLongLong_(v), 42)
self.assertEquals(OC_TestNumber.numberAsFloat_(v), 42.0)
self.assertEquals(OC_TestNumber.numberAsDouble_(v), 42.0)
示例5: testPythonLongConversions
# 需要导入模块: from PyObjCTest.pythonnumber import OC_TestNumber [as 别名]
# 或者: from PyObjCTest.pythonnumber.OC_TestNumber import numberAsUnsignedInt_ [as 别名]
def testPythonLongConversions(self):
if sys.version_info[0] == 2:
v = long(42)
self.assertIsInstance(v, long)
else:
v = 42
self.assertEqual(OC_TestNumber.numberAsBOOL_(v), 1)
self.assertEqual(OC_TestNumber.numberAsChar_(v), 42)
self.assertEqual(OC_TestNumber.numberAsShort_(v), 42)
self.assertEqual(OC_TestNumber.numberAsInt_(v), 42)
self.assertEqual(OC_TestNumber.numberAsLong_(v), 42)
self.assertEqual(OC_TestNumber.numberAsLongLong_(v), 42)
self.assertEqual(OC_TestNumber.numberAsUnsignedChar_(v), 42)
self.assertEqual(OC_TestNumber.numberAsUnsignedShort_(v), 42)
self.assertEqual(OC_TestNumber.numberAsUnsignedInt_(v), 42)
self.assertEqual(OC_TestNumber.numberAsUnsignedLong_(v), 42)
self.assertEqual(OC_TestNumber.numberAsUnsignedLongLong_(v), 42)
self.assertEqual(OC_TestNumber.numberAsUnsignedLongLong_(v), 42)
self.assertEqual(OC_TestNumber.numberAsFloat_(v), 42.0)
self.assertEqual(OC_TestNumber.numberAsDouble_(v), 42.0)
# Negative values
if sys.version_info[0] == 2:
v = long(-42)
self.assertIsInstance(v, long)
else:
v = -42
self.assertEqual(OC_TestNumber.numberAsBOOL_(v), 1)
self.assertEqual(OC_TestNumber.numberAsChar_(v), -42)
self.assertEqual(OC_TestNumber.numberAsShort_(v), -42)
self.assertEqual(OC_TestNumber.numberAsInt_(v), -42)
self.assertEqual(OC_TestNumber.numberAsLong_(v), -42)
self.assertEqual(OC_TestNumber.numberAsLongLong_(v), -42)
self.assertEqual(OC_TestNumber.numberAsUnsignedChar_(v), 214)
self.assertEqual(OC_TestNumber.numberAsUnsignedShort_(v), 65494)
self.assertEqual(OC_TestNumber.numberAsUnsignedInt_(v), 4294967254)
if sys.maxsize == (2 ** 31) -1:
self.assertEqual(OC_TestNumber.numberAsUnsignedLong_(v), 4294967254)
else:
self.assertEqual(OC_TestNumber.numberAsUnsignedLong_(v), 18446744073709551574)
self.assertEqual(OC_TestNumber.numberAsUnsignedLongLong_(v), 18446744073709551574)
self.assertEqual(OC_TestNumber.numberAsFloat_(v), -42.0)
self.assertEqual(OC_TestNumber.numberAsDouble_(v), -42.0)
# Overflow
if sys.version_info[0] == 2:
v = long(892455)
self.assertIsInstance(v, long)
else:
v = 892455
self.assertEqual(OC_TestNumber.numberAsBOOL_(v), 1)
self.assertEqual(OC_TestNumber.numberAsChar_(v), 39)
self.assertEqual(OC_TestNumber.numberAsShort_(v), -25049)
self.assertEqual(OC_TestNumber.numberAsUnsignedChar_(v), 39)
self.assertEqual(OC_TestNumber.numberAsUnsignedShort_(v), 40487)
# Very much overflow
v = 2 ** 64 + 1
self.assertEqual(OC_TestNumber.numberAsBOOL_(v), 1)
self.assertEqual(OC_TestNumber.numberAsChar_(v), 1)
self.assertEqual(OC_TestNumber.numberAsShort_(v), 1)
self.assertEqual(OC_TestNumber.numberAsInt_(v), 1)
self.assertEqual(OC_TestNumber.numberAsLong_(v), 1)
self.assertEqual(OC_TestNumber.numberAsLongLong_(v), 1)
self.assertEqual(OC_TestNumber.numberAsUnsignedChar_(v), 1)
self.assertEqual(OC_TestNumber.numberAsUnsignedShort_(v), 1)
self.assertEqual(OC_TestNumber.numberAsUnsignedInt_(v), 1)
self.assertEqual(OC_TestNumber.numberAsUnsignedLong_(v), 1)
self.assertEqual(OC_TestNumber.numberAsUnsignedLongLong_(v), 1)