Beispiel #1
0
 def test_calc_bar_birth_false(self):
     test_name = "Calc Chart Data Test #31"
     data_to_test = '10/13/97'
     class_to_test = CalcData()
     expected_result = None
     # Action
     result = class_to_test.calc_bar_birthday(data_to_test)
     # 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))
Beispiel #2
0
 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))
Beispiel #3
0
 def test_calc_pie_sales_value_error(self):
     test_name = "Calc Chart Data Test #32"
     data_to_test = 'testing'
     class_to_test = CalcData()
     expected_result = None
     # Action
     result = class_to_test.calc_pie_sales(data_to_test)
     # 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))
Beispiel #4
0
 def test_calc_is_valid_type_error(self):
     test_name = "Calc Chart Data Test #33"
     data_to_test = 1234
     class_to_test = CalcData()
     expected_result = False
     # Action
     result = class_to_test.is_valid(data_to_test)
     # 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))
Beispiel #5
0
 def test_calc_line_false(self):
     test_name = "Calc Chart Data Test #5"
     data_to_test = "salad"
     class_to_test = CalcData()
     expected_result = None
     # Action
     result = class_to_test.calc_line(data_to_test, 500)
     # 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))
Beispiel #6
0
 def test_calc_bar_bmi_false(self):
     test_name = "Calc Chart Data Test #18"
     data_to_test = 'Overweight and Underweight'
     class_to_test = CalcData()
     expected_result = None
     # Action
     result = class_to_test.calc_bar_bmi(data_to_test)
     # 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))
Beispiel #7
0
 def test_file_contents_are_valid(self):
     test_name = "Calc Chart Data Test #1"
     data_to_test = "A001,gender M,age 52,sales 123,bmi Overweight,"\
                    "salary 50,birthday 23/10/1998,valid 1,"
     class_to_test = CalcData()
     expected_result = True
     # Action
     result = class_to_test.is_valid(data_to_test)
     # 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))
Beispiel #8
0
 def test_calc_pie_gender_m(self):
     test_name = "Calc Chart Data Test #6"
     data_to_test = "M"
     class_to_test = CalcData()
     expected_result = 1
     # Action
     class_to_test.calc_pie_gender(data_to_test)
     result = class_to_test.count_gender_m
     # 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))
Beispiel #9
0
 def test_file_contents_are_not_valid(self):
     test_name = "Calc Chart Data Test #2"
     data_to_test = "a001,M,52,123,Overweight,50,23-10-1998 Z005,F,"\
                    "18,624,Normal,85,25-04-1158 C078,F,35"
     class_to_test = CalcData()
     expected_result = False
     # Action
     result = class_to_test.is_valid(data_to_test)
     # 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))
Beispiel #10
0
 def test_calc_line_age(self):
     test_name = "Calc Chart Data Test #3"
     data_to_test = "age"
     class_to_test = CalcData()
     expected_result = [50]
     # Action
     class_to_test.calc_line(data_to_test, 50)
     result = class_to_test.age_list
     # 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))
Beispiel #11
0
 def test_calc_bar_bmi_no(self):
     test_name = "Calc Chart Data Test #17"
     data_to_test = 'Normal'
     class_to_test = CalcData()
     expected_result = 1
     # Action
     class_to_test.calc_bar_bmi(data_to_test)
     result = class_to_test.count_bmi_no
     # 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))
Beispiel #12
0
 def test_calculate_bmi(self):
     test_name = "Calc Chart Data Test #39"
     data_to_test = ['', 'A001,gender F,age 21,sales 001,bmi Normal,salary 12,birthday 01/01/1996,valid 1,',\
     'Q001,gender M,age 45,sales 999,bmi Underweight,salary 725,birthday 31/12/1971,valid 1,',\
      'A002,gender F,age 21,sales 001,bmi Normal,salary 12,birthday 01/01/1996,valid 1,']
     class_to_test = CalcData()
     expected_result = None
     # Action
     result = class_to_test.calculate(data_to_test, 'bmi')
     # 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))
Beispiel #13
0
 def test_pie_chart_gender(self):
     test_name = "Calc Chart Data Pie Chart Gender Test #06"
     data_to_test = None
     class_to_test = CalcData()
     expected_result = None
     class_to_test.calc_pie_gender("M")
     class_to_test.calc_pie_gender("F")
     # Action
     result = class_to_test.pie_chart("gender")
     # 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))
Beispiel #14
0
 def test_pie_chart_false(self):
     test_name = "Calc Chart Data Pie Chart FALSE Test #08"
     data_to_test = "testing"
     class_to_test = CalcData()
     expected_result = None
     class_to_test.calc_pie_sales(150)
     class_to_test.calc_pie_sales(250)
     # Action
     result = class_to_test.pie_chart(data_to_test)
     # 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))
Beispiel #15
0
 def test_bar_chart_birthday(self):
     test_name = "Calc Chart Data Bar Chart Birthday Test #03"
     data_to_test = None
     class_to_test = CalcData()
     expected_result = None
     class_to_test.calc_bar_birthday("12/12/12")
     class_to_test.calc_bar_birthday("12/10/12")
     # Action
     result = class_to_test.bar_chart("birthday")
     # 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))
Beispiel #16
0
    def get_data(self, choice):
        # choose file to get data from
        file_name = input("Please enter the filename to read data from >>> ")
        # check file exists
        try:
            file_contents = self._load_file_data(file_name)
            # create instance of CalcData to calc data for particular chart
            i = CalcData()

            if file_contents:  # if contents isn't empty
                if i.is_valid(file_contents):  # as long as contents are valid
                    i.calculate(file_contents,
                                choice)  # calculate the chart data
                    return i  # return i so chart can be called
                else:
                    print(Err.get_error_message(210))
        except FileNotFoundError:
            print(Err.ErrorHandler.get_error_message(201))
    def test_gender_pie_chart_with_bad_data_does_not_match_reference_chart(
            self):
        # Arrange
        file_name = 'testdata\\test_output_all_male_all_500_sales.txt'
        chart_type = "sales"
        expected_image_file = 'reference_charts\\pie_chart_sales.png'
        actual_image_file = 'created_charts\\pie_chart.png'

        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.pie_chart(chart_type)

        # Assert
        if filecmp.cmp(expected_image_file, actual_image_file, shallow=False):
            chart_images_match = True
        else:
            chart_images_match = False

        self.assertFalse(chart_images_match)
    def test_bmi_bar_chart_with_correct_data_matches_reference_chart(self):
        # Arrange
        file_name = 'testdata\\test_output.txt'
        chart_type = "bmi"
        expected_image_file = 'reference_charts\\bar_chart_bmi.png'
        actual_image_file = 'created_charts\\bar_chart.png'

        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.bar_chart(chart_type)

        # Assert
        if filecmp.cmp(expected_image_file, actual_image_file, shallow=False):
            chart_images_match = True
        else:
            chart_images_match = False

        self.assertTrue(chart_images_match)
Beispiel #19
0
 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))
Beispiel #20
0
 def test_bar_chart_false(self):
     test_name = "Calc Chart Data Bar Chart FALSE Test #05"
     data_to_test = "testing"
     class_to_test = CalcData()
     expected_result = None
     class_to_test.calc_bar_bmi("Overweight")
     class_to_test.calc_bar_bmi("Underweight")
     # Action
     result = class_to_test.bar_chart(data_to_test)
     # 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_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)