Coverage for src/abcd_graph/graph/core/abcd_objects/edge.py: 95%

1 __all__ = ["Edge"]

2

3 from dataclasses import dataclass

4 from typing import Any

5

6

7@dataclass

8 class Edge:

9 __slots__ = ["v1", "v2"]

10

11 v1: int

12 v2: int

13

14 def __post_init__(self) -> None:

15 self.to_ordered()

16

17 def __eq__(self, other: Any) -> bool:

18 if not isinstance(other, Edge):

19 return NotImplemented

20 return self.v1 == other.v1 and self.v2 == other.v2

21

22 def __hash__(self) -> int:

23 return hash((self.v1, self.v2))

24

25 def to_ordered(self) -> None:

26 if self.v1 < self.v2:

27 self.v1, self.v2 = self.v2, self.v1

28

29 @property

30 def is_loop(self) -> bool:

31 return self.v1 == self.v2