diff --git a/dahuffman/huffmancodec.py b/dahuffman/huffmancodec.py index 997fd09..e4c26e0 100644 --- a/dahuffman/huffmancodec.py +++ b/dahuffman/huffmancodec.py @@ -21,17 +21,18 @@ class _EndOfFileSymbol: def __repr__(self) -> str: return "_EOF" + def __eq__(self, other) -> bool: + return other.__class__ == self.__class__ + # Because _EOF will be compared with normal symbols (strings, bytes), - # we have to provide a minimal set of comparison methods. - # We'll make _EOF smaller than the rest (meaning lowest frequency) + # we have to provide a minimal set of comparison methods. We'll make + # _EOF smaller than all values other than itself since there will + # always be 1 and only 1 end of file per file. def __lt__(self, other) -> bool: - return True + return self != other def __gt__(self, other) -> bool: - return False - - def __eq__(self, other) -> bool: - return other.__class__ == self.__class__ + return self == other def __hash__(self) -> int: return hash(self.__class__) diff --git a/tests/test_eof.py b/tests/test_eof.py new file mode 100644 index 0000000..0983a07 --- /dev/null +++ b/tests/test_eof.py @@ -0,0 +1,35 @@ +import pytest + +from dahuffman.huffmancodec import _EOF + + +@pytest.fixture(params=( + b"\0", + b"abc", + "abc", + 0, + 100, + -1000, + False, + True, + None, + [], + (), + {}, + [-100, 0, 10], + (-100, 10)) +) +def to_compare(request): + return request.param + + +class TestEndOfFileSymbol: + + def test_eq(self): + assert _EOF == _EOF + + def test_lt(self, to_compare): + assert _EOF < to_compare + + def test_gt(self, to_compare): + assert to_compare > _EOF