Beispiel #1
0
    def test_alive_normal(self, sample_matrix_normal):
        matrix = sample_matrix_normal["matrix"]

        board = BoardVO.build(matrix)

        assert board.alive(0, 0)
        assert not board.alive(1, 0)
Beispiel #2
0
    def test_build_normal(self, sample_matrix_normal):
        expected_width = sample_matrix_normal["width"]
        expected_height = sample_matrix_normal["height"]
        matrix = sample_matrix_normal["matrix"]

        try:
            board = BoardVO.build(matrix, expected_width, expected_height)
            assert board.width == expected_width
            assert board.height == expected_height
        except IndexError:
            assert False
Beispiel #3
0
    def test_alive_except_with_less_than_0(self, sample_matrix_normal):
        matrix = sample_matrix_normal["matrix"]

        board = BoardVO.build(matrix)

        with pytest.raises(IndexError):
            board.alive(-1, -1)

        with pytest.raises(IndexError):
            board.alive(-1, 0)

        with pytest.raises(IndexError):
            board.alive(0, -1)
Beispiel #4
0
    def test___init___normal(self, sample_matrix_normal):
        matrix = sample_matrix_normal["matrix"]
        expected_width = sample_matrix_normal["width"]
        expected_height = sample_matrix_normal["height"]

        try:
            board = BoardVO.build(matrix)
            board_ds = BoardDomainService(board, False, 10)
            current = board_ds.current
            assert current.width == expected_width
            assert current.height == expected_height
        except IndexError:
            assert False
Beispiel #5
0
    def test_count_neighbors_except_less_than_0(self, sample_matrix_normal):
        matrix = sample_matrix_normal["matrix"]

        board = BoardVO.build(matrix)

        with pytest.raises(IndexError):
            board.count_neighbors(-1, -1)

        with pytest.raises(IndexError):
            board.count_neighbors(-1, 0)

        with pytest.raises(IndexError):
            board.count_neighbors(0, -1)
Beispiel #6
0
    def test_transition_to_next_generation_normal(self, sample_matrix_normal):
        matrix = sample_matrix_normal["matrix"]
        expected = ((False, False, False, False,
                     False), (False, True, False, False,
                              False), (False, False, True, True, False),
                    (False, False, False, False, False), (False, True, True,
                                                          True, False))

        board = BoardVO.build(matrix)
        board_ds = BoardDomainService(board, False, 10)
        board_ds.transition_to_next_generation()
        current = board_ds.current
        assert current.board == expected
        assert len(board_ds) == 2
Beispiel #7
0
    def test_count_neighbors_normal(self, sample_matrix_normal):
        matrix = sample_matrix_normal["matrix"]

        expected = [[1, 2, 0, 0, 0], [1, 3, 1, 2, 1], [2, 4, 2, 3, 0],
                    [2, 4, 4, 5, 2], [2, 3, 3, 3, 0]]

        board = BoardVO.build(matrix)

        actual = []
        for y in range(5):
            actual.append([])
            for x in range(5):
                actual[y].append(board.count_neighbors(x, y))

        assert all([e == a for e, a in zip(expected, actual)])
Beispiel #8
0
    def test_alive_except_with_more_than_expected(self, sample_matrix_normal):
        width = sample_matrix_normal["width"]
        height = sample_matrix_normal["height"]
        matrix = sample_matrix_normal["matrix"]

        board = BoardVO.build(matrix)

        with pytest.raises(IndexError):
            board.alive(width + 1, height + 1)

        with pytest.raises(IndexError):
            board.alive(width + 1, height)

        with pytest.raises(IndexError):
            board.alive(width, height + 1)
Beispiel #9
0
    def test_move_previous(self, sample_matrix_normal):
        matrix = sample_matrix_normal["matrix"]

        board = BoardVO.build(matrix)
        board_ds = BoardDomainService(board, False, 10)
        expected = board_ds.current

        board_ds.transition_to_next_generation()
        board_ds.move_previous()
        current = board_ds.current

        assert expected == current

        with pytest.raises(IndexError):
            board_ds.move_previous()
Beispiel #10
0
    def test_count_neighbors_normal_with_looped(self, sample_matrix_normal):
        width = sample_matrix_normal["width"]
        height = sample_matrix_normal["height"]
        matrix = sample_matrix_normal["matrix"]

        expected = [[3, 4, 2, 2, 3], [2, 3, 1, 2, 3], [3, 4, 2, 3, 1],
                    [4, 4, 4, 5, 2], [4, 4, 3, 3, 1]]

        board = BoardVO.build(matrix)

        actual = []
        for y in range(height):
            actual.append([])
            for x in range(width):
                actual[y].append(board.count_neighbors(x, y, True))

        assert all([e == a for e, a in zip(expected, actual)])
Beispiel #11
0
    def test_build_except_with_less_than_0(self, sample_matrix_normal):
        width = sample_matrix_normal["width"]
        height = sample_matrix_normal["height"]
        matrix = sample_matrix_normal["matrix"]

        with pytest.raises(IndexError):
            BoardVO.build(matrix, -1, height)

        with pytest.raises(IndexError):
            BoardVO.build(matrix, width, -1)

        with pytest.raises(IndexError):
            BoardVO.build(matrix, -1, -1)