From 81dbc44e6d7f6227de66224269aa63046c2e719b Mon Sep 17 00:00:00 2001 From: Ian Johnson Date: Mon, 29 Apr 2013 15:16:41 +0100 Subject: Added __ne__ methods to appropriate types. --- src/pypeline/core/types/either.py | 6 ++++++ src/pypeline/core/types/just.py | 3 +++ src/pypeline/core/types/nothing.py | 6 ++++++ src/pypeline/core/types/tests/either_tests.py | 4 ++++ src/pypeline/core/types/tests/just_tests.py | 10 +++++++--- src/pypeline/core/types/tests/nothing_tests.py | 9 ++++++--- 6 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/pypeline/core/types/either.py b/src/pypeline/core/types/either.py index 5b650be..73dd6a6 100644 --- a/src/pypeline/core/types/either.py +++ b/src/pypeline/core/types/either.py @@ -36,6 +36,9 @@ class Left(Either): return False + def __ne__(self, other): + return not self.__eq__(other) + def __repr__(self): return "" % self.val @@ -55,5 +58,8 @@ class Right(Either): return False + def __ne__(self, other): + return not self.__eq__(other) + def __repr__(self): return "" % self.val diff --git a/src/pypeline/core/types/just.py b/src/pypeline/core/types/just.py index 6328c5b..07d3c23 100644 --- a/src/pypeline/core/types/just.py +++ b/src/pypeline/core/types/just.py @@ -51,6 +51,9 @@ class Just(Maybe): return True return False + def __ne__(self, other): + return not self.__eq__(other) + def __hash__(self): return self._a.__hash__() diff --git a/src/pypeline/core/types/nothing.py b/src/pypeline/core/types/nothing.py index aab5df2..9d6e7e2 100644 --- a/src/pypeline/core/types/nothing.py +++ b/src/pypeline/core/types/nothing.py @@ -33,6 +33,12 @@ class Nothing(Maybe): def return_(self, a): return return_(a) + def __eq__(self, other): + return Nothing._instance is other + + def __ne__(self, other): + return not self.__eq__(other) + def __ge__(self, function): return Nothing() diff --git a/src/pypeline/core/types/tests/either_tests.py b/src/pypeline/core/types/tests/either_tests.py index 74b762a..8f59f91 100644 --- a/src/pypeline/core/types/tests/either_tests.py +++ b/src/pypeline/core/types/tests/either_tests.py @@ -25,4 +25,8 @@ class EitherUnitTests(unittest.TestCase): def test_eq(self): self.assertEquals(Left(10), Left(10)) self.assertEquals(Right("something"), Right("something")) + + + def test_ne(self): + self.assertNotEquals(Left(10), Left(11)) self.assertNotEquals(Left(10), Right(10)) diff --git a/src/pypeline/core/types/tests/just_tests.py b/src/pypeline/core/types/tests/just_tests.py index 8d0cf89..0c73b82 100644 --- a/src/pypeline/core/types/tests/just_tests.py +++ b/src/pypeline/core/types/tests/just_tests.py @@ -40,6 +40,10 @@ class JustMonadUnitTest(unittest.TestCase): def test_eq(self): - self.assertTrue(Just(10) == return_(10)) - self.assertFalse(Just(10) == None) - self.assertFalse(Just(10) == object()) + self.assertEquals(Just(10), return_(10)) + + + def test_ne(self): + self.assertNotEquals(Just(11), return_(10)) + self.assertNotEquals(Just(11), None) + self.assertNotEquals(Just(11), object()) diff --git a/src/pypeline/core/types/tests/nothing_tests.py b/src/pypeline/core/types/tests/nothing_tests.py index a350379..ddda8d6 100644 --- a/src/pypeline/core/types/tests/nothing_tests.py +++ b/src/pypeline/core/types/tests/nothing_tests.py @@ -36,6 +36,9 @@ class NothingMonadUnitTest(unittest.TestCase): def test_eq(self): - self.assertTrue(Nothing() == return_("blah")) - self.assertFalse(Nothing() == None) - self.assertFalse(Nothing() == object()) + self.assertEquals(Nothing(), return_("blah")) + + + def test_ne(self): + self.assertNotEquals(Nothing(), None) + self.assertNotEquals(Nothing(), object()) -- cgit v1.2.3