-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from FOSSEE/dimUnits
Dimensional Units
- Loading branch information
Showing
7 changed files
with
151 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,8 @@ env | |
build/ | ||
dist/ | ||
pyvnt.egg-info | ||
manual_tests/* | ||
manual_tests/ | ||
manual_debug/ | ||
**/__pycache__/* | ||
.vscode | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 * | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|