Debian Codegraph @

test/jpypetest/test_hash.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 jpype
19 import common
20 import sys
21
22
23 class HashTestCase(common.JPypeTestCase):
24
25 def setUp(self):
26 common.JPypeTestCase.setUp(self)
27
28 def testHashString(self):
29 self.assertIsNotNone(hash(jpype.java.lang.String("upside down")))
30 self.assertIsNotNone(hash(jpype.JString("upside down")))
31 self.assertEqual(hash(jpype.JString("upside down")),
32 hash("upside down"))
33
34 def testHashArray(self):
35 self.assertIsNotNone(hash(jpype.JArray(jpype.JInt)([1, 2, 3])))
36
37 def testHashObject(self):
38 self.assertIsNotNone(hash(jpype.java.lang.Object()))
39
40 def testHashBoolean(self):
41 self.assertIsNotNone(hash(jpype.java.lang.Boolean(True)))
42 self.assertEqual(hash(jpype.java.lang.Boolean(True)), hash(True))
43
44 def testHashByte(self):
45 self.assertIsNotNone(hash(jpype.java.lang.Byte(5)))
46 self.assertEqual(hash(jpype.java.lang.Byte(5)), hash(5))
47
48 def testHashChar(self):
49 self.assertIsNotNone(hash(jpype.java.lang.Character("a")))
50 # Differences in implementation yield different hashes currently.
51 #self.assertEqual(hash(jpype.java.lang.Character("a")), hash("a"))
52
53 def testHashShort(self):
54 self.assertIsNotNone(hash(jpype.java.lang.Short(1)))
55 self.assertEqual(hash(jpype.java.lang.Short(1)), hash(1))
56
57 def testHashLong(self):
58 self.assertIsNotNone(hash(jpype.java.lang.Long(55)))
59 self.assertEqual(hash(jpype.java.lang.Long(55)), hash(55))
60
61 def testHashInteger(self):
62 self.assertIsNotNone(hash(jpype.java.lang.Integer(123)))
63 self.assertEqual(hash(jpype.java.lang.Integer(123)), hash(123))
64
65 def testHashFloat(self):
66 self.assertIsNotNone(hash(jpype.java.lang.Float(3.141592)))
67
68 def testHashDouble(self):
69 self.assertIsNotNone(hash(jpype.java.lang.Double(6.62607004e-34)))
70
71 def testHashNone(self):
72 self.assertEqual(hash(None), hash(jpype.JObject(None)))
73 q = jpype.JObject(None, jpype.java.lang.Double)
74 self.assertEqual(hash(None), hash(jpype.JObject(None)))