Beispiel #1
0
    def test_should_compare_work_properly_case_1(self):
        """Case 1: a comparator returning 0."""
        solution1 = Solution(2, 2)
        solution2 = Solution(2, 2)

        mocked_comparator: Comparator = mock()
        when(mocked_comparator).compare(solution1, solution2).thenReturn(0)

        comparator_list = [mocked_comparator]

        multi_comparator = MultiComparator(comparator_list)
        self.assertEqual(0, multi_comparator.compare(solution1, solution2))

        verify(mocked_comparator, times=1).compare(solution1, solution2)
Beispiel #2
0
    def test_should_compare_work_properly_case_3(self):
        """Case 2: two comparators; the first returns 0 and the second one returns -1.
        Expected result: -1
        """
        solution1 = Solution(2, 2)
        solution2 = Solution(2, 2)

        mocked_comparator1: Comparator = mock()
        when(mocked_comparator1).compare(solution1, solution2).thenReturn(0)
        mocked_comparator2: Comparator = mock()
        when(mocked_comparator2).compare(solution1, solution2).thenReturn(-1)

        comparator_list = [mocked_comparator1, mocked_comparator2]

        multi_comparator = MultiComparator(comparator_list)
        self.assertEqual(-1, multi_comparator.compare(solution1, solution2))

        verify(mocked_comparator1, times=1).compare(solution1, solution2)
        verify(mocked_comparator2, times=1).compare(solution1, solution2)
Beispiel #3
0
    def test_should_compare_return_zero_if_the_comparator_list_is_empty(self):
        solution1 = Solution(2, 2)
        solution2 = Solution(2, 2)

        multi_comparator = MultiComparator([])
        self.assertEqual(0, multi_comparator.compare(solution1, solution2))