From 95c178bf2f69ab221914a35981a70ca35c98ef30 Mon Sep 17 00:00:00 2001 From: Alexis Maya-Isabelle Shuping Date: Mon, 12 Aug 2024 15:08:29 -0500 Subject: [PATCH] Finish tests for Either --- modules/types/Either.py | 10 +++++----- test/types/test_Either.py | 7 +++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/modules/types/Either.py b/modules/types/Either.py index 60af900..76fdb9a 100644 --- a/modules/types/Either.py +++ b/modules/types/Either.py @@ -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 @@ -45,7 +45,7 @@ def val(self) -> B: @warning Raises a TypeError if called on a Left. ''' - ... + ... # pragma: no cover @property @abstractmethod @@ -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]': @@ -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. diff --git a/test/types/test_Either.py b/test/types/test_Either.py index d67e1f1..57d7a11 100644 --- a/test/types/test_Either.py +++ b/test/types/test_Either.py @@ -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}"