Coverage for src/abcd_graph/graph/core/abcd_objects/abstract.py: 100%

1 import abc

2

3 from abcd_graph.graph.core.abcd_objects.edge import Edge

4

5

6 class AbstractGraph(abc.ABC):

7 @property

8 @abc.abstractmethod

9 def adj_dict(self) -> dict[Edge, int]: ...

10

11

12 class AbstractCommunity(AbstractGraph):

13 def __init__(self, edges: list[Edge], community_id: int) -> None:

14 self.community_id = community_id

15 self._adj_dict: dict[Edge, int] = {}

16 self._bad_edges: list[Edge] = []

17

18 self._diagnostics = {

19 "num_loops": 0,

20 "num_multi_edges": 0,

21 }

22

23 for edge in edges:

24 if edge.is_loop:

25 self._bad_edges.append(edge)

26 self._diagnostics["num_loops"] += 1

27

28 if edge in self.adj_dict:

29 self._bad_edges.append(edge)

30 self._adj_dict[edge] += 1

31 self._diagnostics["num_multi_edges"] += 1

32 else:

33 self._adj_dict[edge] = 1

34

35 self._edges = edges

36

37 @property

38 def edges(self) -> list[Edge]:

39 return self._edges

40

41 @property

42 def adj_dict(self) -> dict[Edge, int]:

43 return self._adj_dict

44

45 @property

46 def diagnostics(self) -> dict[str, int]:

47 return self._diagnostics