def test__dependent_reference_counter_after_addref(self): num_refs = 10 ref1 = ReferenceCounter() ref2 = ReferenceCounter() for i in range(num_refs - 1): ref1.add_reference() ref1.depend_on_counter(ref2) self.assertEquals(ref1.get_reference_count(), num_refs - 1) self.assertEquals(ref2.get_reference_count(), 1) ref1.add_reference() self.assertEquals(ref1.get_reference_count(), num_refs) for iteration, _ in iterate(range(num_refs)): ref1.remove_reference() if iteration.last: self.assertEquals(ref2.get_reference_count(), 0) else: self.assertEquals(ref2.get_reference_count(), 1)
def test__dependent_reference_counter(self): ref1 = ReferenceCounter() ref2 = ReferenceCounter() ref1.depend_on_counter(ref2) self.assertEquals(ref1.get_reference_count(), 0) self.assertEquals(ref2.get_reference_count(), 0) ref1.add_reference() self.assertEquals(ref1.get_reference_count(), 1) self.assertEquals(ref2.get_reference_count(), 1) ref1.add_reference() self.assertEquals(ref1.get_reference_count(), 2) self.assertEquals(ref2.get_reference_count(), 1) ref1.remove_reference() self.assertEquals(ref1.get_reference_count(), 1) self.assertEquals(ref2.get_reference_count(), 1) ref1.remove_reference() self.assertEquals(ref1.get_reference_count(), 0) self.assertEquals(ref2.get_reference_count(), 0)