-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
61 lines (40 loc) · 1.25 KB
/
tests.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from typing import Final
from hypothesis import given, strategies as st, assume
from main import Symbol
KEY_NONEXISTENT: Final[str] = "nonexistent"
@given(st.text())
def test_symbols_are_unique(key: str) -> None:
sym1 = Symbol(key)
sym2 = Symbol(key)
assert sym1 != sym2
assert sym1 == sym1
assert sym2 == sym2
@given(st.text())
def test_symbol_str(key: str) -> None:
assert str(Symbol(key)) == key
@given(st.text())
def test_symbol_hash(key: str) -> None:
sym1 = Symbol(key)
sym2 = Symbol(key)
assert hash(sym1) == hash(sym1)
assert hash(sym2) == hash(sym2)
assert hash(sym1) != hash(sym2)
@given(st.text())
def test_symbol_repr(key: str) -> None:
assert repr(Symbol(key)) == f"Symbol({repr(key)})"
def test_symbol_key_for_nonexistent() -> None:
sym = Symbol(KEY_NONEXISTENT)
assert Symbol.key_for(sym) is None
@given(st.text())
def test_key_for(key: str) -> None:
assume(key != KEY_NONEXISTENT)
assert Symbol.key_for(Symbol.for_key(key)) == key
@given(st.text())
def test_symbol_for(key: str) -> None:
assume(key != KEY_NONEXISTENT)
sym1 = Symbol.for_key(key)
sym2 = Symbol.for_key(key)
sym3 = Symbol(key)
assert sym1 == sym2
assert sym1 != sym3
assert sym2 != sym3