def test_gets_borders(self): par_cost_table = [[None, None], [None, None]] no_par_cost_table = [[None, None], [None, None]] list = [None] * 2 expected = [0, 1] mock_individual_cost_computer = MutableNumber(0) actual = partition_trajectory(list, self.get_mock_cost_computer(par_cost_table), \ self.get_mock_cost_computer(no_par_cost_table), \ self.create_mock_model_cost_getter_func(mock_individual_cost_computer), \ mock_individual_cost_computer) self.verify_iterable_works_more_than_once(expected, actual) self.assertEquals(mock_individual_cost_computer.get_val(), 0)
def test_get_all_of_three_item_list(self): par_cost_table = [[None, None, 6], [None, None, None], [None, None, None]] no_par_cost_table = [[None, None, 5], [None, None, None], [None, None, None]] list = [None] * 3 expected = [0, 1, 2] mock_individual_cost_computer = MutableNumber(0) actual = partition_trajectory(list, self.get_mock_cost_computer(par_cost_table), \ self.get_mock_cost_computer(no_par_cost_table), \ self.create_mock_model_cost_getter_func(mock_individual_cost_computer), \ mock_individual_cost_computer) self.verify_iterable_works_more_than_once(expected, actual) self.assertEquals(mock_individual_cost_computer.get_val(), 1 * 2)
def test_no_partition_cost_normal_case(self): segments = [1, 3, 5, 7, 9, -1, 2, 3] mock_line_seg_getter = MutableNumber(1) seg_iterable_getter = self.mock_line_segment_iterable_getter( segments, 0, 4) model_cost_computer = self.mock_adder_model_cost_computer( lambda num: num * 3) cost = no_partition_cost_computer(segments, 0, 4, seg_iterable_getter, model_cost_computer, mock_line_seg_getter) self.assertEquals(75, cost) self.assertEquals(mock_line_seg_getter.get_val(), 2)
def test_no_line_segs_provided(self): segments = [1, 3, 5, 7, 9, -2, 3, 4] mock_line_seg_getter = MutableNumber(1) seg_iterable_getter = lambda l, low, high, func: [] model_cost_computer = self.mock_adder_model_cost_computer( lambda num: num * 3) partition_line_getter = self.mock_partition_line_getter(4, 5, 3) distance_function = self.mock_global_dist_func(lambda x, y: None) self.assertRaises(Exception, no_partition_cost_computer, segments, 5, 3, \ seg_iterable_getter, model_cost_computer, mock_line_seg_getter) self.assertRaises(Exception, partition_cost_computer, segments, 5, 3, seg_iterable_getter, \ partition_line_getter, model_cost_computer, distance_function, mock_line_seg_getter) self.assertEquals(mock_line_seg_getter.get_val(), 1)
def test_partition_cost_abs_diff_distance_func(self): segments = [0, 9, 3, 1, 3, 5, 7, 9] mock_line_seg_getter = MutableNumber(1) seg_iterable_getter = self.mock_line_segment_iterable_getter( segments, 3, 8) partition_line_getter = self.mock_partition_line_getter(4, 3, 8) model_cost_computer = self.mock_adder_model_cost_computer( lambda num: num * 3) distance_function = self.mock_global_dist_func(lambda x, y: abs(x - y)) cost = partition_cost_computer(segments, 3, 8, seg_iterable_getter, \ partition_line_getter, model_cost_computer, distance_function, \ mock_line_seg_getter) self.assertEquals(25, cost) self.assertEquals(mock_line_seg_getter.get_val(), 2)
def test_get_all_of_four_item_list(self): par_cost_table = \ [[None, None, 3, 3], \ [None, None, None, 4], \ [None, None, None, None], \ [None, None, None, None]] no_par_cost_table = \ [[None, None, 2, 2], \ [None, None, None, 3], \ [None, None, None, None], \ [None, None, None, None]] list = [None] * 4 expected = [0, 1, 2, 3] mock_individual_cost_computer = MutableNumber(0) actual = partition_trajectory(list, self.get_mock_cost_computer(par_cost_table), \ self.get_mock_cost_computer(no_par_cost_table), \ self.create_mock_model_cost_getter_func(mock_individual_cost_computer), \ mock_individual_cost_computer) self.verify_iterable_works_more_than_once(expected, actual) self.assertEquals(mock_individual_cost_computer.get_val(), 2 * 2)
def test_bad_input_indices(self): segments = [1, 3, 5, 7, 9, -2, 3, 4] mock_line_seg_getter = MutableNumber(1) seg_iterable_getter = self.mock_line_segment_iterable_getter( segments, 0, 4) model_cost_computer = self.mock_adder_model_cost_computer( lambda num: num * 3) partition_line_getter = self.mock_partition_line_getter(4, 5, 3) distance_function = self.mock_global_dist_func(lambda x, y: None) self.assertRaises(IndexError, no_partition_cost_computer, segments, 5, 3, \ seg_iterable_getter, model_cost_computer, mock_line_seg_getter) self.assertRaises(IndexError, partition_cost_computer, segments, 5, 3, seg_iterable_getter, \ partition_line_getter, model_cost_computer, distance_function, mock_line_seg_getter) partition_line_getter = self.mock_partition_line_getter(4, 2, 2) self.assertRaises(IndexError, no_partition_cost_computer, segments, 2, 2, \ seg_iterable_getter, model_cost_computer, mock_line_seg_getter) self.assertRaises(IndexError, partition_cost_computer, segments, 2, 2, seg_iterable_getter, \ partition_line_getter, model_cost_computer, distance_function, mock_line_seg_getter) self.assertEquals(mock_line_seg_getter.get_val(), 1)
def test_get_some_of_four_item_list(self): par_cost_table = \ [[None, None, 2, 3], \ [None, None, None, None], \ [None, None, None, None], \ [None, None, None, None]] no_par_cost_table = \ [[None, None, 2, 2], \ [None, None, None, None], \ [None, None, None, None], \ [None, None, None, None]] list = [None] * 4 expected_partition = [0, 2, 3] mock_individual_cost_computer = MutableNumber(0) actual = partition_trajectory(list, self.get_mock_cost_computer(par_cost_table), \ self.get_mock_cost_computer(no_par_cost_table), \ self.create_mock_model_cost_getter_func(mock_individual_cost_computer), \ mock_individual_cost_computer) self.verify_iterable_equals_list(actual, expected_partition) self.assertEquals(mock_individual_cost_computer.get_val(), 2 * 2)