def test_closurability(self): num = MutableFloat(1.0) def add(other): num.increment(other) add(2.0) add(3.0) add(10) self.assertEquals(16, num.get_val())
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() index = ClusterCandidateIndex([1, 2, 3, 4, 5], epsilon=0) candidate.distance_to_candidate = mock_dist_to_other_candidate_func index.find_neighbors_of(cluster_candidate=candidate) self.assertEquals(counter.get_val(), 5)
def mean_func(): total = MutableFloat(0.0) count = MutableNumber(0) def func(num): total.increment(num) count.increment(1) return total.get_val() / count
def test_all(self): num = MutableFloat(1.0) num.increment(3) num.increment(5) num.multiply(2) num.multiply(2) self.assertEquals(36, num.get_val())
def test_bad_val(self): self.assertRaises(Exception, MutableFloat, None) m_float = MutableFloat(0) self.assertRaises(Exception, m_float.set_val, None)