Skip to content

Commit

Permalink
fix: fixing tests and circular dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
eturino committed Jul 29, 2021
1 parent 159004d commit 2324136
Show file tree
Hide file tree
Showing 12 changed files with 189 additions and 158 deletions.
23 changes: 0 additions & 23 deletions key_set/all.py

This file was deleted.

30 changes: 0 additions & 30 deletions key_set/all_except_some.py

This file was deleted.

94 changes: 93 additions & 1 deletion key_set/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations
from abc import ABC, abstractmethod

# abc is a builtin module, we have to import ABC and abstractmethod
from key_set.enum import KeySetType
from .enum import KeySetType


class KeySet(ABC): # Inherit from ABC(Abstract base class)
Expand Down Expand Up @@ -44,3 +45,94 @@ def invert(self):
Some <-> AllExceptSome
"""
pass


class KeySetAll(KeySet):
"""Represents the ALL sets: 𝕌 (the entirety of possible keys)."""

def key_set_type(self) -> KeySetType:
"""Returns the KeySetType that describes the set."""
return KeySetType.ALL

def elements(self) -> set[str]:
"""Returns an empty set."""
return set()

def represents_all(self) -> bool:
"""Returns true if the set is a ALL KeySet."""
return True

def invert(self) -> KeySetNone:
"""Returns a new KeySet NONE."""
return KeySetNone()


class KeySetNone(KeySet):
"""Represents the NONE sets: ø (empty set)."""

def key_set_type(self) -> KeySetType:
"""Returns the KeySetType that describes the set."""
return KeySetType.NONE

def elements(self) -> set[str]:
"""Returns an empty set."""
return set()

def represents_none(self) -> bool:
"""Returns true if the set is a NONE KeySet."""
return True

def invert(self) -> KeySetAll:
"""Returns a new KeySet ALL."""
return KeySetAll()


class KeySetSome(KeySet):
"""Represents the SOME sets: a concrete set (`A ⊂ 𝕌`)."""

def __init__(self, elements: set[str]):
"""Requires the set of elements of the concrete set."""
self._elements = set(elements)

def key_set_type(self) -> KeySetType:
"""Returns the KeySetType that describes the set."""
return KeySetType.SOME

def elements(self) -> set[str]:
"""Returns a copy of the set of the elements of the concrete set."""
return set(self._elements)

def represents_some(self) -> bool:
"""Returns true if the set is a SOME KeySet."""
return True

def invert(self) -> KeySetAllExceptSome:
"""Returns a new KeySet ALL_EXCEPT_SOME."""
return KeySetAllExceptSome(self.elements())


class KeySetAllExceptSome(KeySet):
"""Represents the ALL_EXCEPT_SOME sets: the complementary of a concrete set.
Includes all the elements except the given ones (`A' = {x ∈ 𝕌 | x ∉ A}`).
"""

def __init__(self, elements: set[str]):
"""Requires the set of elements of the concrete set."""
self._elements = set(elements)

def key_set_type(self) -> KeySetType:
"""Returns the KeySetType that describes the set."""
return KeySetType.ALL_EXCEPT_SOME

def elements(self) -> set[str]:
"""Returns a copy of the set of the elements of the concrete set."""
return set(self._elements)

def represents_all_except_some(self) -> bool:
"""Returns true if the set is a ALL_EXCEPT_SOME KeySet."""
return True

def invert(self) -> KeySetSome:
"""Returns a new KeySet SOME."""
return KeySetSome(self.elements())
23 changes: 0 additions & 23 deletions key_set/none.py

This file was deleted.

27 changes: 0 additions & 27 deletions key_set/some.py

This file was deleted.

14 changes: 0 additions & 14 deletions key_set/utils.py

This file was deleted.

23 changes: 23 additions & 0 deletions tests/test_all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
import __future__ # noqa: F401

from key_set.base import KeySetAll


class TestAll: # noqa: D101

def test_represents(self) -> None:
ks = KeySetAll()
assert ks.represents_all()
assert not ks.represents_none()
assert not ks.represents_some()
assert not ks.represents_all_except_some()

def test_invert(self) -> None:
ks = KeySetAll()
actual = ks.invert()
assert actual.represents_none()

def test_elements(self) -> None:
ks = KeySetAll()
assert ks.elements() == set()
24 changes: 24 additions & 0 deletions tests/test_all_except_some.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
import __future__ # noqa: F401

from key_set.base import KeySetAllExceptSome


class TestAllExceptSome: # noqa: D101

def test_represents(self) -> None:
ks = KeySetAllExceptSome({'a', 'b'})
assert ks.represents_all_except_some()
assert not ks.represents_none()
assert not ks.represents_all()
assert not ks.represents_some()

def test_invert(self) -> None:
ks = KeySetAllExceptSome({'a', 'b'})
actual = ks.invert()
assert actual.represents_some()
assert actual.elements() == {'a', 'b'}

def test_elements(self) -> None:
ks = KeySetAllExceptSome({'a', 'b'})
assert ks.elements() == {'a', 'b'}
5 changes: 1 addition & 4 deletions tests/test_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
import __future__ # noqa: F401

import key_set # noqa: F401
from key_set.all import KeySetAll
from key_set.all_except_some import KeySetAllExceptSome
from key_set.none import KeySetNone
from key_set.some import KeySetSome
from key_set.base import KeySetAll, KeySetNone, KeySetSome, KeySetAllExceptSome


class TestElements: # noqa: D101
Expand Down
23 changes: 23 additions & 0 deletions tests/test_none.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
import __future__ # noqa: F401

from key_set.base import KeySetNone


class TestNone: # noqa: D101

def test_represents(self) -> None:
ks = KeySetNone()
assert ks.represents_none()
assert not ks.represents_all()
assert not ks.represents_some()
assert not ks.represents_all_except_some()

def test_invert(self) -> None:
ks = KeySetNone()
actual = ks.invert()
assert actual.represents_all()

def test_elements(self) -> None:
ks = KeySetNone()
assert ks.elements() == set()
25 changes: 25 additions & 0 deletions tests/test_some.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
import __future__ # noqa: F401

import key_set # noqa: F401
from key_set.base import KeySetSome


class TestSome: # noqa: D101

def test_represents(self) -> None:
ks = KeySetSome({'a', 'b'})
assert ks.represents_some()
assert not ks.represents_none()
assert not ks.represents_all()
assert not ks.represents_all_except_some()

def test_invert(self) -> None:
ks = KeySetSome({'a', 'b'})
actual = ks.invert()
assert actual.represents_all_except_some()
assert actual.elements() == {'a', 'b'}

def test_elements(self) -> None:
ks = KeySetSome({'a', 'b'})
assert ks.elements() == {'a', 'b'}
36 changes: 0 additions & 36 deletions tests/test_utils.py

This file was deleted.

0 comments on commit 2324136

Please sign in to comment.