Skip to content

Commit

Permalink
1.1 update
Browse files Browse the repository at this point in the history
add error message as a class object thingy that can be accessed instead of just a printed statement
  • Loading branch information
Wo0fle committed Dec 24, 2024
1 parent c5c1802 commit 6d24e9c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 20 deletions.
49 changes: 34 additions & 15 deletions TEST_virtual_sq1.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


# im pretty sure i tested every typical case
# soooo basically if something fails then thats a skill issue :]
# soooo basically if something fails then thats a skill issue :)

@pytest.fixture
def sq1():
Expand Down Expand Up @@ -32,50 +32,69 @@ def test_apply_state_with_dash(sq1):

def test_apply_illegal_alg_too_many_dashes_top(sq1):
sq1.apply_alg("--3/")
assert sq1.__str__() == "A1B2C3D4-5E6F7G8H"
assert sq1.error_message == 'Error at "--3" (move #1).\nSquare-1 reset to previous state.\n'


def test_apply_illegal_alg_too_many_dashes_bottom(sq1):
sq1.apply_alg("0,--3/")
assert sq1.__str__() == "A1B2C3D4-5E6F7G8H"
sq1.apply_alg("0,-3/0,--3")
assert sq1.error_message == 'Error at "0,--3" (move #2).\nSquare-1 reset to previous state.\n'


def test_apply_illegal_alg_too_many_commas(sq1):
sq1.apply_alg("3,4,5,6")
assert sq1.__str__() == "A1B2C3D4-5E6F7G8H"
assert sq1.error_message == 'Error at "3,4,5,6" (move #1).\nSquare-1 reset to previous state.\n'


def test_apply_illegal_alg_impossible_top_turn(sq1):
sq1.apply_alg("2")
assert sq1.__str__() == "A1B2C3D4-5E6F7G8H"
sq1.apply_alg("2 oh hello there! you should IGNORE THIS TEXT BRUH")
assert sq1.error_message == 'Error at "2" (move #1).\nSquare-1 reset to previous state.\n'


def test_apply_illegal_alg_impossible_bottom_turn(sq1):
sq1.apply_alg("0,-2")
assert sq1.__str__() == "A1B2C3D4-5E6F7G8H"
sq1.apply_alg("0,2/3/0,2")
assert sq1.error_message == 'Error at "0,2" (move #3).\nSquare-1 reset to previous state.\n'


def test_apply_illegal_case(sq1):
sq1.apply_alg("2/", True)
assert sq1.__str__() == "A1B2C3D4-5E6F7G8H"
sq1.apply_alg("/ (3,0) / (1,0) / (0,-3) / (-1,0) / (-3,0) / (1,0) / (0,3) /", True)
# in case you don't see why this is an issue, it's missing the top layer realignment at the end to make the sq1 back into a square, which makes the alg inversion fail
assert sq1.error_message == 'Error at "1,0" (move #7).\nCheck that your input starts and ends in fully-aligned cubeshape.\nSquare-1 reset to previous state.\n'


def test_apply_illegal_state_extra_pieces(sq1):
sq1.apply_state("ABCDEFGHI123456789")
assert sq1.__str__() == "A1B2C3D4-5E6F7G8H"
assert sq1.error_message == 'Error with "ABCDEFGHI123456789".\nCheck your input isn\'t missing any or contains any extra symbols.\nSquare-1 reset to previous state.\n'


def test_apply_illegal_state_missing_pieces(sq1):
sq1.apply_state("ABCDEF1234567")
assert sq1.__str__() == "A1B2C3D4-5E6F7G8H"
assert sq1.error_message == 'Error with "ABCDEF1234567".\nCheck your input isn\'t missing any or contains any extra symbols.\nSquare-1 reset to previous state.\n'


def test_apply_illegal_state_impossible_state(sq1):
sq1.apply_state("1ABCDEFG2345678")
assert sq1.__str__() == "A1B2C3D4-5E6F7G8H"

assert sq1.error_message == 'Error with "1ABCDEFG2345678".\nCheck your input isn\'t missing any or contains any extra symbols.\nSquare-1 reset to previous state.\n'
# no need to include a "check that your input is actually possible" message IMO because... that's kind of implied

def test_apply_algs_from_different_initial_states(sq1):
sq1.apply_state("CG216F5B/EHD4A837")
sq1.apply_alg("(3,-1)/ (-2,1)/ (2,-4)/ (-2,-5)/ (0,-3)/ (3,-1)/ (0,-3)/ (3,0)/ (4,-4)/ (6,-2)", True)
assert sq1.__str__() == "A1B2C3D4-5E6F7G8H"

def test_error_message_reset_from_bad_alg(sq1):
sq1.apply_alg("2/")
assert sq1.error_message == 'Error at "2" (move #1).\nSquare-1 reset to previous state.\n'
sq1.apply_alg("//")
assert sq1.error_message == ''

def test_error_message_reset_from_bad_case(sq1):
sq1.apply_alg("-2/", True)
assert sq1.error_message == 'Error at "-2" (move #1).\nCheck that your input starts and ends in fully-aligned cubeshape.\nSquare-1 reset to previous state.\n'
sq1.apply_alg("//")
assert sq1.error_message == ''

def test_error_message_reset_from_bad_state(sq1):
sq1.apply_state("1ABCDEFG2345678")
assert sq1.error_message == 'Error with "1ABCDEFG2345678".\nCheck your input isn\'t missing any or contains any extra symbols.\nSquare-1 reset to previous state.\n'
sq1.apply_alg("//")
assert sq1.error_message == ''
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
long_description = (this_directory / "README.md").read_text()

setup(
name='virtual_sq1',
name='virtual-sq1',
description='Python module that simulates a Square-1 twisty puzzle',
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down
14 changes: 10 additions & 4 deletions virtual_sq1.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
Need help? Visit https://github.com/Wo0fle/virtual-sq1
"""

__version__ = '1.0.0'
__version__ = '1.1.0'


class Square1:
Expand All @@ -65,6 +65,7 @@ def __init__(self) -> None:
self.top = Layer("A1B2C3D4")
self.equator_flipped = False
self.bottom = Layer("5E6F7G8H")
self.error_message = ""

def __str__(self) -> str:
"""Converts the Square1's state to a string."""
Expand Down Expand Up @@ -125,11 +126,13 @@ def _error_detected(self, input_type: int, errored_input, error_turns: list = []
if input_type == 0: # case
self._invert_alg(errored_input)

print(f'Error at "{",".join(error_turns)}" (move #{len(errored_input) - error_turns_i}).\nSquare-1 reset to previous state.\n')
self.error_message = f'Error at "{",".join(error_turns)}" (move #{len(errored_input) - error_turns_i}).\nCheck that your input starts and ends in fully-aligned cubeshape.\nSquare-1 reset to previous state.\n'
elif input_type == 1: # alg
print(f'Error at "{",".join(error_turns)}" (move #{error_turns_i + 1}).\nSquare-1 reset to previous state.\n')
self.error_message = f'Error at "{",".join(error_turns)}" (move #{error_turns_i + 1}).\nSquare-1 reset to previous state.\n'
elif input_type == 2: # state
print(f'Error with "{"".join(errored_input)}".\nSquare-1 reset to previous state.\n')
self.error_message = f'Error with "{"".join(errored_input)}".\nCheck your input isn\'t missing any or contains any extra symbols.\nSquare-1 reset to previous state.\n'

print(self.error_message)

def slash(self) -> None: # lol "slice" is taken by Python already
"""Does a slice/slash move to the Square1."""
Expand Down Expand Up @@ -257,6 +260,7 @@ def apply_alg(self, alg: str, for_case: bool = False) -> None:

if legal:
self.slash()
self.error_message = ""
else:
if for_case:
self._error_detected(0, simplfied_alg, simplfied_alg[i], i)
Expand Down Expand Up @@ -328,6 +332,8 @@ def apply_state(self, state: str) -> None:
self.top = Layer(new_top)
self.bottom = Layer(new_bottom)

self.error_message = ""

break
elif value > 12:
print('\nSYNTAX ERROR involving impossible layer state detected!')
Expand Down

0 comments on commit 6d24e9c

Please # to comment.