def test_calls_dist_to_other_candidate_when_finding_candidates(self): counter = MutableFloat(0) def mock_dist_to_other_candidate_func(other_candidate): counter.increment(1) return 0 candidate = ClusterCandidate() candidate.distance_to_candidate = mock_dist_to_other_candidate_func candidate.find_neighbors([1, 2, 3, 4, 5], epsilon=0) self.assertEquals(counter.get_val(), 5)
def test_calls_dist_to_other_candidate_when_finding_candidates(self): counter = MutableFloat(0) def mock_dist_to_other_candidate_func(other_candidate): counter.increment(1) return 0 candidate = ClusterCandidate() candidate.distance_to_candidate = mock_dist_to_other_candidate_func candidate.find_neighbors([1, 2, 3, 4, 5], epsilon=0) self.assertEquals(counter.get_val(), 5)
def find_neighbors(self, candidates, epsilon): neighbors = ClusterCandidate.find_neighbors(self, candidates, epsilon) if self.num_neighbors != -1 and self.num_neighbors != len(neighbors): raise Exception("neighbors count should never be changing") self.num_neighbors = len(neighbors) return neighbors