Esempio n. 1
0
def test_get_filled_indices_should_be_seven():
    b = Board(10, 22)
    filled_indices = [0, 1, 2, 3, 4, 5, 6]
    for i in range(10):
        for j in range(7):
            b.fill_matrix(b.board_tetrominos_matrix, i, j)
    assert b.get_filled_indices() == filled_indices
Esempio n. 2
0
def test_switch_current_tetromino():
    b = Board(10, 22)
    for i in range(100):
        last_tetromino_id = b.current_tetromino.id
        b.switch_current_tetromino()
        if not i + 1 % 7:
            assert b.current_tetromino.id != last_tetromino_id
Esempio n. 3
0
def test_hold_current_tetromino():
    b = Board(10, 22)
    m = Movement(b)
    assert b.held_tetromino is None
    last_tetromino_id = b.current_tetromino.id
    # should hold current tetromino
    b.hold_current_tetromino()
    assert b.held_tetromino.id == last_tetromino_id
    # not dropped yet, so held tetromino should be unchanged
    b.hold_current_tetromino()
    assert b.held_tetromino.id == last_tetromino_id
    # drop tetromino then hold, held tetromino should replace current
    m.hard_drop()
    b.hold_current_tetromino()
    assert b.held_tetromino.id != last_tetromino_id
    assert b.current_tetromino.id == last_tetromino_id
    # test held tetromino position gets reset if moved before holding
    b.current_tetromino.offset(-1, 0)
    assert (b.current_tetromino.origin.x, b.current_tetromino.origin.y) != \
        (SPAWN[b.current_tetromino.id].x, SPAWN[b.current_tetromino.id].y)
    b.hold_current_tetromino()
    m.hard_drop()
    b.hold_current_tetromino()
    assert (b.current_tetromino.origin.x, b.current_tetromino.origin.y) == \
        (SPAWN[b.current_tetromino.id].x, SPAWN[b.current_tetromino.id].y)
Esempio n. 4
0
def test_drop_lines_multiple():
    b = Board(10, 22)
    for i in range(10):
        b.board_tetrominos_squares.append(Square(Point(i, 0), colors.ASH))
        b.board_tetrominos_squares.append(Square(Point(i, 2), colors.ASH))
    b.board_tetrominos_squares.append(Square(Point(0, 1), colors.ASH))
    b.board_tetrominos_squares.append(Square(Point(1, 1), colors.ASH))
    b.board_tetrominos_squares.append(Square(Point(2, 1), colors.ASH))
    b.board_tetrominos_squares.append(Square(Point(0, 3), colors.ASH))
    b.board_tetrominos_squares.append(Square(Point(1, 3), colors.ASH))

    b.update_matrices()
    filled_indices = b.get_filled_indices()
    b.clear_lines(filled_indices)
    b.drop_lines(filled_indices)
    b.update_matrices()

    for i in range(3):
        assert b.board_tetrominos_matrix[i][0] == 1
    for i in range(3, 10):
        assert b.board_tetrominos_matrix[i][0] == 0

    for i in range(2):
        assert b.board_tetrominos_matrix[i][1] == 1
    for i in range(2, 10):
        assert b.board_tetrominos_matrix[i][1] == 0
Esempio n. 5
0
def test_drop_lines_single():
    b = Board(10, 22)
    b.current_tetromino = Tetromino("O", SPAWN["O"], COLORS["O"])
    b.ghost_tetromino = b.get_ghost_tetromino()
    for i in range(10):
        b.board_tetrominos_squares.append(Square(Point(i, 0), colors.ASH))
    b.board_tetrominos_squares.append(Square(Point(0, 1), colors.ASH))
    b.board_tetrominos_squares.append(Square(Point(1, 1), colors.ASH))
    b.board_tetrominos_squares.append(Square(Point(2, 1), colors.ASH))

    b.update_matrices()
    filled_indices = b.get_filled_indices()
    b.clear_lines(filled_indices)
    b.drop_lines(filled_indices)
    b.update_matrices()

    ghost_squares = b.ghost_tetromino.squares

    assert ghost_squares[0].x == 4
    assert ghost_squares[0].x == 4
    assert ghost_squares[0].y == 0
    assert ghost_squares[1].x == 5
    assert ghost_squares[1].y == 0
    assert ghost_squares[2].x == 5
    assert ghost_squares[2].y == 1
    assert ghost_squares[3].x == 4
    assert ghost_squares[3].y == 1

    for i in range(3):
        assert b.board_tetrominos_matrix[i][0] == 1
    for i in range(3, 10):
        assert b.board_tetrominos_matrix[i][0] == 0
Esempio n. 6
0
 def __init__(self, *args, **kwargs):
     """Initialize a Window object."""
     log.info("Initializing window {}".format(args))
     super().__init__(*args, **kwargs)
     self.board = Board(int(self.width / config.UNIT),
                        int(self.height / config.UNIT))
     self.keyboard = Keyboard(Movement(self.board))
     self.on_key_press = self.keyboard.on_key_press
Esempio n. 7
0
 def test_board_can_extract_jobs_by_status(self):
     jobs = [
         Job(status='pending'),
         Job(status='active'),
         Job(status='active')
     ]
     board = Board(jobs=jobs)
     self.assertEqual(len(board.jobs_by_status('pending')), 1)
Esempio n. 8
0
def test_clear_matrix():
    b = Board(10, 22)
    for i in range(10):
        for j in range(22):
            b.fill_matrix(b.board_tetrominos_matrix, i, j)
    b.clear_matrix(b.board_tetrominos_matrix)
    for i in range(10):
        for j in range(22):
            assert b.board_tetrominos_matrix[i][j] == 0
Esempio n. 9
0
def test_init():
    width = 10
    height = 22
    b = Board(width, height)
    assert b.width == width
    assert b.height == height
    assert len(b.board_tetrominos_matrix) == width
    for column in b.board_tetrominos_matrix:
        assert len(column) == height
        for value in column:
            assert value == 0
    assert len(b.current_tetromino_matrix) == width
    for column in b.current_tetromino_matrix:
        assert len(column) == height
    assert b.random_tetrominos is not None
    assert b.current_tetromino.id in ["O", "I", "J", "L", "S", "Z", "T"]
    assert len(b.board_tetrominos_squares) == 0
Esempio n. 10
0
def test_clear_lines():
    b = Board(10, 22)
    # Set up lines that should be cleared
    for i in range(10):
        b.board_tetrominos_squares.append(Square(Point(i, 3), colors.ASH))
        b.board_tetrominos_squares.append(Square(Point(i, 8), colors.ASH))

    b.update_matrices()
    filled_indices = b.get_filled_indices()
    b.clear_lines(filled_indices)
    b.update_matrices()

    lines_cleared = True
    for i in range(10):
        if (b.board_tetrominos_matrix[i][3] == 1
                or b.board_tetrominos_matrix[i][8] == 1):
            lines_cleared = False
    assert lines_cleared
Esempio n. 11
0
 def test_board_can_sort_jobs_by_title(self):
     jobs = [Job(title="cccccc"), Job(title="bbbbbb"), Job(title="aaaaaa")]
     board = Board(jobs = jobs)
     sorted_jobs = board.jobs_sorted_by(attribute = 'title')
     self.assertEqual(sorted_jobs[0].title, "Aaaaaa")
Esempio n. 12
0
 def test_board_has_zero_jobs_by_default(self):
     self.assertEqual(len(Board().jobs), 0)
Esempio n. 13
0
 def test_board_can_set_jobs_in_constructor(self):
     jobs = [Job(), Job(), Job()]
     board = Board(jobs = jobs)
     self.assertEqual(len(board.jobs), 3)
Esempio n. 14
0
def test_unfill_matrix():
    b = Board(10, 22)
    for i in range(10):
        for j in range(22):
            b.unfill_matrix(b.board_tetrominos_matrix, i, j)
            assert b.board_tetrominos_matrix[i][j] == 0
Esempio n. 15
0
 def test_board_returns_no_jobs_if_no_jobs_are_in_board(self):
     board = Board()
     self.assertEqual(len(board.jobs_by_status('dead')), 0)
Esempio n. 16
0
 def test_board_ignores_expired_jobs_when_extracting_by_status(self):
     jobs = [Job(due_date=datetime.date(1991, 4, 20), status='dead')]
     board = Board(jobs=jobs)
     self.assertEqual(len(board.jobs_by_status('dead')), 1)
Esempio n. 17
0
def test_get_filled_indices_should_be_zero():
    b = Board(10, 22)
    assert not b.get_filled_indices()
Esempio n. 18
0
import unittest

import numpy as np
from numpy import testing as np_test

from src.board.board import Board
from src.board.board_exception import BoardException

# TODO: There must be a nicer way to set this up
board = [[0, 6, 0, 3, 0, 0, 8, 0, 4], [5, 3, 7, 0, 9, 0, 0, 0, 0],
         [0, 4, 0, 0, 0, 6, 3, 0, 7], [0, 9, 0, 0, 5, 1, 2, 3, 8],
         [0, 0, 0, 0, 0, 0, 0, 0, 0], [7, 1, 3, 6, 2, 0, 0, 4, 0],
         [3, 0, 6, 4, 0, 0, 0, 1, 0], [0, 0, 0, 0, 6, 0, 5, 2, 3],
         [1, 0, 2, 0, 0, 9, 0, 8, 0]]
sudoku = Board(board)


class WhenSelectingElement(unittest.TestCase):
    def test_return_correct_element(self):
        self.assertEqual(sudoku.element(1, 2).value, 6)

    # TODO: Extract similar tests to a method to reduce repetition
    def test_throws_BoardException_when_out_of_bounds(self):
        with self.assertRaises(BoardException):
            sudoku.element(0, 4)
        with self.assertRaises(BoardException):
            sudoku.element(10, 4)
        with self.assertRaises(BoardException):
            sudoku.element(None, 4)
        with self.assertRaises(BoardException):
            sudoku.element(4, 0)
Esempio n. 19
0
 def test_board_ignores_sort_if_attribute_does_not_exist(self):
     jobs = [Job(title="cccccc"), Job(title="bbbbbb"), Job(title="aaaaaa")]
     board = Board(jobs = jobs)
     not_sorted_jobs = board.jobs_sorted_by(attribute = 'non-existent-field')
     self.assertEqual(not_sorted_jobs[0].title, "Cccccc")
Esempio n. 20
0
 def test_board_does_not_sort_by_default(self):
     jobs = [Job(title="xxxxxx"), Job(title="bbbbbb"), Job(title="aaaaaa")]
     board = Board(jobs = jobs)
     self.assertEqual(board.jobs[0].title, "Xxxxxx")
Esempio n. 21
0
 def find(self):
     job_repository = JobRepository(self._database)
     jobs = job_repository.findAll()
     return Board(jobs=jobs)