From 716db54bc4787997f769db069de17a22fe6c9ac5 Mon Sep 17 00:00:00 2001 From: ThaHobbyist Date: Fri, 7 Jun 2024 18:11:52 +0530 Subject: [PATCH] Added writeOut and giveVal methods in vector data type --- manual_tests/test_pyvnt.py | 4 ++-- pyvnt/Reference/vector.py | 15 +++++++++++++++ testFile.txt | 17 ----------------- tests/test_vector.py | 6 +++++- 4 files changed, 22 insertions(+), 20 deletions(-) delete mode 100644 testFile.txt diff --git a/manual_tests/test_pyvnt.py b/manual_tests/test_pyvnt.py index f54e1d7..30945d9 100755 --- a/manual_tests/test_pyvnt.py +++ b/manual_tests/test_pyvnt.py @@ -11,7 +11,7 @@ # test for KeyData and Foam classes key1 = KeyData('solver', prop1, prop2) -print(key1.giveVal()) +# print(key1.giveVal()) head = Foam("test_head",None, None) # head.appendDict(args) @@ -33,7 +33,7 @@ # key1 = KeyData('solver', prop1) # print(key1) -writeTo(head, 'testFile.txt') +# writeTo(head, 'testFile.txt') diff --git a/pyvnt/Reference/vector.py b/pyvnt/Reference/vector.py index 05eb36f..8544c32 100644 --- a/pyvnt/Reference/vector.py +++ b/pyvnt/Reference/vector.py @@ -84,5 +84,20 @@ def normalise(self, tol: PropertyFloat) -> Self: self.setProperties(self._ValueProperty__name, PropertyFloat(self._ValueProperty__name + "_x", self.__x.giveVal()/s), PropertyFloat(self._ValueProperty__name + "_y", self.__y.giveVal()/s), PropertyFloat(self._ValueProperty__name + "_z", self.__z.giveVal()/s)) return self + def giveVal(self): + ''' + Returns the vector value + ''' + + res = (self.__x.giveVal(), self.__y.giveVal(), self.__z.giveVal()) + + return res + + def writeOut(self, file): + ''' + Returns the vector value in a string format + ''' + file.write( f"({self.__x.giveVal()} {self.__y.giveVal()} {self.__z.giveVal()})") + def __repr__(self): return f"PropertyVector(name = {self._ValueProperty__name}, x = {self.__x.giveVal()}, y = {self.__y.giveVal()}, z = {self.__z.giveVal()})" \ No newline at end of file diff --git a/testFile.txt b/testFile.txt deleted file mode 100644 index 5b57149..0000000 --- a/testFile.txt +++ /dev/null @@ -1,17 +0,0 @@ -test_head -{ - test_child - { - test_child2 - { - solver PCG PBiCG; - } - - test_child3 - { - solver PCG PBiCG; - } - - } - -} diff --git a/tests/test_vector.py b/tests/test_vector.py index 3064377..fd93507 100644 --- a/tests/test_vector.py +++ b/tests/test_vector.py @@ -49,4 +49,8 @@ def test_vector_normalise(self): self.vprop1.normalise(PropertyFloat('tol', 0.1)) assert self.vprop1.x() == 1/14**0.5 assert self.vprop1.y() == 2/14**0.5 - assert self.vprop1.z() == 3/14**0.5 \ No newline at end of file + assert self.vprop1.z() == 3/14**0.5 + + def test_vector_giveVal(self): + assert self.vprop1.giveVal() == (1, 2, 3) + assert self.vprop2.giveVal() == (4, 5, 6)