diff --git a/symmetria/elements/_base.py b/symmetria/elements/_base.py index be617d8..023b1c7 100644 --- a/symmetria/elements/_base.py +++ b/symmetria/elements/_base.py @@ -1,11 +1,28 @@ +from dataclasses import dataclass + + +@dataclass(init=False, frozen=True, order=False, eq=False) class _Element: """Base class for elements.""" - @staticmethod - def name() -> str: - """Shortcut for the class name.""" - return __class__.__name__ - def rep(self) -> str: """Shortcut for `__repr__()`.""" return self.__repr__() + + def typename(self) -> str: + """Shortcut for the name of the class type. + + :return: The name of the class type. + :rtype: str + + :example: + >>> from symmetria import Cycle, CycleDecomposition, Permutation + ... + >>> Permutation(1, 2, 3).typename() + 'Permutation' + >>> Cycle(1, 2).typename() + 'Cycle' + >>> CycleDecomposition(Cycle(1, 3, 2)).typename() + 'CycleDecomposition' + """ + return self.__class__.__name__ diff --git a/tests/test_factory.py b/tests/test_utils.py similarity index 100% rename from tests/test_factory.py rename to tests/test_utils.py diff --git a/tests/tests_cycle/__init__.py b/tests/tests_elements/__init__.py similarity index 100% rename from tests/tests_cycle/__init__.py rename to tests/tests_elements/__init__.py diff --git a/tests/tests_elements/test_base.py b/tests/tests_elements/test_base.py new file mode 100644 index 0000000..c09ea9d --- /dev/null +++ b/tests/tests_elements/test_base.py @@ -0,0 +1,35 @@ +import pytest + +from symmetria import Cycle, Permutation, CycleDecomposition +from tests.test_utils import _check_values +from symmetria.elements._base import _Element + + +@pytest.mark.parametrize( + argnames="expression, evaluation, expected", + argvalues=[ + ("_element.name()", _Element().typename(), "_Element"), + ("Permutation(1).name()", Permutation(1).typename(), "Permutation"), + ("Cycle(1).name()", Cycle(1).typename(), "Cycle"), + ("CycleDecomposition(Cycle(1)).name()", CycleDecomposition(Cycle(1)).typename(), "CycleDecomposition"), + ], +) +def test_name(expression, evaluation, expected) -> None: + _check_values(expression=expression, evaluation=evaluation, expected=expected) + + +@pytest.mark.parametrize( + argnames="expression, evaluation, expected", + argvalues=[ + ("_element.rep()", _Element().rep(), "_Element()"), + ("Permutation(1).rep()", Permutation(1).rep(), Permutation(1).__repr__()), + ("Cycle(1).rep()", Cycle(1).rep(), Cycle(1).__repr__()), + ( + "CycleDecomposition(Cycle(1)).rep()", + CycleDecomposition(Cycle(1)).rep(), + CycleDecomposition(Cycle(1)).__repr__(), + ), + ], +) +def test_rep(expression, evaluation, expected) -> None: + _check_values(expression=expression, evaluation=evaluation, expected=expected) diff --git a/tests/tests_cycle_decomposition/__init__.py b/tests/tests_elements/tests_cycle/__init__.py similarity index 100% rename from tests/tests_cycle_decomposition/__init__.py rename to tests/tests_elements/tests_cycle/__init__.py diff --git a/tests/tests_cycle/test_cases.py b/tests/tests_elements/tests_cycle/test_cases.py similarity index 100% rename from tests/tests_cycle/test_cases.py rename to tests/tests_elements/tests_cycle/test_cases.py diff --git a/tests/tests_cycle/test_constructors.py b/tests/tests_elements/tests_cycle/test_constructors.py similarity index 92% rename from tests/tests_cycle/test_constructors.py rename to tests/tests_elements/tests_cycle/test_constructors.py index f5389b2..1fce6fc 100644 --- a/tests/tests_cycle/test_constructors.py +++ b/tests/tests_elements/tests_cycle/test_constructors.py @@ -1,7 +1,7 @@ import pytest from symmetria import Cycle -from tests.tests_cycle.test_cases import ( +from tests.tests_elements.tests_cycle.test_cases import ( TEST_CONSTRUCTOR, TEST_CONSTRUCTOR_ERROR, ) diff --git a/tests/tests_cycle/test_generic_method.py b/tests/tests_elements/tests_cycle/test_generic_method.py similarity index 98% rename from tests/tests_cycle/test_generic_method.py rename to tests/tests_elements/tests_cycle/test_generic_method.py index cea9582..7b9aefc 100644 --- a/tests/tests_cycle/test_generic_method.py +++ b/tests/tests_elements/tests_cycle/test_generic_method.py @@ -1,8 +1,8 @@ import pytest from symmetria import Cycle -from tests.test_factory import _check_values -from tests.tests_cycle.test_cases import ( +from tests.test_utils import _check_values +from tests.tests_elements.tests_cycle.test_cases import ( TEST_MAP, TEST_SGN, TEST_ORBIT, diff --git a/tests/tests_cycle/test_magic_methods.py b/tests/tests_elements/tests_cycle/test_magic_methods.py similarity index 94% rename from tests/tests_cycle/test_magic_methods.py rename to tests/tests_elements/tests_cycle/test_magic_methods.py index 2da8722..712b8c2 100644 --- a/tests/tests_cycle/test_magic_methods.py +++ b/tests/tests_elements/tests_cycle/test_magic_methods.py @@ -1,7 +1,7 @@ import pytest -from tests.test_factory import _check_values -from tests.tests_cycle.test_cases import ( +from tests.test_utils import _check_values +from tests.tests_elements.tests_cycle.test_cases import ( TEST_EQ, TEST_INT, TEST_LEN, @@ -126,4 +126,4 @@ def test_pow_error(cycle, power, error, msg) -> None: ) def test_repr(cycle, expected_value) -> None: """Tests for the method `__repr__()`.""" - _check_values(expression=f"{cycle.name}.__repr__()", evaluation=cycle.__repr__(), expected=expected_value) + _check_values(expression=f"{cycle.typename}.__repr__()", evaluation=cycle.__repr__(), expected=expected_value) diff --git a/tests/tests_permutation/__init__.py b/tests/tests_elements/tests_cycle_decomposition/__init__.py similarity index 100% rename from tests/tests_permutation/__init__.py rename to tests/tests_elements/tests_cycle_decomposition/__init__.py diff --git a/tests/tests_cycle_decomposition/test_cases.py b/tests/tests_elements/tests_cycle_decomposition/test_cases.py similarity index 100% rename from tests/tests_cycle_decomposition/test_cases.py rename to tests/tests_elements/tests_cycle_decomposition/test_cases.py diff --git a/tests/tests_cycle_decomposition/test_constructors.py b/tests/tests_elements/tests_cycle_decomposition/test_constructors.py similarity index 91% rename from tests/tests_cycle_decomposition/test_constructors.py rename to tests/tests_elements/tests_cycle_decomposition/test_constructors.py index 34105a2..4db6735 100644 --- a/tests/tests_cycle_decomposition/test_constructors.py +++ b/tests/tests_elements/tests_cycle_decomposition/test_constructors.py @@ -1,7 +1,7 @@ import pytest from symmetria import CycleDecomposition -from tests.tests_cycle_decomposition.test_cases import ( +from tests.tests_elements.tests_cycle_decomposition.test_cases import ( TEST_CONSTRUCTOR, TEST_CONSTRUCTOR_ERROR, ) diff --git a/tests/tests_cycle_decomposition/test_generic_methods.py b/tests/tests_elements/tests_cycle_decomposition/test_generic_methods.py similarity index 98% rename from tests/tests_cycle_decomposition/test_generic_methods.py rename to tests/tests_elements/tests_cycle_decomposition/test_generic_methods.py index c7de9e8..40792e8 100644 --- a/tests/tests_cycle_decomposition/test_generic_methods.py +++ b/tests/tests_elements/tests_cycle_decomposition/test_generic_methods.py @@ -1,7 +1,7 @@ import pytest -from tests.test_factory import _check_values -from tests.tests_cycle_decomposition.test_cases import ( +from tests.test_utils import _check_values +from tests.tests_elements.tests_cycle_decomposition.test_cases import ( TEST_MAP, TEST_SGN, TEST_ORBIT, diff --git a/tests/tests_cycle_decomposition/test_magic_methods.py b/tests/tests_elements/tests_cycle_decomposition/test_magic_methods.py similarity index 95% rename from tests/tests_cycle_decomposition/test_magic_methods.py rename to tests/tests_elements/tests_cycle_decomposition/test_magic_methods.py index 0368da0..2af6628 100644 --- a/tests/tests_cycle_decomposition/test_magic_methods.py +++ b/tests/tests_elements/tests_cycle_decomposition/test_magic_methods.py @@ -1,8 +1,8 @@ import pytest from symmetria import Cycle, CycleDecomposition -from tests.test_factory import _check_values -from tests.tests_cycle_decomposition.test_cases import ( +from tests.test_utils import _check_values +from tests.tests_elements.tests_cycle_decomposition.test_cases import ( TEST_EQ, TEST_POW, TEST_BOOL, @@ -124,7 +124,7 @@ def test_pow_error(cycle_decomposition, power, error, msg) -> None: def test_repr(cycle_decomposition, expected_value) -> None: """Tests for the method `__repr__()`.""" _check_values( - expression=f"{cycle_decomposition.name}.__repr__()", + expression=f"{cycle_decomposition.typename}.__repr__()", evaluation=cycle_decomposition.__repr__(), expected=expected_value, ) diff --git a/tests/tests_elements/tests_permutation/__init__.py b/tests/tests_elements/tests_permutation/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/tests_permutation/test_cases.py b/tests/tests_elements/tests_permutation/test_cases.py similarity index 100% rename from tests/tests_permutation/test_cases.py rename to tests/tests_elements/tests_permutation/test_cases.py diff --git a/tests/tests_permutation/test_constructors.py b/tests/tests_elements/tests_permutation/test_constructors.py similarity index 95% rename from tests/tests_permutation/test_constructors.py rename to tests/tests_elements/tests_permutation/test_constructors.py index 6f9e281..dc45cb6 100644 --- a/tests/tests_permutation/test_constructors.py +++ b/tests/tests_elements/tests_permutation/test_constructors.py @@ -1,8 +1,8 @@ import pytest from symmetria import Permutation -from tests.test_factory import _check_values -from tests.tests_permutation.test_cases import ( +from tests.test_utils import _check_values +from tests.tests_elements.tests_permutation.test_cases import ( TEST_CONSTRUCTOR, TEST_CONSTRUCTOR_ERROR, TEST_CONSTRUCTOR_FROM_DICT, diff --git a/tests/tests_permutation/test_generic_methods.py b/tests/tests_elements/tests_permutation/test_generic_methods.py similarity index 98% rename from tests/tests_permutation/test_generic_methods.py rename to tests/tests_elements/tests_permutation/test_generic_methods.py index ea06739..e451193 100644 --- a/tests/tests_permutation/test_generic_methods.py +++ b/tests/tests_elements/tests_permutation/test_generic_methods.py @@ -1,7 +1,7 @@ import pytest -from tests.test_factory import _check_values -from tests.tests_permutation.test_cases import ( +from tests.test_utils import _check_values +from tests.tests_elements.tests_permutation.test_cases import ( TEST_MAP, TEST_SGN, TEST_IMAGE, diff --git a/tests/tests_permutation/test_magic_methods.py b/tests/tests_elements/tests_permutation/test_magic_methods.py similarity index 95% rename from tests/tests_permutation/test_magic_methods.py rename to tests/tests_elements/tests_permutation/test_magic_methods.py index 5014535..0d001f0 100644 --- a/tests/tests_permutation/test_magic_methods.py +++ b/tests/tests_elements/tests_permutation/test_magic_methods.py @@ -1,7 +1,7 @@ import pytest -from tests.test_factory import _check_values -from tests.tests_permutation.test_cases import ( +from tests.test_utils import _check_values +from tests.tests_elements.tests_permutation.test_cases import ( TEST_EQ, TEST_INT, TEST_LEN, @@ -128,7 +128,7 @@ def test_pow_error(permutation, power, error, msg) -> None: def test_repr(permutation, expected_value) -> None: """Tests for the method `__repr__()`.""" _check_values( - expression=f"{permutation.name}.__repr__()", evaluation=permutation.__repr__(), expected=expected_value + expression=f"{permutation.typename}.__repr__()", evaluation=permutation.__repr__(), expected=expected_value )