Restructured code
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
"""Contains function to manually test the visual detection of a board"""
|
||||
|
||||
import numpy as np
|
||||
import cv2
|
||||
|
||||
from shenzhen_solitaire.cv import adjustment
|
||||
from shenzhen_solitaire.cv import board_parser
|
||||
from shenzhen_solitaire import board
|
||||
from shenzhen_solitaire.cv.configuration import Configuration
|
||||
|
||||
|
||||
def generate() -> None:
|
||||
"""Generate a configuration"""
|
||||
with open("pictures/20190809172213_1.jpg", 'rb') as png_file:
|
||||
img_str = png_file.read()
|
||||
nparr = np.frombuffer(img_str, np.uint8)
|
||||
image = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
|
||||
|
||||
generated_config = Configuration.generate(image)
|
||||
generated_config.save('test_config.zip')
|
||||
|
||||
|
||||
def parse() -> board.Board:
|
||||
"""Parse a configuration"""
|
||||
with open("pictures/20190809172213_1.jpg", 'rb') as png_file:
|
||||
img_str = png_file.read()
|
||||
nparr = np.frombuffer(img_str, np.uint8)
|
||||
image = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
|
||||
# image = cv2.resize(image, (1000, 629))
|
||||
|
||||
loaded_config = Configuration.load('test_config.zip')
|
||||
# loaded_config.field_adjustment = adjustment.adjust_field(image)
|
||||
return board_parser.parse_board(image, loaded_config)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# generate()
|
||||
parse()
|
||||
@@ -2,12 +2,12 @@
|
||||
import unittest
|
||||
|
||||
from shenzhen_solitaire.board import NumberCard, Position
|
||||
from shenzhen_solitaire.board_actions import MoveAction, BunkerizeAction, GoalAction, HuaKillAction
|
||||
from shenzhen_solitaire import board_possibilities
|
||||
from shenzhen_solitaire.solver.board_actions import MoveAction, BunkerizeAction, GoalAction, HuaKillAction
|
||||
from shenzhen_solitaire.solver import board_possibilities
|
||||
from .boards import TEST_BOARD
|
||||
|
||||
|
||||
class ChainTestClass(unittest.TestCase):
|
||||
class ChainTest(unittest.TestCase):
|
||||
"""Tests the chain class"""
|
||||
|
||||
def test_sequence(self) -> None:
|
||||
|
||||
24
test/test_cv.py
Normal file
24
test/test_cv.py
Normal file
@@ -0,0 +1,24 @@
|
||||
"""Contains function to manually test the visual detection of a board"""
|
||||
|
||||
import unittest
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
from shenzhen_solitaire import board
|
||||
from shenzhen_solitaire.card_detection import adjustment, board_parser
|
||||
from shenzhen_solitaire.card_detection.configuration import Configuration
|
||||
|
||||
|
||||
class CardDetectionTest(unittest.TestCase):
|
||||
def test_parse(self) -> None:
|
||||
"""Parse a configuration"""
|
||||
with open("pictures/20190809172213_1.jpg", "rb") as png_file:
|
||||
img_str = png_file.read()
|
||||
nparr = np.frombuffer(img_str, np.uint8)
|
||||
image = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
|
||||
# image = cv2.resize(image, (1000, 629))
|
||||
|
||||
loaded_config = Configuration.load("test_config.zip")
|
||||
# loaded_config.field_adjustment = adjustment.adjust_field(image)
|
||||
print(board_parser.parse_board(image, loaded_config))
|
||||
@@ -2,7 +2,7 @@
|
||||
import unittest
|
||||
import copy
|
||||
|
||||
from shenzhen_solitaire import solver
|
||||
from shenzhen_solitaire.solver import solver
|
||||
|
||||
from .boards import TEST_BOARD
|
||||
|
||||
@@ -13,7 +13,7 @@ class SolverTest(unittest.TestCase):
|
||||
def test_solver(self) -> None:
|
||||
"""Tests solver"""
|
||||
board_copy = copy.deepcopy(TEST_BOARD)
|
||||
board_id = TEST_BOARD.state_identifier # type: ignore
|
||||
board_id = TEST_BOARD.state_identifier
|
||||
board_solution_iterator = solver.solve(TEST_BOARD)
|
||||
for _, current_solution in zip(range(1), board_solution_iterator):
|
||||
self.assertEqual(board_id, board_copy.state_identifier)
|
||||
|
||||
Reference in New Issue
Block a user