Exemplo n.º 1
0
    def test_calculate_total__if_string_values__exception_thrown(self):
        """
        Scenario:
        1. Create object of Sortings class
        2. Initialize list with string
        3. Call calculate_total()

        Expected result: Exception thrown
        """
        sortings = Sortings()
        sortings.list = ["Test"]

        with self.assertRaises(Exception) as actual:
            sortings.calculate_total()

        self.assertEqual("An input list should contain only numeric values", actual.exception.message)
Exemplo n.º 2
0
    def test_calculate_total__if_non_list_value__exception_thrown(self):
        """
        Scenario:
        1. Create object of Sortings class
        2. Initialize list with int value
        3. Call calculate_total()

        Expected result: Exception thrown
        """
        sortings = Sortings()
        sortings.list = -20303

        with self.assertRaises(Exception) as actual:
            sortings.calculate_total()

        self.assertEqual("Can not calculate total for object of type not 'list'", actual.exception.message)
Exemplo n.º 3
0
    def test_calculate_total__if_empty_list__exception_thrown(self):
        """
        Scenario:
        1. Create object of Sortings class
        2. Initialize list by empty list
        3. Call calculate_total()

        Expected result: Exception thrown
        """
        sortings = Sortings()
        sortings.list = []

        with self.assertRaises(Exception) as actual:
            sortings.calculate_total()

        self.assertEqual("Can not calculate total of an empty list", actual.exception.message)
Exemplo n.º 4
0
    def test_calculate_total__if_one_negative_value__returns_this_value(self):
        """
        Scenario:
        1. Create object of Sortings class
        2. Initialize list with one negative value
        3. Call calculate_total()

        Expected result: This value returned
        """
        sortings = Sortings()
        sortings.list = [-33012]
        actual_result = sortings.calculate_total()
        self.assertEqual(-33012, actual_result)
Exemplo n.º 5
0
    def test__calculate_total__if_float_values__returns_total(self):
        """
        Scenario:
        1. Create object of Sortings class
        2. Initialize list with float values and float resulting expressions
        3. Call calculate_total()

        Expected result: Correct total returned
        """
        sortings = Sortings()
        sortings.list = [0.333, 0, 1 / 3, 1.0 / 3.0]

        actual_result = sortings.calculate_total()

        self.assertEqual(0.6663333333333333, actual_result)
Exemplo n.º 6
0
    def test_calculate_total__if_negative_values__returns_total(self):
        """
        Scenario:
        1. Create object of Sortings class
        2. Initialize list with mix of negative and positive values
        3. Call calculate_total()

        Expected result: Correct total returned
        """
        sortings = Sortings()
        sortings.list = [100, -2, -10, -3, 2]

        actual_result = sortings.calculate_total()

        self.assertEqual(87, actual_result)
Exemplo n.º 7
0
    def test_calculate_total__total_is_calculated(self):
        """
        Scenario:
        1. Create object of Sortings class
        2. Initialize list with int values
        3. Call calculate_total()

        Expected result: Total of int values returned
        """
        sortings = Sortings()
        sortings.list = [20202, 1, 2, 3]

        actual_result = sortings.calculate_total()

        self.assertEqual(20208, actual_result)