def test_check_move_with_condition_2_and_valid_items_in_destination(self):
        game = GameState(4)
        game.columns[0].cards.items = [Card(1), Card(2)]
        game.columns[1].cards.items = [Card(4), Card(3)]
        move = Move(0, 1)

        self.assertTrue(MoveHelper.check_move(game, move))
    def test_draw_column_with_one_card_and_valid_coordinate(self):
        screen = Screen(10, 10)
        column = Column()
        column.cards.items = [Card(5)]
        ScreenHelper.draw_column(screen, 0, 0, column)

        expected_screen = Screen(10, 10)
        ScreenHelper.draw_card(expected_screen, 0, 0, Card(5))

        self.assertListEqual(expected_screen.get_matrix(), screen.get_matrix())
Esempio n. 3
0
    def test_get_representation_with_single_digit_and_number_shown(self):
        test_card = Card(2)
        actual_representation = test_card.get_representation()
        expected_representation = ""
        expected_representation += " ____\n"
        expected_representation += "|   2|\n"
        expected_representation += "|    |\n"
        expected_representation += "|    |\n"
        expected_representation += "|____|"

        self.assertEqual(expected_representation, actual_representation)
Esempio n. 4
0
    def test_get_representation_with_double_digit_and_number_not_shown(self):
        test_card = Card(10)
        actual_representation = test_card.get_representation(show_number=False)
        expected_representation = ""
        expected_representation += " ____\n"
        expected_representation += "|   *|\n"
        expected_representation += "|    |\n"
        expected_representation += "|    |\n"
        expected_representation += "|____|"

        self.assertEqual(expected_representation, actual_representation)
    def test_draw_game_with_one_column(self):
        screen = Screen(10, 10)
        game = GameState(2)
        game.columns[0].cards.items = [Card(5), Card(4)]
        ScreenHelper.draw_game(screen, game)

        expected_screen = Screen(10, 10)
        column = Column()
        column.cards.items = [Card(5), Card(4)]
        ScreenHelper.draw_column(expected_screen, 0, 0, column)

        self.assertListEqual(expected_screen.get_matrix(), screen.get_matrix())
    def test_draw_card_with_invalid_coordinates(self):
        """
        A test that trying to draw a card on an invalid screen won't change the state of the screen
        """
        screen = Screen(4, 4)
        card = Card(3)

        self.assertRaises(IndexError, ScreenHelper.draw_card, screen, 0, 0, card)

        self.assertListEqual(Screen(4, 4).get_matrix(), screen.get_matrix())
    def test_draw_card_with_valid_coordinates_and_no_number(self):
        screen = Screen(6, 5)
        card = Card(2)

        ScreenHelper.draw_card(screen, 0, 0, card, show_number=False)

        expected_matrix = [list(" ____ "),
                           list("|   *|"),
                           list("|    |"),
                           list("|    |"),
                           list("|____|")]

        self.assertListEqual(expected_matrix, screen.get_matrix())
    def test_draw_card_with_valid_coordinates(self):
        screen = Screen(6, 5)
        card = Card(2)

        ScreenHelper.draw_card(screen, 0, 0, card)

        expected_matrix = [list(" ____ "),
                           list("|   2|"),
                           list("|    |"),
                           list("|    |"),
                           list("|____|")]

        self.assertListEqual(expected_matrix, screen.get_matrix())
    def test_draw_game_with_multiple_columns(self):
        screen = Screen(30, 30)
        game = GameState(4)
        game.columns[0].cards.items = [Card(5), Card(4)]
        game.columns[1].cards.items = [Card(3), Card(2)]
        ScreenHelper.draw_game(screen, game)

        expected_screen = Screen(30, 30)
        column1 = Column()
        column2 = Column()
        column1.cards.items = [Card(5), Card(4)]
        column2.cards.items = [Card(3), Card(2)]
        ScreenHelper.draw_column(expected_screen, 0, 0, column1)
        ScreenHelper.draw_column(expected_screen, 10, 0, column2)

        self.assertListEqual(expected_screen.get_matrix(), screen.get_matrix())
    def test_check_move_with_condition_3_and_valid_items_in_destination(self):
        game = GameState(
            14)  # large so that we generate the correct number of columns
        game.columns[1].cards.items = [Card(2), Card(1)]
        game.columns[2].cards.items = [Card(4), Card(3)]
        game.columns[3].cards.items = [Card(2), Card(1)]

        self.assertTrue(MoveHelper.check_move(game, Move(1, 2)))
        self.assertTrue(MoveHelper.check_move(game, Move(3, 2)))
    def test_card_will_fit_on_screen_with_invalid_y_coordinates(self):
        screen = Screen(5, 5)
        card = Card(3)

        self.assertFalse(ScreenHelper.card_will_fit_on_screen(screen, 0, 1, card))
    def test_card_will_fit_on_screen_with_valid_coordinates(self):
        screen = Screen(6, 5)
        card = Card(3)

        self.assertTrue(ScreenHelper.card_will_fit_on_screen(screen, 0, 0, card))
    def test_check_move_with_condition_1_and_items_in_deque(self):
        game = GameState(2)
        game.columns[0].cards.items = [Card(1), Card(2)]
        move = Move(0, 0)

        self.assertTrue(MoveHelper.check_move(game, move))
    def test_check_move_with_condition_3_and_no_items_in_destination(self):
        game = GameState(2)
        game.columns[1].cards.items = [Card(1), Card(2)]
        move = Move(1, 2)

        self.assertTrue(MoveHelper.check_move(game, move))