提交 780536f2 authored 作者: notoraptor's avatar notoraptor

Small additions:

- test `!=` operator on Wrap and Wrapper - remove useless condition in `Wrap.__eq__`.
上级 1a2ef20a
...@@ -104,6 +104,7 @@ class TestWrapper(TestCase): ...@@ -104,6 +104,7 @@ class TestWrapper(TestCase):
w1 = Wrap(a=1, b='test string', array=numpy.asarray([1, 2, 4, 5, 7]), floatting=-4.5, npy_scalar=numpy.asarray(12)) w1 = Wrap(a=1, b='test string', array=numpy.asarray([1, 2, 4, 5, 7]), floatting=-4.5, npy_scalar=numpy.asarray(12))
w2 = Wrap(a=1, b='test string', array=numpy.asarray([1, 2, 4, 5, 7]), floatting=-4.5, npy_scalar=numpy.asarray(12)) w2 = Wrap(a=1, b='test string', array=numpy.asarray([1, 2, 4, 5, 7]), floatting=-4.5, npy_scalar=numpy.asarray(12))
assert w1 == w2 assert w1 == w2
assert not (w1 != w2)
assert hash(w1) == hash(w2) assert hash(w1) == hash(w2)
assert all(hasattr(w1, key) for key in ('a', 'b', 'array', 'floatting', 'npy_scalar')) assert all(hasattr(w1, key) for key in ('a', 'b', 'array', 'floatting', 'npy_scalar'))
# Changing attributes names only. # Changing attributes names only.
...@@ -127,6 +128,7 @@ class TestWrapper(TestCase): ...@@ -127,6 +128,7 @@ class TestWrapper(TestCase):
a2=TensorType('int64', (False, True, False, False, True)), a2=TensorType('int64', (False, True, False, False, True)),
a3=Generic()) a3=Generic())
assert w1 == w2 assert w1 == w2
assert not (w1 != w2)
assert hash(w1) == hash(w2) assert hash(w1) == hash(w2)
assert w1.name == w2.name assert w1.name == w2.name
# Changing attributes names only. # Changing attributes names only.
......
...@@ -103,7 +103,7 @@ class Wrap(dict): ...@@ -103,7 +103,7 @@ class Wrap(dict):
for k in self: for k in self:
if k not in other or not (isinstance(self[k], type(other[k])) and isinstance(other[k], type(self[k]))): if k not in other or not (isinstance(self[k], type(other[k])) and isinstance(other[k], type(self[k]))):
return False return False
if isinstance(self[k], numpy.ndarray) or isinstance(other[k], numpy.ndarray): if isinstance(self[k], numpy.ndarray):
if not numpy.allclose(self[k], other[k]): if not numpy.allclose(self[k], other[k]):
return False return False
elif self[k] != other[k]: elif self[k] != other[k]:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论