From 7b9ce2aab2b26f836383b04e92db19449ce3db92 Mon Sep 17 00:00:00 2001 From: ThaHobbyist Date: Mon, 1 Jul 2024 13:52:45 +0530 Subject: [PATCH 1/4] Made a basic implementation of Dimensional units --- .gitignore | 3 +- pyvnt/Reference/dimSet.py | 96 +++++++++++++++++++++++++++++++++ pyvnt/Reference/errorClasses.py | 7 +++ 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 pyvnt/Reference/dimSet.py diff --git a/.gitignore b/.gitignore index 16dc710..08ad3b8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,8 @@ env build/ dist/ pyvnt.egg-info -manual_tests/* +manual_tests/ +manual_debug/ **/__pycache__/* .vscode diff --git a/pyvnt/Reference/dimSet.py b/pyvnt/Reference/dimSet.py new file mode 100644 index 0000000..c5b2a3a --- /dev/null +++ b/pyvnt/Reference/dimSet.py @@ -0,0 +1,96 @@ +from enum import IntEnum +from pyvnt.Reference.errorClasses import IncorrectLengthError +from pyvnt.Reference.basic import * + +class DimmType(IntEnum): + MASS = auto() + LENGTH = auto() + TIME = auto() + TEMPERATURE = auto() + MOLES = auto() + CURRENT = auto() + LUMINOUS_INTENSITY = auto() + +class DimmSet(ValueProperty): + ''' + DimmSet class is a class that represents a set of dimensions. + It is used to represent the dimensions of a physical quantity. + + Contrsucor Parameters: + name: str + The name of the physical quantity + dimms: list + A list of 7 elements representing the dimensions of the physical quantity. + The elements should be in the following order: + 1. Mass + 2. Length + 3. Time + 4. Temperature + 5. Moles + 6. Current + 7. Luminous Intensity + + ''' + __slots__ = ['name', 'dimmtype', 'dimm'] + + def __init__(self, name, dimms: [] = [0] * 7): + super(DimmSet, self).__init__() + + self.dimmtype = DimmType + self.dimm = [0] * 7 + self.name = name + + if len(dimms) == 7: + self.setProperties(*dimms) + else: + raise IncorrectLengthError(len(dimms)) + + def instance_restricted(self): + pass + + def setProperties(self, m = 0, l = 0, t = 0, temp = 0, mol = 0, c = 0, li = 0): + ''' + Sets the dimensions of the physical quantity. + + Parameters: + m: int + The dimension of mass. + l: int + The dimension of length. + t: int + The dimension of time. + temp: int + The dimension of temperature. + mol: int + The dimension of moles. + c: int + The dimension of current. + li: int + The dimension of luminous intensity. + ''' + if m: + self.dimm[DimmType.MASS] = m + if l: + self.dimm[DimmType.LENGTH] = l + if t: + self.dimm[DimmType.TIME] = t + if temp: + self.dimm[DimmType.TEMPERATURE] = tmp + if mol: + self.dimm[DimmType.MOLES] = mol + if c: + self.dimm[DimmType.CURRENT] = c + if li: + self.dimm[DimmType.LUMINOUS_INTENSITY] = li + + def __repr__(self): + return f"DimmSet({self.dimm})" + + def giveVal(self): + ''' + Returns the dimensions of the physical quantity. + ''' + + return self.dimm + + diff --git a/pyvnt/Reference/errorClasses.py b/pyvnt/Reference/errorClasses.py index da9fc5f..5db3495 100755 --- a/pyvnt/Reference/errorClasses.py +++ b/pyvnt/Reference/errorClasses.py @@ -99,4 +99,11 @@ def __init__(self, key: str): def __str__(self): return f"{self.key} Already exists" +class IncorrectLengthError(Exception): + def __init__(self, length: int): + self.length = length + + def __str__(self): + return f"Length of values should be 7. Length of given list is {self.length}" + From 1d209a5d5ec32f90572364bce17642b8e9a92f28 Mon Sep 17 00:00:00 2001 From: ThaHobbyist Date: Mon, 1 Jul 2024 14:28:27 +0530 Subject: [PATCH 2/4] Added tests for dimentional units --- pyvnt/Reference/dimSet.py | 28 ++++++++++++++-------------- pyvnt/__init__.py | 2 ++ tests/test_dimm.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 14 deletions(-) create mode 100644 tests/test_dimm.py diff --git a/pyvnt/Reference/dimSet.py b/pyvnt/Reference/dimSet.py index c5b2a3a..b958050 100644 --- a/pyvnt/Reference/dimSet.py +++ b/pyvnt/Reference/dimSet.py @@ -1,4 +1,4 @@ -from enum import IntEnum +from enum import IntEnum, auto from pyvnt.Reference.errorClasses import IncorrectLengthError from pyvnt.Reference.basic import * @@ -31,14 +31,14 @@ class DimmSet(ValueProperty): 7. Luminous Intensity ''' - __slots__ = ['name', 'dimmtype', 'dimm'] + __slots__ = ['_ValueProperty__name', '_DimmSet__dimmtype', '_DimmSet__dimm'] def __init__(self, name, dimms: [] = [0] * 7): super(DimmSet, self).__init__() - self.dimmtype = DimmType - self.dimm = [0] * 7 - self.name = name + self.__dimmtype = DimmType + self.__dimm = [0] * 7 + self._ValueProperty__name = name if len(dimms) == 7: self.setProperties(*dimms) @@ -69,28 +69,28 @@ def setProperties(self, m = 0, l = 0, t = 0, temp = 0, mol = 0, c = 0, li = 0): The dimension of luminous intensity. ''' if m: - self.dimm[DimmType.MASS] = m + self.__dimm[DimmType.MASS - 1] = m if l: - self.dimm[DimmType.LENGTH] = l + self.__dimm[DimmType.LENGTH - 1] = l if t: - self.dimm[DimmType.TIME] = t + self.__dimm[DimmType.TIME - 1] = t if temp: - self.dimm[DimmType.TEMPERATURE] = tmp + self.__dimm[DimmType.TEMPERATURE - 1] = temp if mol: - self.dimm[DimmType.MOLES] = mol + self.__dimm[DimmType.MOLES - 1] = mol if c: - self.dimm[DimmType.CURRENT] = c + self.__dimm[DimmType.CURRENT - 1] = c if li: - self.dimm[DimmType.LUMINOUS_INTENSITY] = li + self.__dimm[DimmType.LUMINOUS_INTENSITY - 1] = li def __repr__(self): - return f"DimmSet({self.dimm})" + return f"DimmSet(name : {self._ValueProperty__name}, dimm : {self.__dimm})" def giveVal(self): ''' Returns the dimensions of the physical quantity. ''' - return self.dimm + return self.__dimm diff --git a/pyvnt/__init__.py b/pyvnt/__init__.py index af6fd89..40809a3 100755 --- a/pyvnt/__init__.py +++ b/pyvnt/__init__.py @@ -1,8 +1,10 @@ from pyvnt.Reference.basic import * from pyvnt.Reference.vector import * from pyvnt.Reference.tensor import * +from pyvnt.Reference.dimSet import DimmSet from pyvnt.DictionaryElement.foamDS import * from pyvnt.DictionaryElement.keyData import * from pyvnt.Converter.Writer.writer import * from pyvnt.utils import * from pyvnt.utils.showTree import * + diff --git a/tests/test_dimm.py b/tests/test_dimm.py new file mode 100644 index 0000000..c1312c8 --- /dev/null +++ b/tests/test_dimm.py @@ -0,0 +1,29 @@ +import pytest + +from pyvnt import * + +class TestDimm: + def setup_method(self, method): + self.dimms = [1, 2, 3, 4, 5, 6, 7] + self.dset = DimmSet('test', self.dimms) + + def teardown_method(self, method): + del self.dset + del self.dimms + + def test_dimm_print(self): + assert str(self.dset) == f"DimmSet(name : test, dimm : {self.dimms})" + + def test_dimm_val(self): + assert self.dset.giveVal() == self.dimms + + def test_dimm_edit(self): + dummy_dimms = [1, 2, 3, 4, 5, 6, 7] + self.dset.setProperties(*dummy_dimms) + assert self.dset.giveVal() == dummy_dimms + + def test_dimm_edit_fail(self): + dummy_dimms = [1, 2, 3, 4, 5, 6, 7, 8] + with pytest.raises(TypeError): + self.dset.setProperties(*dummy_dimms) + From 6c24fea2e46a5443123ae44141b97a69f4c911dd Mon Sep 17 00:00:00 2001 From: ThaHobbyist Date: Mon, 1 Jul 2024 14:49:14 +0530 Subject: [PATCH 3/4] Modified github actions --- .github/workflows/python-testing.yml | 4 ++-- requirements.txt | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 requirements.txt diff --git a/.github/workflows/python-testing.yml b/.github/workflows/python-testing.yml index 1e7670a..819d981 100644 --- a/.github/workflows/python-testing.yml +++ b/.github/workflows/python-testing.yml @@ -16,7 +16,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.9", "3.10", "3.11", "3.12"] + python-version: ["3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v4 @@ -27,7 +27,7 @@ jobs: - name: Install dependencies and build package run: | python -m pip install --upgrade pip - python -m pip install pytest anytree setuptools wheel build + python -m pip install -r requirements.txt python -m build pip install dist/*.whl - name: Test with pytest diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..c768b33 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,13 @@ +anytree==2.12.1 +build==1.2.1 +dataclasses==0.6 +iniconfig==2.0.0 +numpy==1.26.4 +packaging==24.0 +pluggy==1.5.0 +pyproject_hooks==1.1.0 +pytest==8.2.0 +setuptools==69.5.1 +six==1.16.0 +typing==3.7.4.3 +wheel==0.43.0 From d95b5443f46522ce039043f139ec2e63503e684c Mon Sep 17 00:00:00 2001 From: ThaHobbyist Date: Mon, 1 Jul 2024 14:50:52 +0530 Subject: [PATCH 4/4] Modified python versions in testing --- .github/workflows/python-testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-testing.yml b/.github/workflows/python-testing.yml index 819d981..3b457b4 100644 --- a/.github/workflows/python-testing.yml +++ b/.github/workflows/python-testing.yml @@ -16,7 +16,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.10", "3.11", "3.12"] + python-version: ["3.11", "3.12"] steps: - uses: actions/checkout@v4