def test_validate_date_is_false_words(self): """ Test the validate date function :return: True """ v = Validator() result = v.validate_date("02-March-1991") self.assertFalse(result, 'invalid Date format')
def get_url(self): while 1: url = raw_input("Please insert URL to API :") validator = Validator() if validator.validate_url(url): self.api_url = url return 0
def test_validate_salary_is_false_negative_value(self): """ Test the validate salary function :return: True """ v = Validator() result = v.validate_salary("-20") self.assertFalse(result, 'invalid Salary')
def test_validate_salary_is_false_too_small(self): """ Test the validate salary function :return: """ v = Validator() result = v.validate_salary('8') self.assertFalse(result, 'invalid SALARY')
def test_validate_salary_is_true_3_digit(self): """ Test the validate salary function :return: True """ v = Validator() result = v.validate_salary("200") self.assertTrue(result, 'valid Salary')
def test_validate_salary_is_false_words(self): """ Test the validate salary function :return: True """ v = Validator() result = v.validate_salary("seventy thousand") self.assertFalse(result, 'valid Salary')
def __init__(self): self.modes = { 'AUTHENTICATION': self.process_token, 'VOTING': self.vote, 'FEEDBACK': self.send_feedback, self.confirm: 'CONFIRMATION' } self.key_val = Validator(KEYS_FILE)
def __init__(self, hps, device): self.hps = hps self.device = device # load validator # when paired validation data is available, we also calculate bleu if hps.paired_valid_data is not None: self.bleu_validator = Validator(hps.paired_valid_data, device)
def representation(): is_validation_pass, flash_message = Validator( request, request.files['file']).get_results() if not is_validation_pass: flash(flash_message) return render_template('index.html') return render_template('representation.html')
def test_validate_method_name_is_false2(self): validator = Validator() result_1 = validator.validate_method_name("Name") result_2 = validator.validate_method_name("get_Name") result_3 = validator.validate_method_name("1_get") self.assertFalse(result_1) self.assertFalse(result_2) self.assertFalse(result_3)
def validate_text(self): brackets = self.inputBracketsLineEdit.text() if len(brackets) % 2 != 0 or brackets == '': QMessageBox.warning(self, 'Alarm', 'Incorrect number of brackets') validator = Validator(brackets) self.inputTextEdit.setText( validator.validate(self.inputTextEdit.toPlainText()))
def test_validate_salary_is_true_small_but_includes_zero(self): """ Test the validate salary function :return: """ v = Validator() result = v.validate_salary('008') self.assertTrue(result, 'valid SALARY')
def test_validate_date_is_true(self): """ Test the validate date function :return: True """ v = Validator() result = v.validate_date("02-03-1990") self.assertTrue(result, 'valid Date')
def test_09_validate_bmi_is_true(self): """ Test the validate bmi true function :return: """ v = Validator() result = v.validate_bmi("Normal") self.assertTrue(result, "Valide BMI")
def test_validate_date_is_false_invalid_format(self): """ Test the validate date function :return: """ v = Validator() result = v.validate_date('01/08/1991') self.assertFalse(result, 'invalid date, wrong format')
def test_11_validate_bmi_is_false_notEqualN(self): """ Test the validate bmi true function :return: """ v = Validator() result = v.validate_bmi("N") self.assertNotEqual(result, 'Normal', "Invaid BMI")
def test_10_validate_bmi_is_false_space(self): """ Test the validate bmi true function :return: """ v = Validator() result = v.validate_bmi(" ") self.assertFalse(result, "Invalid BMI")
def test_14_validate_bmi_is_false_notequal_over(self): """ Test the validate bmi true function :return: """ v = Validator() result = v.validate_bmi("OVERWEIGHT") self.assertNotEqual(result, 'Overweight', "Invaid BMI")
def test_12_validate_bmi_is_false_notEqualO(self): """ Test the validate bmi true function :return: """ v = Validator() result = v.validate_bmi("OBESITY") self.assertNotEqual(result, 'Obesity', "Invaid BMI")
def test_validate_age_is_false_negative_num(self): """ Test the validate age function :return: """ v = Validator() result = v.validate_age('-20') self.assertFalse(result, 'invalid AGE')
def test_15_validate_bmi_is_false_notequal_under(self): """ Test the validate bmi true function :return: """ v = Validator() result = v.validate_bmi("U") self.assertNotEqual(result, 'Underweight', "Invaid BMI")
def test_validate_age_is_true(self): """ Test the validate age function :return: True """ v = Validator() result = v.validate_age("20") self.assertTrue(result, 'valid AGE')
def test_validate_date_is_false_invalid_date(self): """ Test the validate date function :return: """ v = Validator() result = v.validate_date('89/13/1991') self.assertFalse(result, 'invalid date, date doesnt exist')
def test_check_field_bmi(self): v = Validator() self.assertTrue(v.check_field('BMI', 'Normal')) self.assertTrue(v.check_field('BMI', 'Overweight')) self.assertTrue(v.check_field('BMI', 'Obesity')) self.assertTrue(v.check_field('BMI', 'Underweight')) self.assertFalse(v.check_field('BMI', 21)) self.assertFalse(v.check_field('BMI', 'A0501'))
def test_validate_regex(self): row = OrderedDict([('Product Number', 'P-10001'), ('__row_number', 1)]) validations = {'Product Number': [{'method': 'regex', 'kwargs': {'pattern': '\\d+'}}]} with self.assertLogs(level='ERROR') as log_output: # A failing regex match should log a ValueError on Row 1 is_valid = Validator(validations=validations).validate_row(row) self.assertFalse(is_valid) self.assertTrue('ERROR on ROW 1' in log_output.output[0]) self.assertTrue('ValueError' in log_output.output[0]) error_logs_count = len(log_output) # Test same row value against a valid regex validations = {'Product Number': [{'method': 'regex', 'kwargs': {'pattern': '[A-Z]+-\\d+'}}]} is_valid = Validator(validations=validations).validate_row(row) self.assertTrue(is_valid) # No more error logs should have been produced self.assertEqual(error_logs_count, len(log_output))
def val_thread(port): val = Validator(port=port) val.create_connections() while True: val.receive() if len(val.mempool) == 5: blk = val.create_block(0, 5) print(blk) break
def setUp(self): """ Create a validator and add one note to it. Note(delay=100, height=15, duration=100) """ self.the_note = Note(delay=100, height=15, duration=100) score = Score([self.the_note]) self.validator = Validator(score, margin=10) self.validator.add_reference_note(self.the_note)
def get_consequent_atoms(self): if not self.consequent_atoms: atoms = [] validate = Validator() for token in self.get_consequent(): if validate.is_fact(token): atoms.append(token) self.consequent_atoms = atoms return self.consequent_atoms
def main(): # Check if the number of command line arguments is correct if len(sys.argv) < 6: print( "-- python --|-- main.py --|-- L --|-- K --|-- training_set.csv --|-- validation_set.csv --|-- test_set.csv --|" ) sys.exit(1) # The program takes two integer L and K as input to prune the decision tree L = int(sys.argv[1]) K = int(sys.argv[2]) # Get the file path of the training data, validation data and test data dataDir = './data1/' training_set = dataDir + sys.argv[3] validation_set = dataDir + sys.argv[4] test_set = dataDir + sys.argv[5] # Build a decision tree on training data decisionTree = DecisionTree(training_set) ############################################# # decisionTree.exportTree('tree.txt') # print decisionTree ############################################# # Create a validator using test data to calculate the prediction accuracy of a given decision tree validator = Validator(test_set) # Calculate the prediction accuracy of the original decision tree on test data validator.calculateAccuracy(decisionTree.root) # Display the prediction accuracy before pruning print("\nA decision tree is fully grown to fit the training data.") validator.displayAccuracy() # Post pruning the decision tree print("\nPost prunning", '.' * 30) print("L =", L, ", K =", K, ", the pruned decision tree is:\n") # Prune the original decision tree using L, K and validation data as inputs decisionTree.pruneTree(L, K, validation_set) ############################################## # decisionTree.exportTree('pruned_tree.txt') ############################################## # print the decision tree to standard output print(decisionTree) # Override the __str__ method in DecisionTree class # Calculate the prediction accuracy of the pruned decision tree on test data validator.calculateAccuracy(decisionTree.root) # Display the prediction accuracy after pruning validator.displayAccuracy()
def setUp(self): view = CmdView() data_vis = DataVis() validator = Validator() format = Format() pickle = Pickle() db = Database('company.db') self.con = Controller(view, data_vis, validator, format, pickle, db) view.controller_set(self.con)