def setUp(self): self.s = Switch(ipp=selfipp) self.em = EndManager(self.s) self.ce = End(closeipp) self.ce2 = End(closeipp2) self.ce3 = End(closeipp3) self.me = End(mediumipp) self.fe = End(faripp)
class TestEndManager(TestCase): def setUp(self): self.s = Switch(ipp=selfipp) self.em = EndManager(self.s) self.ce = End(closeipp) self.ce2 = End(closeipp2) self.ce3 = End(closeipp3) self.me = End(mediumipp) self.fe = End(faripp) def test_end_manager_add_end_adds_end_at_correct_distance(self): self.em.add(self.ce) bucket = self.em._buckets[hash.distance(self.s.ipp, self.ce)] assert bucket[hash.hexhash(self.ce)] def test_bucket_for_gives_correct_bucket(self): self.em.add(self.ce) d1 = hash.distance(self.s.ipp, self.ce) assert self.em._buckets[d1] is self.em.bucket_for(self.ce) self.em.add(self.fe) d2 = hash.distance(self.s.ipp, self.fe) assert self.em._buckets[d2] == self.em.bucket_for(self.fe)