Exemplo n.º 1
0
class TestTicketRange(TestCase):
    @parameterized.expand(from_file(directory=TEST_DATA_DIR, file='ticket_range.json')['invalid_ticket_range'])
    def test_raises_error_if_max_number_greater_than_min(self, min_number, max_number):
        with self.assertRaises(InvalidTicketRangeError):
            TicketRange(Ticket(min_number), Ticket(max_number))

    @parameterized.expand(from_file(directory=TEST_DATA_DIR, file='ticket_range.json')['simple_method_data'])
    def test_when_simple_method_is_winner(self, min_number, max_number, times):
        result = str(TicketRange(Ticket(min_number), Ticket(max_number)))
        self.assertIn('Simple method has won', result)
        self.assertIn(f'Simple method ran {times} times', result)

    @parameterized.expand(from_file(directory=TEST_DATA_DIR, file='ticket_range.json')['complex_method_data'])
    def test_when_complex_method_is_winner_and_two_tickets_equal(self, min_number, max_number, times):
        result = str(TicketRange(Ticket(min_number), Ticket(max_number)))
        self.assertIn('Complex method has won', result)
        self.assertIn(f'complex method ran {times} times', result)

    @parameterized.expand(from_file(directory=TEST_DATA_DIR, file='ticket_range.json')['complex_alternative_data'])
    def test_when_complex_alternative_method_is_winner(self, min_number, max_number, times):
        result = str(TicketRange(min_number, max_number))
        self.assertIn('Alternative complex method has won', result)
        self.assertIn(f'alternative complex method ran {times} times', result)

    @parameterized.expand(from_file(directory=TEST_DATA_DIR, file='ticket_range.json')['draw_data'])
    def test_when_it_is_a_draw(self, min_number, max_number):
        self.assertIn('It is a draw', str(TicketRange(Ticket(min_number), Ticket(max_number))))
Exemplo n.º 2
0
class TestIsSimpleLucky(TestCase):
    @parameterized.expand(from_file(directory=TEST_DATA_DIR, file='ticket_methods.json')['is_simple_valid'])
    def test_valid_values(self, ticket):
        self.assertTrue(Ticket(ticket).is_simple_lucky)

    @parameterized.expand(from_file(directory=TEST_DATA_DIR, file='ticket_methods.json')['is_simple_invalid'])
    def test_invalid_values(self, ticket):
        self.assertFalse(Ticket(ticket).is_simple_lucky)
Exemplo n.º 3
0
class TestIsComplexLuckyAlternative(TestCase):
    @parameterized.expand(from_file(directory=TEST_DATA_DIR, file='ticket_methods.json')['is_complex_alternative_valid'])
    def test_valid_values(self, ticket):
        self.assertTrue(Ticket(ticket).is_complex_lucky_alternative)

    @parameterized.expand(from_file(directory=TEST_DATA_DIR, file='ticket_methods.json')['is_complex_alternative_invalid'])
    def test_invalid_values(self, ticket):
        self.assertFalse(Ticket(ticket).is_complex_lucky_alternative)
Exemplo n.º 4
0
class TestSide(TestCase):
    @parameterized.expand(
        from_file(directory=TEST_DATA_DIR, file='side.json')['invalid_side'])
    def test_raises_error_if_side_is_invalid(self, side):
        with self.assertRaises(InvalidSideError):
            Side(side)

    @parameterized.expand(
        from_file(directory=TEST_DATA_DIR, file='side.json')['valid_side'])
    def test_returns_side_if_valid(self, side):
        actual = Side(side)._value
        self.assertEqual(actual, side)
Exemplo n.º 5
0
class TestValidateTicketRange(TestCase):
    @parameterized.expand(
        from_file(directory=TEST_DATA_DIR,
                  file='ticket_range.json')['valid_ticket_range'])
    def test_min_number_less_than_max(self, min_ticket, max_ticket):
        self.assertIsNone(validate_ticket_range(min_ticket, max_ticket))

    @parameterized.expand(
        from_file(directory=TEST_DATA_DIR,
                  file='ticket_range.json')['invalid_ticket_range'])
    def test_max_number_greater_than_min(self, min_number, max_number):
        with self.assertRaises(InvalidTicketRangeError):
            validate_ticket_range(min_number, max_number)
Exemplo n.º 6
0
class TestValidateTicket(TestCase):
    @parameterized.expand(
        from_file(directory=TEST_DATA_DIR,
                  file='tickets.json')['invalid_tickets'])
    def test_raises_error_if_not_valid_ticket(self, ticket):
        with self.assertRaises(InvalidTicketError):
            validate_ticket(ticket)

    @parameterized.expand(
        from_file(directory=TEST_DATA_DIR,
                  file='tickets.json')['valid_tickets'])
    def test_returns_ticket_if_valid(self, ticket):
        self.assertEqual(validate_ticket(ticket), ticket)
Exemplo n.º 7
0
class TestGetValidTickets(TestCase):
    @parameterized.expand(
        from_file(directory=TEST_DATA_DIR,
                  file='tickets.json')['valid_ticket_range'])
    def test_returns_tickets(self, _, min_number, max_number, expected):
        self.assertEqual(list(get_valid_tickets(min_number, max_number)),
                         expected)

    @parameterized.expand(
        from_file(directory=TEST_DATA_DIR,
                  file='tickets.json')['for_generator'])
    def test_result_is_generator(self, min_number, max_number):
        self.assertTrue(
            isinstance(get_valid_tickets(min_number, max_number), Generator))
Exemplo n.º 8
0
class TestTicketInitializer(TestCase):
    @parameterized.expand(from_file(directory=TEST_DATA_DIR, file='tickets.json')['invalid_tickets'])
    def test_raises_error_if_ticket_is_invalid(self, ticket):
        with self.assertRaises(InvalidTicketError):
            Ticket(ticket)

    @parameterized.expand(from_file(directory=TEST_DATA_DIR, file='tickets.json')['valid_tickets'])
    def test_returns_ticket_if_valid(self, ticket):
        actual = Ticket(ticket)._number
        self.assertEqual(actual, ticket)

    @parameterized.expand(from_file(directory=TEST_DATA_DIR, file='tickets.json')['tickets_with_prepended_zeros'])
    def test_returns_ticket_with_prepended_zeros(self, int_ticket_number, result):
        actual = Ticket(int_ticket_number)._number
        self.assertEqual(actual, result)
Exemplo n.º 9
0
class TestChessboard(TestCase):
    @parameterized.expand(
        from_file(directory=TEST_DATA_DIR,
                  file='chessboard.json')['chessboard'])
    def test_building_board(self, height, width, expected_board):
        actual = str(Chessboard(Side(height), Side(width)))
        self.assertEqual(actual, expected_board)
Exemplo n.º 10
0
class TestCompareLuckyTicketCountingFunctions(TestCase):
    @parameterized.expand(
        from_file(directory=TEST_DATA_DIR,
                  file='ticket_range.json')['simple_method_data'])
    def test_when_simple_method_is_winner(self, min_number, max_number, times):
        result = compete_lucky_ticket_counting_functions(
            min_number, max_number)
        self.assertIn('Simple method has won', result)
        self.assertIn(f'Simple method ran {times} times', result)

    @parameterized.expand(
        from_file(directory=TEST_DATA_DIR,
                  file='ticket_range.json')['complex_method_data'])
    def test_when_complex_method_is_winner(self, min_number, max_number,
                                           times):
        result = compete_lucky_ticket_counting_functions(
            min_number, max_number)
        self.assertIn('Complex method has won', result)
        self.assertIn(f'complex method ran {times} times', result)

    @parameterized.expand(
        from_file(directory=TEST_DATA_DIR,
                  file='ticket_range.json')['complex_alternative_data'])
    def test_when_complex_alternative_method_is_winner(self, min_number,
                                                       max_number, times):
        result = compete_lucky_ticket_counting_functions(
            min_number, max_number)
        self.assertIn('Alternative complex method has won', result)
        self.assertIn(f'alternative complex method ran {times} times', result)

    @parameterized.expand(
        from_file(directory=TEST_DATA_DIR,
                  file='ticket_range.json')['draw_data'])
    def test_when_it_is_a_draw(self, min_number, max_number):
        self.assertIn(
            'It is a draw',
            compete_lucky_ticket_counting_functions(min_number, max_number))