def put_effective_calcs(effective_calcs): return_value = tslib.tsput(effective_calcs_name, str(effective_calcs), sys.getsizeof(str(effective_calcs))) if return_value == 1: return 1 else: return 0
def put_global_minimum(global_min): return_value = tslib.tsput(global_minimum_name, str(global_min), sys.getsizeof(str(global_min))) if return_value == 1: return 1 else: return 0
def put_start(num_dimensions): return_value = tslib.tsput(start_tuple_name, num_dimensions, sys.getsizeof(num_dimensions)) if return_value == 1: return 1 else: return 0
def main(): now = datetime.datetime.now() print("Current date and time: ") print(str(now)) print("writing date to tuple") tuple_size = 200 tuple_name = "date" return_value = tslib.tsput(tuple_name, str(now), tuple_size) if return_value == 1: print( "ERROR, tsput returned 1, failure detected, integration test failed" ) sys.exit(1) else: print("return value from tsput : " + str(return_value)) partial_tuple = "da" string_from_tuple_space, matched_tuple_name = tslib.tsread( partial_tuple, tuple_size) if matched_tuple_name.decode('utf-8') != tuple_name: print("ERROR, tsread regex matching from: " + partial_tuple + " | " + matched_tuple_name.decode('utf-8') + " failed, integration test failed") sys.exit(1) else: print("matched tuple name : " + matched_tuple_name.decode('utf-8')) if string_from_tuple_space.decode('utf-8') != str(now): print("ERROR, value retrived from tuple space does not match: " + string_from_tuple_space.decode('utf-8') + " | " + str(now) + " integration test failed") sys.exit(1) print("value retrieved from tuple space : " + string_from_tuple_space.decode('utf-8')) string_from_tuple_space = None string_from_tuple_space, matched_tuple_name = tslib.tsget( "date", tuple_size) if matched_tuple_name.decode('utf-8') != tuple_name: print( "ERROR, tsget regex matching from 'da' to 'date' failed, integration test failed" ) sys.exit(1) else: print("matched tuple name : " + matched_tuple_name.decode('utf-8')) if string_from_tuple_space.decode('utf-8') != str(now): print("ERROR, value retrived from tuple space does not match: " + string_from_tuple_space.decode('utf-8') + " | " + str(now) + " integration test failed") sys.exit(1) print("value retrieved from tuple space : " + string_from_tuple_space.decode('utf-8')) print( "INTEGRATION TEST PASSED, TUPLE PUT INTO SPACE AND RETRIVED ON BOTH PARTIAL AND FULL TUPLE MATCH WITH CORRECT VALUES" ) sys.exit(0)
def put_best_tour(best_tour, num_vertices): # use matrix size * size of int, which should be enough return_value = tslib.tsput(best_tour_name, str(best_tour), sys.getsizeof(int()) * num_vertices) if return_value == 1: return 1 else: return 0
def put_cost_matrix_in_tuple_space(matrix_name, matrix): matrix_as_json_string = matrix.to_json() size = len(matrix_as_json_string) return_value = tslib.tsput(matrix_name, matrix_as_json_string, size) if return_value == 1: return 1 else: return 0
def put_tour(tour, tour_identifier): tour_as_json = tour.to_json() tour_as_json_size = TspTour.get_max_tour_size() return_value = tslib.tsput(tour_identifier, tour_as_json, tour_as_json_size) if return_value == 1: return 1 else: return 0
def test_tsput_success(self): tp_name = "testTuple" tp_value = "This is the tuple value" tp_size = 100 tslib.libso.tsput = MagicMock() MagicMock.return_value = 100 return_value = tslib.tsput(tp_name, tp_value, tp_size) self.assertEqual(return_value, 0) tslib.libso.tsput.assert_called_with(tp_name, tp_value, tp_size)
def test_tsput_failure(self): tp_name = "testTuple" tp_value = "This is the tuple value" tp_size = 100 tslib.libso.tsput = MagicMock() # think this is the 'real' tsput err code MagicMock.return_value = -104 return_value = tslib.tsput(tp_name, tp_value, tp_size) self.assertEqual(return_value, 1) tslib.libso.tsput.assert_called_with(tp_name, tp_value, tp_size)