-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest_jump.py
58 lines (39 loc) · 1.49 KB
/
test_jump.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import hashlib
from unittest import TestCase
import jump
class JumpConsistentHashTestCase(TestCase):
"""Test the pure Python version."""
def test_hash(self):
h = jump.py_hash(1, 1)
self.assertEqual(h, 0)
h = jump.py_hash(42, 57)
self.assertEqual(h, 43)
h = jump.py_hash(0xDEAD10CC, 1)
self.assertEqual(h, 0)
h = jump.py_hash(0xDEAD10CC, 666)
self.assertEqual(h, 361)
h = jump.py_hash(256, 1024)
self.assertEqual(h, 520)
def test_negative_bucket_number(self):
self.assertRaises(ValueError, jump.py_hash, 0, -10)
self.assertRaises(ValueError, jump.py_hash, 0xDEAD10CC, -666)
def test_very_large_key(self):
jump.py_hash(int(hashlib.sha1(b"abc").hexdigest(), 16), 5)
class JumpConsistentHashExtensionTestCase(TestCase):
"""Test the C extension version."""
def test_hash(self):
h = jump.c_hash(1, 1)
self.assertEqual(h, 0)
h = jump.c_hash(42, 57)
self.assertEqual(h, 43)
h = jump.c_hash(0xDEAD10CC, 1)
self.assertEqual(h, 0)
h = jump.c_hash(0xDEAD10CC, 666)
self.assertEqual(h, 361)
h = jump.c_hash(256, 1024)
self.assertEqual(h, 520)
def test_negative_bucket_number(self):
self.assertRaises(ValueError, jump.c_hash, 0, -10)
self.assertRaises(ValueError, jump.c_hash, 0xDEAD10CC, -666)
def test_very_large_key(self):
jump.c_hash(int(hashlib.sha1(b"abc").hexdigest(), 16), 5)