solver-0h-h1/sources/test_grid.py

84 lines
2.5 KiB
Python
Raw Normal View History

# 0h h1 Solver. Solves grids of 0h h1 game.
# Copyright (C) 2015 Gabriel Augendre <gabriel@augendre.info>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
__author__ = 'gaugendre'
import pytest
from grid import *
@pytest.fixture
def array():
return [['B', ' ', ' ', ' '],
['B', 'B', ' ', ' '],
[' ', ' ', ' ', ' '],
[' ', 'B', ' ', 'B']]
@pytest.fixture
def full_grid(array):
return Grid(len(array), array)
@pytest.fixture
def empty_grid(array):
return Grid(len(array))
def test_without_state(empty_grid):
for line in empty_grid.squares:
for square in line:
assert square.state == ' '
def test_with_state(full_grid, array):
i = 0
for line in full_grid.squares:
j = 0
for square in line:
assert square.state == array[i][j]
j += 1
i += 1
# @pytest.fixture()
# def matrix():
# return [[0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1],
# [1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1],
# [1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1],
# [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
# [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
# [0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0],
# [1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0],
# [0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0]]
#
#
# def test_out_of_zone(matrix):
# beginning = Pixel(0, 0)
# assert region_growing(matrix, beginning) is None
#
#
# def test_in_zone(matrix):
# beginning = Pixel(1, 1)
# assert region_growing(matrix, beginning) == {Pixel(1, 0), Pixel(1, 1),
# Pixel(1, 2), Pixel(2, 0),
# Pixel(2, 1)}
#
#
# def test_out_of_matrix(matrix):
# beginning = Pixel(15, 12)
# assert region_growing(matrix, beginning) is None