136 ring.add_node(("192.168.10.%s" % str(10 + n), "%s" % str(10 + n)))
137 self.assertEqual(
138 len([n[0] for n in ring.ring]),
139 len(set([n[0] for n in ring.ring])))140
141 def test_7_node_positional_integrity(self):
142 """Make a cluster, verify we don't have positional collisions"""
163 ring.add_node(("192.168.10.%s" % str(10 + n), "%s" % str(10 + n)))
164 self.assertEqual(
165 len([n[0] for n in ring.ring]),
166 len(set([n[0] for n in ring.ring])))167
168
169class ConsistentHashRingTestFNV1A(unittest.TestCase):
20 ring.add_node(("192.168.10.%s" % str(10 + n), "%s" % str(10 + n)))
21 self.assertEqual(
22 len([n[0] for n in ring.ring]),
23 len(set([n[0] for n in ring.ring]))) 24
25 def test_4_node_positional_integrity(self):
26 """Make a cluster, verify we don't have positional collisions"""
154 ring.add_node(("192.168.10.%s" % str(10 + n), "%s" % str(10 + n)))
155 self.assertEqual(
156 len([n[0] for n in ring.ring]),
157 len(set([n[0] for n in ring.ring])))158
159 def test_9_node_positional_integrity(self):
160 """Make a cluster, verify we don't have positional collisions"""
145 ring.add_node(("192.168.10.%s" % str(10 + n), "%s" % str(10 + n)))
146 self.assertEqual(
147 len([n[0] for n in ring.ring]),
148 len(set([n[0] for n in ring.ring])))149
150 def test_8_node_positional_integrity(self):
151 """Make a cluster, verify we don't have positional collisions"""
Although there is nothing syntactically wrong with this code, it is hard to read and can be simplified to a set comprehension. Using set comprehension is more performant since there is no need to create a transient list.
mapping = set([num for num in my_magic_nums])
mapping = {num for num in my_magic_nums}