def Create_device(): if request.method == 'POST': data_device = Validator().Add_device(data, request.data) if data_device['status']: return jsonify({'msg': data_device['message']}), status.HTTP_200_OK else: return jsonify({'msg': data_device['message'] }), status.HTTP_400_BAD_REQUEST if request.method == 'GET': return jsonify({'msg': Validator().Display_device(data)}), status.HTTP_200_OK
def test_validator_age_invalid_string(self): val = Validator() test_data = "Blah" expected_result = False actual_result = val.Validate_Age(test_data)[0] self.assertEqual(actual_result, expected_result, "actaul_result should equal" + str(expected_result))
def Update_devices(source, strength): if request.method == 'PUT': result = Validator().Update_device(data, source, request.data) if result['status']: return jsonify({'msg': result['message']}), status.HTTP_200_OK, return jsonify({'msg': result['message']}), status.HTTP_200_OK,
def __init__(self, dir_path, file_name=None): self.validator = Validator() self.validator.is_folder(dir_path) self.file_name = file_name self.dir_path = dir_path self.delimiter = ';' self.sep = ';'
def __init__(self, matrix, alpha, beta, p, ants_n, t_max, Q): self.validator = Validator() self.subject = matrix self.alpha = alpha self.beta = beta self.p = p self.Q = Q self.L = self.INFINITY self.path = list() self.ants_n = ants_n self.t_max = t_max self.cities = len(self.subject) self.ants = list() for i in range(0, self.ants_n): a = Ant(self.cities) self.ants.append(a) self.pheromones = list() for i in range(0, len(self.subject)): self.pheromones.append(list()) for j in range(0, len(self.subject[i])): if i == j: self.pheromones[i].append(0) else: self.pheromones[i].append(1.0)
def test_validator_empid_false_2(self): val = Validator() employee_place_holder = '' test_data = '3201' actual_result, error_message = val.val_empid(employee_place_holder, test_data) self.assertFalse(actual_result, error_message)
def __init__(self, path): self.myModel = Model(Filer(), Validator()) if path != "" or path is not None: self.load_data(path) self.myView = View(self) self.myModel.pickle_data() self.myView.cmdloop()
def test_validator_empid_true(self): val = Validator() employee_place_holder = '' test_data = 'A201' actual_result = val.val_empid(employee_place_holder, test_data) self.assertTrue(actual_result)
def test_validator_age_valid_1(self): val = Validator() test_data = 23 expected_result = True actual_result = val.Validate_Age(test_data)[0] self.assertEqual(actual_result, expected_result, "actaul_result should equal" + str(expected_result))
def test_file_input(self): self.myFiler = Filer() self.myValidator = Validator() self.myModel = Model(self.myFiler,self.myValidator) self.myFiler.read("TestData.csv") self.myModel.toDataSet() self.failIfEqual(self.myModel.get_data_set(), None)
def test_validator_id(self): self.myValidator = Validator() self.result = self.myValidator.match_id("D003") self.expected = None self.failIfEqual(self.result, self.expected) self.result = self.myValidator.match_id("DDD03") self.expected = None self.failUnlessEqual(self.result, self.expected)
def test_validator_birthday_invalid_string_age(self): val = Validator() test_data_1 = "11-25-1991" test_data_2 = "Yahhh" expected_result = False actual_result = val.Validate_Birthday(test_data_1, test_data_2)[0] self.assertEqual(actual_result, expected_result, "actaul_result should equal" + str(expected_result))
def test_validator_birthday_invalid_not_date_error_message(self): val = Validator() test_data_1 = "11-25-1991" test_data_2 = 27 expected_result = "Birthday is not a valid date" actual_result = val.Validate_Birthday(test_data_1, test_data_2)[1] self.assertEqual(actual_result, expected_result, "actaul_result should equal" + str(expected_result))
def Create_connections(): if request.method == 'POST': result = Validator().Connector(data, request.data) if result['status']: return jsonify({'msg': result['message']}), status.HTTP_200_OK, else: return jsonify({'msg': result['message']}), status.HTTP_400_BAD_REQUEST,
def test_validator_sales(self): self.myValidator = Validator() self.result = self.myValidator.match_sales("235") self.expected = None self.failIfEqual(self.result, self.expected) self.result = self.myValidator.match_sales("FED") self.expected = None self.failUnlessEqual(self.result, self.expected)
def test_validator_weight(self): self.myValidator = Validator() self.result = self.myValidator.match_weight("Normal") self.expected = None self.failIfEqual(self.result, self.expected) self.result = self.myValidator.match_weight("F") self.expected = None self.failUnlessEqual(self.result, self.expected)
def test_validator_age(self): self.myValidator = Validator() self.result = self.myValidator.match_age("13") self.expected = None self.failIfEqual(self.result, self.expected) self.result = self.myValidator.match_age("F") self.expected = None self.failUnlessEqual(self.result, self.expected)
def test_validator_gender(self): self.myValidator = Validator() self.result = self.myValidator.match_gender("M") self.expected = None self.failIfEqual(self.result, self.expected) self.result = self.myValidator.match_gender("G") self.expected = None self.failUnlessEqual(self.result, self.expected)
def test_validator_birthday_valid(self): val = Validator() test_data_1 = "25-11-1991" test_data_2 = 26 expected_result = True actual_result = val.Validate_Birthday(test_data_1, test_data_2)[0] self.assertEqual(actual_result, expected_result, "actaul_result should equal" + str(expected_result))
def test_validator_birthday_invalid_wrong_age_error_message(self): val = Validator() test_data_1 = "25-11-1991" test_data_2 = 27 expected_result = "The age given and birthday do not line up" actual_result = val.Validate_Birthday(test_data_1, test_data_2)[1] self.assertEqual(actual_result, expected_result, "actaul_result should equal" + str(expected_result))
def __init__ (self, training_data=None, target=None): self.epsilon = Constants().get_rbfn_deafult_epsilon() self.k = Constants().get_rbfn_default_k() self.base_function_type = Constants().get_rbfn_gaussian_abbreviation() self.training_data = training_data self.target = target self.solver = Constants().get_solver_ls_abbreviation() self.validator = Validator()
def test_csv_file_input(self): self.myFiler = Filer() self.myValidator = Validator() self.myModel = Model(self.myFiler,self.myValidator) self.myFiler.read("TestData.csv") self.expected = 12 self.myModel.toDataSet() self.failUnlessEqual(self.myModel.get_data_set().__len__(), self.expected)
def test_washing_data(self): # There are 5 errors so length should be cut down to 7 after washing self.myFiler = Filer() self.myValidator = Validator() self.myModel = Model(self.myFiler,self.myValidator) self.myFiler.read("TestData.csv") self.expected = 8 self.myModel.toDataSet() self.failUnlessEqual(self.myModel.wash_data().__len__(), self.expected)
def __init__(self, file_path, file_name): self.validator = Validator() self.validator.is_folder(file_path) self.normalized = False self.norm = None self.file_name = file_name self.file_path = file_path self.data, self.header = self.set_data() self.rbfn = RBFN()
def Does_path_exist(): if request.method == 'GET': result = Validator().Check_path(data, request.args.get('from'), request.args.get('to')) print(result) if result['status']: return jsonify({'msg': result['message']}), status.HTTP_200_OK else: return jsonify({'msg': result['message']}), status.HTTP_400_BAD_REQUEST
def main(): p = Problem() controller = Controller(15, p.getSize(), 100) permSolution = controller.runAlgorithm() finalSolution = p.giveFinalSolution(permSolution[0]) validator = Validator(1000, 30, 40) validator.plotACO for i in range(len(finalSolution)): print(finalSolution[i])
def allocate(self): exec("self.allocator = " + self.allocation + "()") self.allocator.allocate(self.electors, self.data) validator = Validator() valid, allocated = validator.validate(self.electors, self.data) if not valid: raise Exception("Correct Number of Electors Not Allocated: " + str(allocated)) dq = DemocracyQuotient().calc(self.data) return self.data, dq
def __init__(self, players, updater=None): self.players = players self.nplayers = len(players) self.state = GameState(self.nplayers) self.validator = Validator(self.state) self.logger = logging.getLogger(__name__) if updater is not None: self.update = ViewUpdater() else: self.update = updater self.delay = 0.5 self.stalematecond = 2000
def play(self): """ This method is the core of game which takes care of game's status """ won = False who = -1 board = Board(3, 3) validator = Validator(3, 3) self.first = input("First player please input your Name:\n>> ") self.second = input("Second player please input your Name:\n>> ") while (won is not True): if board.isfull() is not True: r = int( input( f"{self.first}: give row number where you want to put cross\n>> " )) c = int( input( f"{self.first}: give column number where you want to put cross\n>> " )) board.update_board(r - 1, c - 1, 1) board.print_board() won = validator.check_if_won(board.board, 1) if (won is True): who = 1 break else: print("Sorry No one won !") return if board.isfull() is not True: r = int( input( f"{self.second}: give row number where you want to put circle\n>> " )) c = int( input( f"{self.second}: give column number where you want to put circle\n>> " )) board.update_board(r - 1, c - 1, 0) board.print_board() won = validator.check_if_won(board.board, 0) if (won is True): who = 2 break else: print("Sorry No one won !") return if (who == 1): print(f"Congrats {self.first} You won the game!") else: print("Congrats {self.second} You won the game!")
def upload_workflow_input_files(self, wdl_file, json_file): """ Given workflow inputs, parse them to determine which inputs are files or files containing file paths, and upload those files to the bucket specified by the SingleBucket instance. :param wdl_file: File containing workflow description. Used to determine which workflow inputs are files. :param json_file: JSON inputs to wdl. Contains actual paths to files. :return: A list of files that were uploaded. """ v = Validator(wdl_file, json_file) # get all the wdl arguments and figure out which ones are file inputs, store them in an array. wdl_args = v.get_wdl_args() file_keys = {k: v for k, v in wdl_args.iteritems() if 'File' in v}.keys() json_dict = v.get_json() files_to_upload = list() for file_key in file_keys: # need to make sure that keys in wdl args but not json dict aren't processed as file keys. # also, need to skip gs urls since they are already uploaded. if file_key in json_dict.keys( ) and "gs://" not in json_dict[file_key]: if 'fofn' in file_key: # get files listed in the fofn and add them to list of files to upload files_to_upload.extend( get_files_from_fofn(json_dict[file_key])) """ Next don't want to upload the original fofn because it won't have the 'gs://' prefix for the files in. Therefore need to create a new fofn that has updated paths, and we add that to files_to_upload. """ new_fofn = update_fofn(json_dict[file_key], self.bucket.name) files_to_upload.append(new_fofn) else: if isinstance(json_dict[file_key], list): for f in json_dict[file_key]: if "gs://" not in f: files_to_upload.append(f) elif isinstance(json_dict[file_key], dict): file_dict = json_dict[file_key] for k, v in file_dict.iteritems( ): #assume all Map with File are Map[?,File] if "gs://" not in v: files_to_upload.append(v) else: files_to_upload.append(json_dict[file_key]) self.upload_files(files_to_upload) return files_to_upload