Skip to content

Commit

Permalink
Merge pull request #6 from FOSSEE/dimUnits
Browse files Browse the repository at this point in the history
Dimensional Units
  • Loading branch information
ThaHobbyist authored Jul 1, 2024
2 parents f749511 + d95b544 commit 710165f
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/python-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: ["3.11", "3.12"]

steps:
- uses: actions/checkout@v4
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ env
build/
dist/
pyvnt.egg-info
manual_tests/*
manual_tests/
manual_debug/
**/__pycache__/*
.vscode

Expand Down
96 changes: 96 additions & 0 deletions pyvnt/Reference/dimSet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
from enum import IntEnum, auto
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__ = ['_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._ValueProperty__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 - 1] = m
if l:
self.__dimm[DimmType.LENGTH - 1] = l
if t:
self.__dimm[DimmType.TIME - 1] = t
if temp:
self.__dimm[DimmType.TEMPERATURE - 1] = temp
if mol:
self.__dimm[DimmType.MOLES - 1] = mol
if c:
self.__dimm[DimmType.CURRENT - 1] = c
if li:
self.__dimm[DimmType.LUMINOUS_INTENSITY - 1] = li

def __repr__(self):
return f"DimmSet(name : {self._ValueProperty__name}, dimm : {self.__dimm})"

def giveVal(self):
'''
Returns the dimensions of the physical quantity.
'''

return self.__dimm


7 changes: 7 additions & 0 deletions pyvnt/Reference/errorClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"


2 changes: 2 additions & 0 deletions pyvnt/__init__.py
Original file line number Diff line number Diff line change
@@ -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 *

13 changes: 13 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions tests/test_dimm.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 710165f

Please sign in to comment.