forked from Aunsiels/pyformlang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_symbol.py
42 lines (35 loc) · 1.23 KB
/
test_symbol.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""Tests for the symbols."""
from pyformlang.finite_automaton import State, Symbol
class TestSymbol:
"""Tests for the symbols."""
def test_can_create(self) -> None:
"""Tests the creation of symbols."""
assert Symbol("") is not None
assert Symbol(1) is not None
def test_repr(self) -> None:
"""Tests the representation of symbols."""
symbol1 = Symbol("ABC")
assert str(symbol1) == "ABC"
symbol2 = Symbol(1)
assert str(symbol2) == "1"
assert repr(symbol2) == "Symbol(1)"
def test_eq(self) -> None:
"""Tests equality of symbols."""
symbol1 = Symbol("ABC")
symbol2 = Symbol(1)
symbol3 = Symbol("ABC")
assert symbol1 == symbol3
assert symbol2 == 1
assert symbol2 != symbol3
assert symbol1 != symbol2
assert "A" == Symbol("A")
assert State("A") != Symbol("A")
def test_hash(self) -> None:
"""Tests the hashing of symbols."""
symbol1 = hash(Symbol("ABC"))
symbol2 = hash(Symbol(1))
symbol3 = hash(Symbol("ABC"))
assert isinstance(symbol1, int)
assert symbol1 == symbol3
assert symbol2 != symbol3
assert symbol1 != symbol2