Skip to content

Commit

Permalink
Finish tests for Either
Browse files Browse the repository at this point in the history
  • Loading branch information
ashuping committed Aug 12, 2024
1 parent a1efb42 commit 95c178b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 5 additions & 5 deletions modules/types/Either.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Either[A, B](ABC):
def is_right(self) -> bool:
''' Return True if this Either is a Right; otherwise, return False.
'''
...
... # pragma: no cover

@property
@abstractmethod
Expand All @@ -45,7 +45,7 @@ def val(self) -> B:
@warning Raises a TypeError if called on a Left.
'''
...
... # pragma: no cover

@property
@abstractmethod
Expand All @@ -54,7 +54,7 @@ def lval(self) -> B:
@warning Raises a TypeError if called on a Right.
'''
...
... # pragma: no cover

@abstractmethod
def map(self, f: Callable[[B], C]) -> 'Either[A, C]':
Expand All @@ -64,14 +64,14 @@ def map(self, f: Callable[[B], C]) -> 'Either[A, C]':
If it is a Left, do not call `f` and just return a Left() of the
lval.
'''
...
... # pragma: no cover

@abstractmethod
def flat_map(self, f: Callable[[B], 'Either[A, C]']) -> 'Either[A, C]':
''' Similar to Map, except that `f` should convert `B`'s directly into
an `Either`.
'''
...
... # pragma: no cover

def __eq__(self, other) -> bool:
''' Returns True iff both Eithers being compared are the same type (i.e.
Expand Down
7 changes: 7 additions & 0 deletions test/types/test_Either.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ def test_equals():
assert Right(12) != Right("12")

assert Right(12) != Left(12)
assert Left(12) != Right(12)

def test_str():
assert str(Left(12)) == "Left[int](12)"
assert str(Left("test")) == "Left[str](test)"
assert str(Right(12)) == "Right[int](12)"
assert str(Right("test")) == "Right[str](test)"

def test_map_right():
transform = lambda x: f"my {x}"
Expand Down

0 comments on commit 95c178b

Please sign in to comment.