forked from UNN/2026-rff_mp
111 lines
3.2 KiB
Python
111 lines
3.2 KiB
Python
import pytest
|
|
import sys
|
|
import os
|
|
|
|
from source.models.base import Cell
|
|
|
|
class TestCellCreation:
|
|
"""Тесты создания клетки и начальных значений."""
|
|
|
|
def test_coordinates_are_set(self):
|
|
cell = Cell(3, 7)
|
|
assert cell.x == 3
|
|
assert cell.y == 7
|
|
|
|
def test_default_flags_are_false(self):
|
|
cell = Cell(0, 0)
|
|
assert cell.is_wall is False
|
|
assert cell.is_start is False
|
|
assert cell.is_exit is False
|
|
|
|
def test_create_wall(self):
|
|
cell = Cell(0, 0, is_wall=True)
|
|
assert cell.is_wall is True
|
|
|
|
def test_create_start(self):
|
|
cell = Cell(0, 0, is_start=True)
|
|
assert cell.is_start is True
|
|
|
|
def test_create_exit(self):
|
|
cell = Cell(0, 0, is_exit=True)
|
|
assert cell.is_exit is True
|
|
|
|
|
|
class TestCellIsPassable:
|
|
"""Тесты метода is_possible."""
|
|
|
|
def test_empty_cell_is_passable(self):
|
|
cell = Cell(0, 0)
|
|
assert cell.is_possible() is True
|
|
|
|
def test_wall_is_not_passable(self):
|
|
cell = Cell(0, 0, is_wall=True)
|
|
assert cell.is_possible() is False
|
|
|
|
def test_start_cell_is_passable(self):
|
|
cell = Cell(0, 0, is_start=True)
|
|
assert cell.is_possible() is True
|
|
|
|
def test_exit_cell_is_passable(self):
|
|
cell = Cell(0, 0, is_exit=True)
|
|
assert cell.is_possible() is True
|
|
|
|
|
|
class TestCellFlagsAreMutuallyExclusive:
|
|
"""Тесты взаимного исключения флагов."""
|
|
|
|
def test_set_wall_clears_start(self):
|
|
cell = Cell(0, 0, is_start=True)
|
|
cell.is_wall = True
|
|
assert cell.is_start is False
|
|
assert cell.is_wall is True
|
|
|
|
def test_set_wall_clears_exit(self):
|
|
cell = Cell(0, 0, is_exit=True)
|
|
cell.is_wall = True
|
|
assert cell.is_exit is False
|
|
assert cell.is_wall is True
|
|
|
|
def test_set_start_clears_wall(self):
|
|
cell = Cell(0, 0, is_wall=True)
|
|
cell.is_start = True
|
|
assert cell.is_wall is False
|
|
assert cell.is_start is True
|
|
|
|
def test_set_start_clears_exit(self):
|
|
cell = Cell(0, 0, is_exit=True)
|
|
cell.is_start = True
|
|
assert cell.is_exit is False
|
|
assert cell.is_start is True
|
|
|
|
def test_set_exit_clears_wall(self):
|
|
cell = Cell(0, 0, is_wall=True)
|
|
cell.is_exit = True
|
|
assert cell.is_wall is False
|
|
assert cell.is_exit is True
|
|
|
|
def test_set_exit_clears_start(self):
|
|
cell = Cell(0, 0, is_start=True)
|
|
cell.is_exit = True
|
|
assert cell.is_start is False
|
|
assert cell.is_exit is True
|
|
|
|
def test_unset_wall_does_not_clear_others(self):
|
|
# снятие флага (False) не должно трогать остальные
|
|
cell = Cell(0, 0, is_wall=True)
|
|
cell.is_wall = False
|
|
assert cell.is_start is False
|
|
assert cell.is_exit is False
|
|
|
|
|
|
class TestCellStr:
|
|
"""Тесты строкового представления клетки."""
|
|
|
|
def test_str_returns_string(self):
|
|
cell = Cell(0, 0)
|
|
assert isinstance(str(cell), str)
|
|
|
|
def test_repr_contains_coordinates(self):
|
|
cell = Cell(4, 9)
|
|
assert "4" in repr(cell)
|
|
assert "9" in repr(cell) |