def read_country_info(self): csv_reader = CsvReader() fields, lines = csv_reader.read_csv(csv_file="kerstpuzzel_landen.csv", header_present=True) countries = csv_reader.transform_csv_structure_into_json_structure(fields, lines) self.population = {} self.area = {} for country in countries: self.population[country["Land"]] = int(country["Inwoners"]) self.area[country["Land"]] = int(country["Oppervlak"])
def test_multiplication(self): print("Unit Test for Multiplication") test_data = CsvReader( '/src/csvTestData/Unit Test Multiplication.csv').data for row in test_data: self.assertEqual( self.calculator.multiply(row['Value 1'], row['Value 2']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result']))
def test_subtraction(self): print("Unit Test for Subtraction") test_data = CsvReader( '/src/csvTestData/Unit Test Subtraction.csv').data for row in test_data: self.assertEqual( self.calculator.subtract(row['Value 1'], row['Value 2']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result']))
def test_addition(self): test_data = CsvReader('/src/Addition.csv').data for row in test_data: self.assertEqual( self.calculator.subtract(row['Value 1'], row['Value 2']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result']))
def test_mul(self): test_data_mul = CsvReader( "/src/CsvData/Multiplication.csv").return_data_as_mul() for row in test_data_mul: result_mul = float(row['Result']) self.assertEqual( self.calculator.subtract(row['Value 1'], row['Value 2']), result_mul) self.assertEqual(self.calculator.result, result_mul)
def test_squareroot(self): print("Unit Test for Square Root") test_data = CsvReader( '/src/csvTestData/Unit Test Square Root.csv').data for row in test_data: self.assertEqual(self.calculator.squareroot(row['Value 1']), round(float(row['Result']), 8)) self.assertEqual(self.calculator.result, round(float(row['Result']), 8))
def test_squareroot(self): print("________Square Root________") test_data = CsvReader('/src/csv/Square_Root.csv').data for row in test_data: self.calculator.sqroot(int(row['Value 1'])) self.assertAlmostEqual(self.calculator.result, float(row['Result'])) print('√', row['Value 1'], '=', self.calculator.result)
def test_addition(self): test_data_add = CsvReader( "/src/CsvData/Addition.csv").return_data_as_addition() for row in test_data_add: result_add = float(row['Result']) self.assertEqual( self.calculator.subtract(row['Value 1'], row['Value 2']), result_add) self.assertEqual(self.calculator.result, result_add)
def test_division(self): test_data = CsvReader('csvFiles/division.csv').data for row in test_data: self.assertEqual( self.calculator.divide(int(row['Value 1']), int(row['Value 2'])), format(float(row['Result']), '.7f')) self.assertEqual(self.calculator.result, format(float(row['Result']), '.7f'))
def test_division(self): test_data = CsvReader( "src/CsvData/Division.csv").return_data_as_division() for row in test_data: result = round(float(row['Result']), 9) self.assertEqual( self.calculator.division(row['Value 1'], row['Value 2']), result) self.assertEqual(self.calculator.result, result)
def test_division_method_calculator(self): test_data = CsvReader('/src/Unit Test Division.csv').data print('Division Test') pprint(test_data) for row in test_data: self.assertEqual( self.calculator.divide(row['Value 1'], row['Value 2']), float(row['Result'])) self.assertEqual(self.calculator.result, float(row['Result']))
def test_addition(self): test_data = CsvReader('/src/addition.csv').data for row in test_data: self.assertEqual(self.calculator.add(row['Value 1'], row['Value 2']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result'])) print(row['Value 1'] + ' + ' + row['Value 2'] + ' = ' + row['Result'] + ', Expect: ', self.calculator.result) # Clear Csv Reader for next unit test CsvReader.data.clear()
def test_multiplication(self): test_data_multiplication = CsvReader( '/src/Unit_Test_Multiplication.csv').data for row in test_data_multiplication: result = float(row['Result']) self.assertEqual( self.calculator.multiply(row['Value 1'], row['Value 2']), result) self.assertEqual(self.calculator.result, result)
class FileReader: def __init__(self, file_info): reader_type = file_info['readerType'] if reader_type == 'csv': self.reader = CsvReader(file_info) def read_file(self, file_path): return self.reader.read_file(file_path)
def test_subtraction(self): test_data_subtraction = CsvReader( '/src/Unit_Test_Subtraction.csv').data pprint(test_data_subtraction) for row in test_data_subtraction: result = float(row['Result']) self.assertEqual( self.calculator.subtract(row['Value 1'], row['Value 2']), result) self.assertEqual(self.calculator.result, result)
class MyTestCase(unittest.TestCase): def setUp(self) -> None: self.csv_reader = CsvReader('Source/Addition.csv') def test_return_data(self): values = self.csv_reader.return_data('Value') self.assertIsInstance(values, list) test_class = ClassFactory('Value', self.csv_reader.data[0]) for value in values: self.assertEqual(value.__name__, test_class.__name__)
def test_square(self): test_data = CsvReader('/src/square.csv').data print('') print('******TEST_SQUARE******') for row in test_data: self.assertEqual(self.calculator.squ(int(row['Value 1'])),int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result'])) print( 'Square of:', row['Value 1'] + ' = ' + row['Result'] + ', Expect: ', self.calculator.result) # Clear Csv Reader for next unit test CsvReader.data.clear()
class MyTestCase(unittest.TestCase): def setUp(self) -> None: self.csv_reader = CsvReader('UnitTestAddition.csv') def test_return_data_as_objects(self): people = self.csv_reader.return_data_as_objects('person') self.assertIsInstance(people, list) test_class = ClassFactory('person', self.csv_reader.data[0]) for person in people: self.assertEqual(person.__name__, test_class.__name__)
def test_division(self): test_data= CsvReader('/src/division.csv').data print('') print('******TEST_DIVISION******') for row in test_data: self.assertEqual(self.calculator.divide(float(row['Value 1']),float(row['Value 2'])), float(row['Result'])) self.assertEqual(float(self.calculator.result), float(row['Result'])) print(row['Value 2'] + ' / ' + row['Value 1'] + ' = ' + row['Result'] + ', Expect: ', float(round(self.calculator.result,9))) # Clear Csv Reader for next unit test CsvReader.data.clear()
def test_square(self): self.assertEqual(self.calculator.square(3)) self.assertEqual(self.calculator.result, 9) test_data = CsvReader("src/Test/Square.csv").data for row in test_data: result = float(row['Result']) self.assertEqual( self.calculator.square(row['Value 1'], row['Value 2']), result) self.assertEqual(self.calculator.result, result)
def test_square(self): print('') print('******test_square******') CsvReader.test_data_row_list = [] test_data_file_path = CsvReader('./src/Square.csv').test_data_row_list print(test_data_file_path) print('Sqauer loaded') for row in test_data_file_path: self.assertEqual(self.calculator.square(float(row[0])), float(row[1]))
def test_minus(self): print('') print('******test_minus******') test_data_file_path = CsvReader( './src/Subtraction.csv').test_data_row_list print('Subtraction loaded') print(test_data_file_path) for row in test_data_file_path: self.assertEqual(self.calculator.minus(int(row[0]), int(row[1])), int(row[2]))
def test_rooting_method_calculator(self): test_data = CsvReader('/src/Unit Test Square Root.csv').data print('Square Root Test') pprint(test_data) for row in test_data: #if self.calculator.result == float(row['Result']): self.assertEqual(self.calculator.rooting(row['Value 1']), float(row['Result'])) self.assertEqual(self.calculator.result, float(row['Result']))
def test_division(self): self.assertEqual(self.calculator.divide(6, 2), 3) self.assertEqual(self.calculator.result, 3) test_data = CsvReader("src/Test/Division.csv").data for row in test_data: result = float(row['Result']) self.assertEqual( self.calculator.divide(row['Value 1'], row['Value 2']), result) self.assertEqual(self.calculator.result, result)
def test_addition(self): self.assertEqual(self.calculator.add(1, 1), 2) self.assertEqual(self.calculator.result, 2) test_data = CsvReader("src/Test/Addition.csv").data for row in test_data: result = int(row['Result']) self.assertEqual( self.calculator.add(row['Value 1'], row['Value 2']), result) self.assertEqual(self.calculator.result, result)
def test_multiply_method_calculator(self): self.test_data = CsvReader('/src/Multiplication.csv').data for row in self.test_data: self.assertAlmostEqual( self.calculator.multiply(int(row['Value 1']), int(row['Value 2'])), int(float(row['Result']))) self.assertAlmostEquals(self.calculator.result(7), int(float(row['Result', 7]))) print(self.calculator.result)
def test_divide_method_calculator(self): self.test_data = CsvReader('/src/Division.csv').data for row in self.test_data: self.assertNotEqual( self.calculator.divide(int(row['Value 1']), int(row['Value 2'])), int(float(row['Result']))) self.assertNotEqual(self.calculator.result, int(float(row['Result']))), print(self.calculator.result)
def test_subtract_method_calculator(self): self.test_data = CsvReader('/src/Subtraction.csv').data for row in self.test_data: self.assertNotEqual( self.calculator.subtract(int(row['Value 1']), int(row['Value 2'])), int(float(row['Result']))) self.assertNotEqual(self.calculator.result, int(float(row['Result']))) print(self.calculator.result)
def test_plus(self): print('') print('******test_plus******') CsvReader.test_data_row_list = [] test_data_file_path = CsvReader( './src/Addition.csv').test_data_row_list print('Addition loaded') print(test_data_file_path) for row in test_data_file_path: self.assertEqual(self.calculator.plus(int(row[0]), int(row[1])), int(row[2]))
def test_multiplication(self): self.assertEqual(self.calculator.multiply(2, 3), 6) self.assertEqual(self.calculator.result, 6) test_data = CsvReader("src/Test/Multiplication.csv").data for row in test_data: result = float(row['Result']) self.assertEqual( self.calculator.multiply(row['Value 1'], row['Value 2']), result) self.assertEqual(self.calculator.result, result)
def test_multiplication(self): test_data = CsvReader('/src/multiplication.csv').data print('') print('******TEST_MULTIPLICATION******') for row in test_data: self.assertEqual(self.calculator.multiply(row['Value 1'], row['Value 2']), int(row['Result'])) self.assertEqual(self.calculator.result, int(row['Result'])) print(row['Value 2'] + ' * ' + row['Value 1'] + ' = ' + row['Result'] + ', Expect: ', self.calculator.result) # Clear Csv Reader for next unit test CsvReader.data.clear()
def testNewClass(self): csr = CsvReader('AutoCtrl_Area01_01.csv') csr.print()