Пример #1
0
    def test_sort_asc_bubble__if_non_list_value__exception_thrown(self):
        """
        Scenario:
        1. Create object of Sortings class
        2. Initialize list with int value
        3. Call sort_asc_bubble()

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

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

        self.assertEqual("Can not perform sort asc for object of type not 'list'", actual.exception.message)
Пример #2
0
    def test_sort_asc_bubble__if_list_of_lists_values__exception_thrown(self):
        """
        Scenario:
        1. Create object of Sortings class
        2. Initialize list with list of lists
        3. Call sort_asc_bubble()

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

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

        self.assertEqual("An input list should contain only numeric values", actual.exception.message)
Пример #3
0
    def test_sort_asc_bubble__if_empty_list__exception_thrown(self):
        """
        Scenario:
        1. Create object of Sortings class
        2. Initialize list by empty list
        3. Call sort_asc_bubble()

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

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

        self.assertEqual("Can not perform sort asc of an empty list", actual.exception.message)
Пример #4
0
    def test_sort_asc_bubble__load_test(self):
        """
        Expected result: Timing is not exceeding following numbers
        # 0 2.14576721191e-06
        # 1000 0.306516885757
        # 2000 1.18236112595
        # 3000 2.68166708946
        # 4000 4.75515794754
        # 5000 7.46735286713
        # 6000 10.7233338356
        # 7000 14.4423561096
        # 8000 18.9818980694
        # 9000 23.9862349033
        """
        i = 1
        while i < 10000:
            sortings = Sortings(i)

            start = time.time()
            sortings.sort_asc_bubble()
            end = time.time()
            print i, end - start

            i += 1000
Пример #5
0
    def test_sort_asc_bubble__if_equal_values__returns_this_list(self):
        """
        Scenario:
        1. Create object of Sortings class
        2. Initialize list with equal values
        3. Call sort_asc_v()

        Expected result: Same list returned
        """
        sortings = Sortings()
        sortings.list = [2, 2, 2, 2, 2, 2]

        actual_result = sortings.sort_asc_bubble()

        self.assertEqual([2, 2, 2, 2, 2, 2], actual_result)
Пример #6
0
    def test_sort_asc_bubble__if_mixed_int_values__returns_list_sorted_asc(self):
        """
        Scenario:
        1. Create object of Sortings class
        2. Initialize list with mix of negative and non-negative int values
        3. Call sort_asc_bubble()

        Expected result: This list sorted asc returned
        """
        sortings = Sortings()
        sortings.list = [-1, -600, 564, -3224, 333, -208, 34, 1, 0]

        actual_result = sortings.sort_asc_bubble()

        self.assertEqual([-3224, -600, -208, -1, 0, 1, 34, 333, 564], actual_result)
Пример #7
0
    def test_sort_asc_bubble__if_negative_values__returns_list_sorted_asc(self):
        """
        Scenario:
        1. Create object of Sortings class
        2. Initialize list with negative int values
        3. Call sort_asc_bubble()

        Expected result: This list sorted asc returned
        """
        sortings = Sortings()
        sortings.list = [-5098, -6000, -564, -324, -13, -28, -45, -1]

        actual_result = sortings.sort_asc_bubble()

        self.assertEqual([-6000, -5098, -564, -324, -45, -28, -13, -1], actual_result)
Пример #8
0
    def test_sort_asc_bubble__if_non_negative_values__returns_list_sorted_asc(self):
        """
        Scenario:
        1. Create object of Sortings class
        2. Initialize list with non_negative int values
        3. Call sort_asc_bubble()

        Expected result: This list sorted asc returned
        """
        sortings = Sortings()
        sortings.list = [5098, 6000, 564, 324, 0, 13, 28, 45, 1]

        actual_result = sortings.sort_asc_bubble()

        self.assertEqual([0, 1, 13, 28, 45, 324, 564, 5098, 6000], actual_result)
Пример #9
0
    def test_sort_asc_bubble__if_mixed_types_values__returns_list_sorted_asc(self):
        """
        Scenario:
        1. Create object of Sortings class
        2. Initialize list with mix of negative and non-negative int, float, long values
        3. Call sort_asc_bubble()

        Expected result: This list sorted asc returned
        """
        sortings = Sortings()
        sortings.list = [-1.0, -600.66, 564, 32.24, 32.3, -208, 10002020202020202049485763542514145637473484389, 1, 0]

        actual_result = sortings.sort_asc_bubble()

        self.assertEqual(
            [-600.66, -208, -1.0, 0, 1, 32.24, 32.3, 564, 10002020202020202049485763542514145637473484389L],
            actual_result,
        )