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() 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 mock_global_dist_func(self, func): total = MutableFloat(0.0) def mock(num, other_num): total.increment(func(num, other_num)) return total.get_val() return mock
def mock_adder_model_cost_computer(self, func): total = MutableFloat(0.0) def mock(num): total.increment(func(num)) return total.get_val() return mock
def mock_geometric_series_model_cost_computer(self): total = MutableFloat(1.0) def mock(num): total.multiply(num) return total.get_val() return mock
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)
def get_number_list_reducer_that_returns_each_midway_val(func): total = MutableFloat(0.0) def _func(num): total.increment(func(num)) return total.get_val() return _func