Added in a mixin module with an Equality class for mixin use

This commit is contained in:
Adam Nelson 2016-08-17 05:07:29 -04:00
parent 8f760afa70
commit f886d2849e

24
openmc/mixin.py Normal file
View file

@ -0,0 +1,24 @@
import numpy as np
class Equality(object):
"""A Class which provides generic __eq__ and __ne__ functionality which
can easily be inherited by downstream classes.
"""
def __eq__(self, other):
eqval = True
if isinstance(other, type(self)):
for key, value in self.__dict__.items():
if key in other.__dict__:
if not np.array_equal(value, other.__dict__.get(key)):
eqval = False
else:
eqval = False
else:
eqval = False
return eqval
def __ne__(self, other):
return not self.__eq__(other)