def get_sorted_solutions_indexes_test(): mocked_pb_response = build_mocked_response() candidates_pool, sections_set = new_default._build_candidate_pool_and_sections_set( mocked_pb_response) selected_sections_matrix = new_default._build_selected_sections_matrix( sections_set, candidates_pool) best_indexes, selection_matrix = new_default._get_sorted_solutions_indexes( selected_sections_matrix, 5) assert best_indexes.shape[0] == 27 assert all(selection_matrix[best_indexes[0]] == [0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0])
def build_candidate_pool_and_sections_set_test(): mocked_pb_response = build_mocked_response() candidates_pool, sections_set = new_default._build_candidate_pool_and_sections_set( mocked_pb_response) selected_sections_matrix = new_default._build_selected_sections_matrix( sections_set, candidates_pool) # selected_sections_matrix should have 13 lines(13 journeys) and 7 columns(7 sections) assert selected_sections_matrix.shape == (13, 7) # it's too verbose to check the entire matrix... we check only two lines assert [1, 0, 1, 0, 1, 0, 1] in selected_sections_matrix assert [0, 0, 0, 1, 1, 1, 1] in selected_sections_matrix
def get_sorted_solutions_indexes_test(): mocked_pb_response = build_mocked_response() candidates_pool, sections_set, idx_jrny_must_keep = new_default._build_candidate_pool_and_sections_set( mocked_pb_response.journeys ) selected_sections_matrix = new_default._build_selected_sections_matrix(sections_set, candidates_pool) # 4 journeys are must-have, we'd like to select another 5 journeys best_indexes, selection_matrix = new_default._get_sorted_solutions_indexes( selected_sections_matrix, (5 + 4), idx_jrny_must_keep ) assert best_indexes.shape[0] == 33 assert all(selection_matrix[best_indexes[0]] == [0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0])
def build_candidate_pool_and_sections_set_test(): mocked_pb_response = build_mocked_response() candidates_pool, sections_set, idx_jrny_must_keep = new_default._build_candidate_pool_and_sections_set( mocked_pb_response.journeys ) selected_sections_matrix = new_default._build_selected_sections_matrix(sections_set, candidates_pool) # selected_sections_matrix should have 19 lines(19 journeys) and 11 columns(11 sections) assert selected_sections_matrix.shape == (19, 11) # it's too verbose to check the entire matrix... we check only two lines assert [1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1] in selected_sections_matrix assert [0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1] in selected_sections_matrix
def create_candidate_pool_and_sections_set_test(): """ Given response, the tested function should return a candidate pool and a section set """ mocked_pb_response = build_mocked_response() candidates_pool, sections_set, idx_jrny_must_keep = \ new_default._build_candidate_pool_and_sections_set(mocked_pb_response) # We got 19 journeys in all and 4 of them are tagged with 'best', 'comfort', 'non_pt_bike', 'non_pt_walk' assert candidates_pool.shape[0] == 19 assert len(idx_jrny_must_keep) == 4 assert len(sections_set) == 11
def create_candidate_pool_and_sections_set_test(): """ Given response, the tested function should return a candidate pool and a section set """ mocked_pb_response = build_mocked_response() candidates_pool, sections_set = new_default._build_candidate_pool_and_sections_set( mocked_pb_response) # We got 17 journeys in all and 4 of them are tagged with 'best', 'comfort', 'non_pt_bike', 'non_pt_walk' assert candidates_pool.shape[0] == (17 - 4) # We got 11 sections in all and 4 of them are included in J14, J15, J16 and J17 # they should be excluded from the section_set to avoid redundant computation assert len(sections_set) == (11 - 4)