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