From 6d24e9cdbbb3a7d03c1c63938a6b7c99c7e7a049 Mon Sep 17 00:00:00 2001 From: Woofle Date: Tue, 24 Dec 2024 18:58:40 -0500 Subject: [PATCH] 1.1 update add error message as a class object thingy that can be accessed instead of just a printed statement --- TEST_virtual_sq1.py | 49 +++++++++++++++++++++++++++++++-------------- setup.py | 2 +- virtual_sq1.py | 14 +++++++++---- 3 files changed, 45 insertions(+), 20 deletions(-) diff --git a/TEST_virtual_sq1.py b/TEST_virtual_sq1.py index aae34d9..92a5836 100644 --- a/TEST_virtual_sq1.py +++ b/TEST_virtual_sq1.py @@ -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(): @@ -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 == '' diff --git a/setup.py b/setup.py index 17eb0a0..5edb9f4 100644 --- a/setup.py +++ b/setup.py @@ -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', diff --git a/virtual_sq1.py b/virtual_sq1.py index 860b213..fb54313 100644 --- a/virtual_sq1.py +++ b/virtual_sq1.py @@ -49,7 +49,7 @@ Need help? Visit https://github.com/Wo0fle/virtual-sq1 """ -__version__ = '1.0.0' +__version__ = '1.1.0' class Square1: @@ -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.""" @@ -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.""" @@ -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) @@ -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!')