def test_line_chart_age_and_salary_gets_correct_data(self): # Arrange result = False file_name = 'testdata\\test_output.txt' chart_type = "line" expected_age_list = [ '21', '45', '21', '21', '45', '45', '21', '21', '21', '45', '46', '46', '46', '20', '20' ] expected_salary_list = [ '12', '725', '12', '12', '725', '725', '12', '12', '12', '75', '725', '725', '725', '12', '12' ] expected_title = 'Salary Vs Age' expected_y_label = "Salary" expected_x_label = "Age of Staff" expected_grid = True file_contents = [] with open(file_name, "r") as file: for line in file: a_line = line.rstrip() file_contents.append(a_line) file.close() calc_data = CalcData() calc_data.calculate(file_contents, chart_type) # Act calc_data.line_chart() # Assert actual_age_list = ChartLine.get_data(ChartLine)[0] actual_salary_list = ChartLine.get_data(ChartLine)[1] actual_title = ChartLine.get_title(ChartLine) actual_y_label = ChartLine.get_y_label(ChartLine) actual_x_label = ChartLine.get_x_label(ChartLine) actual_grid = ChartLine.get_grid(ChartLine) if actual_age_list == expected_age_list: if actual_salary_list == expected_salary_list: if actual_title == expected_title: if actual_x_label == expected_x_label: if actual_y_label == expected_y_label: if actual_grid == expected_grid: result = True self.assertTrue(result)
def test_line_chart_empty(self): test_name = "Calc Chart Data Line CHart Test #01" data_to_test = None class_to_test = CalcData() expected_result = None # Action result = class_to_test.line_chart() # Assert try: self.assertTrue(result == expected_result) except AssertionError: print("{} Failed - Should be {}, but was {}.".format( test_name, expected_result, result)) else: print("{} Passed".format(test_name))
def test_line_chart_values(self): test_name = "Calc Chart Data Line Chart Test #02" data_to_test = None class_to_test = CalcData() expected_result = None class_to_test.calc_line('age', 50) class_to_test.calc_line('salary', 500) # Action result = class_to_test.line_chart() # Assert try: self.assertTrue(result == expected_result) except AssertionError: print("{} Failed - Should be {}, but was {}.".format( test_name, expected_result, result)) else: print("{} Passed".format(test_name))