Skip to content

Commit ddc6e11

Browse files
committed
Merge pull request #10 from tacaswell/enh_add_eq
ENH: add `__eq__`
2 parents c4e26a4 + 158ab1f commit ddc6e11

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

cycler.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,17 @@ def __imul__(self, other):
252252
self._right = copy.copy(other)
253253
return self
254254

255+
def __eq__(self, other):
256+
"""
257+
Check equality
258+
"""
259+
if len(self) != len(other):
260+
return False
261+
if self.keys ^ other.keys:
262+
return False
263+
264+
return all(a == b for a, b in zip(self, other))
265+
255266
def __repr__(self):
256267
op_map = {zip: '+', product: '*'}
257268
if self._right is None:

test_cycler.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import six
44
from six.moves import zip, range
55
from cycler import cycler, Cycler
6-
from nose.tools import assert_equal, assert_raises, assert_true
6+
from nose.tools import (assert_equal, assert_not_equal,
7+
assert_raises, assert_true)
78
from itertools import product, cycle
89
from operator import add, iadd, mul, imul
910

@@ -160,3 +161,24 @@ def test_call():
160161
assert_equal(a, b)
161162

162163
assert_equal(j, len(c) * 2)
164+
165+
166+
def _eq_test_helper(a, b, res):
167+
if res:
168+
assert_equal(a, b)
169+
else:
170+
assert_not_equal(a, b)
171+
172+
173+
def test_eq():
174+
a = cycler('c', 'rgb')
175+
b = cycler('c', 'rgb')
176+
yield _eq_test_helper, a, b, True
177+
yield _eq_test_helper, a, b[::-1], False
178+
c = cycler('lw', range(3))
179+
yield _eq_test_helper, a+c, c+a, True
180+
yield _eq_test_helper, a+c, c+b, True
181+
yield _eq_test_helper, a*c, c*a, False
182+
yield _eq_test_helper, a, c, False
183+
d = cycler('c', 'ymk')
184+
yield _eq_test_helper, b, d, False

0 commit comments

Comments
 (0)