Skip to content

Commit

Permalink
<Enhancement>[Equality]: <Need equality for PyutInterface>
Browse files Browse the repository at this point in the history
[
In support of hasii2011/pyut#360
]

[#6]
  • Loading branch information
Humberto Sanchez II committed May 30, 2024
1 parent e840bb3 commit 5954633
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/pyutmodelv2/PyutInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,27 @@ def implementors(self, newValue: Implementors):
def addImplementor(self, newClassName: ClassName):
self.implementors.append(newClassName)

def __hash__(self) -> int:
return hash((self.name, self.id))

def __eq__(self, other) -> bool:
"""
Args:
other:
Returns: True if the defined PointNodes are 'functionally' equal
"""
ans: bool = False

if isinstance(other, PyutInterface) is False:
pass
else:
if self.name == other.name and self.id == other.id :
ans = True

return ans

def __repr__(self):

methodsStr = ''
Expand Down
2 changes: 1 addition & 1 deletion src/pyutmodelv2/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__: str = '2.1.5'
__version__: str = '2.1.6'
15 changes: 15 additions & 0 deletions tests/pyutmodelv2/TestPyutInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from unittest import TestSuite
from unittest import main as unitTestMain

from copy import deepcopy

from pyutmodelv2.PyutInterface import PyutInterface

from tests.ProjectTestBase import ProjectTestBase
Expand Down Expand Up @@ -31,6 +33,19 @@ def testInstantiation(self):

self.assertIsNotNone(pyutInterface.implementors, 'Ensure we can access this property')

def testEquality(self):
pyutInterface: PyutInterface = PyutInterface(name='OzzeeInterface')
doppleGanger: PyutInterface = deepcopy(pyutInterface)

self.assertTrue(pyutInterface == doppleGanger, 'Should be the same one')

def testNotEqual(self):

pyutInterface1: PyutInterface = PyutInterface(name='OzzeeInterface')
pyutInterface2: PyutInterface = PyutInterface(name='OzzeeInterface')

self.assertFalse(pyutInterface1 == pyutInterface2, 'IDs should not match')


def suite() -> TestSuite:
import unittest
Expand Down

0 comments on commit 5954633

Please sign in to comment.