| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
import _jpype |
| 19 |
import jpype |
| 20 |
from jpype import JPackage, java |
| 21 |
from jpype.types import * |
| 22 |
import common |
| 23 |
|
| 24 |
|
| 25 |
class NumericTestCase(common.JPypeTestCase): |
| 26 |
def testMathAbs(self): |
| 27 |
self.assertEqual(java.lang.Math.abs(-10), 10) |
| 28 |
|
| 29 |
def testDoubleConversion(self): |
| 30 |
f = java.lang.Float.MAX_VALUE * 2 |
| 31 |
self.assertTrue(JClass("jpype.numeric.NumericTest").doubleIsTwiceMaxFloat(f)) |
| 32 |
|
| 33 |
def testDoubleIsProperlyConverted(self): |
| 34 |
self.assertTrue(java.lang.Double.POSITIVE_INFINITY != 0.0) |
| 35 |
self.assertTrue(java.lang.Double.MAX_VALUE != 0.0) |
| 36 |
self.assertTrue(java.lang.Double.NaN != 0.0) |
| 37 |
self.assertTrue(java.lang.Double.NEGATIVE_INFINITY != 0.0) |
| 38 |
|
| 39 |
def testCompareNullLong(self): |
| 40 |
null = JObject(None, java.lang.Integer) |
| 41 |
self.assertEqual(null, None) |
| 42 |
self.assertNotEqual(null, object()) |
| 43 |
with self.assertRaisesRegex(TypeError, "null"): |
| 44 |
null > 0 |
| 45 |
with self.assertRaisesRegex(TypeError, "null"): |
| 46 |
null < 0 |
| 47 |
with self.assertRaisesRegex(TypeError, "null"): |
| 48 |
null >= 0 |
| 49 |
with self.assertRaisesRegex(TypeError, "null"): |
| 50 |
null <= 0 |
| 51 |
|
| 52 |
def testCompareNullFloat(self): |
| 53 |
null = JObject(None, java.lang.Double) |
| 54 |
self.assertEqual(null, None) |
| 55 |
self.assertNotEqual(null, object()) |
| 56 |
with self.assertRaisesRegex(TypeError, "null"): |
| 57 |
null > 0 |
| 58 |
with self.assertRaisesRegex(TypeError, "null"): |
| 59 |
null < 0 |
| 60 |
with self.assertRaisesRegex(TypeError, "null"): |
| 61 |
null >= 0 |
| 62 |
with self.assertRaisesRegex(TypeError, "null"): |
| 63 |
null <= 0 |
| 64 |
|
| 65 |
def testHashNull(self): |
| 66 |
null = JObject(None, java.lang.Integer) |
| 67 |
self.assertEqual(hash(null), hash(None)) |
| 68 |
null = JObject(None, java.lang.Float) |
| 69 |
self.assertEqual(hash(null), hash(None)) |
| 70 |
|
| 71 |
@common.requireInstrumentation |
| 72 |
def testJPNumber_new(self): |
| 73 |
_jpype.fault("PyJPNumber_new") |
| 74 |
|
| 75 |
class MyNum(_jpype._JNumberLong, internal=True): |
| 76 |
pass |
| 77 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 78 |
JInt(1) |
| 79 |
with self.assertRaises(TypeError): |
| 80 |
MyNum(1) |
| 81 |
_jpype.fault("PyJPModule_getContext") |
| 82 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 83 |
JInt(1) |
| 84 |
JInt(1) |
| 85 |
|
| 86 |
@common.requireInstrumentation |
| 87 |
def testJPNumberLong_int(self): |
| 88 |
ji = JInt(1) |
| 89 |
_jpype.fault("PyJPNumberLong_int") |
| 90 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 91 |
int(ji) |
| 92 |
_jpype.fault("PyJPModule_getContext") |
| 93 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 94 |
int(ji) |
| 95 |
int(ji) |
| 96 |
|
| 97 |
@common.requireInstrumentation |
| 98 |
def testJPNumberLong_float(self): |
| 99 |
ji = JInt(1) |
| 100 |
_jpype.fault("PyJPNumberLong_float") |
| 101 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 102 |
float(ji) |
| 103 |
_jpype.fault("PyJPModule_getContext") |
| 104 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 105 |
float(ji) |
| 106 |
float(ji) |
| 107 |
|
| 108 |
@common.requireInstrumentation |
| 109 |
def testJPNumberLong_str(self): |
| 110 |
ji = JInt(1) |
| 111 |
_jpype.fault("PyJPNumberLong_str") |
| 112 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 113 |
str(ji) |
| 114 |
_jpype.fault("PyJPModule_getContext") |
| 115 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 116 |
str(ji) |
| 117 |
str(ji) |
| 118 |
|
| 119 |
@common.requireInstrumentation |
| 120 |
def testJPNumberLong_repr(self): |
| 121 |
ji = JInt(1) |
| 122 |
_jpype.fault("PyJPNumberLong_repr") |
| 123 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 124 |
repr(ji) |
| 125 |
_jpype.fault("PyJPModule_getContext") |
| 126 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 127 |
repr(ji) |
| 128 |
repr(ji) |
| 129 |
|
| 130 |
@common.requireInstrumentation |
| 131 |
def testJPNumberLong_compare(self): |
| 132 |
ji = JInt(1) |
| 133 |
_jpype.fault("PyJPNumberLong_compare") |
| 134 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 135 |
ji == 1 |
| 136 |
_jpype.fault("PyJPModule_getContext") |
| 137 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 138 |
ji == 1 |
| 139 |
ji == 1 |
| 140 |
|
| 141 |
@common.requireInstrumentation |
| 142 |
def testJPNumberLong_hash(self): |
| 143 |
ji = JInt(1) |
| 144 |
_jpype.fault("PyJPNumberLong_hash") |
| 145 |
with self.assertRaises(SystemError): |
| 146 |
hash(ji) |
| 147 |
_jpype.fault("PyJPModule_getContext") |
| 148 |
with self.assertRaises(SystemError): |
| 149 |
hash(ji) |
| 150 |
hash(ji) |