Debian Codegraph @

test/jpypetest/test_number.py

raw symbols SCIP
1 # *****************************************************************************
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 #
15 # See NOTICE file for details.
16 #
17 # *****************************************************************************
18 import sys
19 import jpype
20 import common
21 import random
22 import _jpype
23 import jpype
24 from jpype import java
25 from jpype.types import *
26 try:
27 import numpy as np
28 except ImportError:
29 pass
30
31
32 class JNumberTestCase(common.JPypeTestCase):
33 def setUp(self):
34 common.JPypeTestCase.setUp(self)
35 self.cls = JClass("jpype.common.Fixture")
36 self.fixture = self.cls()
37
38 def testJavaPrimitives(self):
39 self.assertIsInstance(
40 self.fixture.callNumber(JByte(1)), java.lang.Byte)
41 self.assertIsInstance(
42 self.fixture.callNumber(JShort(1)), java.lang.Short)
43 self.assertIsInstance(
44 self.fixture.callNumber(JInt(1)), java.lang.Integer)
45 self.assertIsInstance(
46 self.fixture.callNumber(JLong(1)), java.lang.Long)
47 self.assertIsInstance(
48 self.fixture.callNumber(JFloat(1)), java.lang.Float)
49 self.assertIsInstance(self.fixture.callNumber(
50 JDouble(1)), java.lang.Double)
51
52 def testPythonPrimitives(self):
53 self.assertIsInstance(self.fixture.callNumber(1), java.lang.Long)
54 self.assertIsInstance(self.fixture.callNumber(1.0), java.lang.Double)
55
56 @common.requireNumpy
57 def testNumpyPrimitives(self):
58 self.assertIsInstance(
59 self.fixture.callNumber(np.int8(1)), java.lang.Byte)
60 self.assertIsInstance(self.fixture.callNumber(
61 np.int16(1)), java.lang.Short)
62 self.assertIsInstance(self.fixture.callNumber(
63 np.int32(1)), java.lang.Integer)
64 self.assertIsInstance(self.fixture.callNumber(
65 np.int64(1)), java.lang.Long)
66 self.assertIsInstance(self.fixture.callNumber(
67 np.float32(1)), java.lang.Float)
68 self.assertIsInstance(self.fixture.callNumber(
69 np.float64(1)), java.lang.Double)