|
1
|
|
|
import math |
|
2
|
|
|
|
|
3
|
|
|
import pytest |
|
4
|
|
|
|
|
5
|
|
|
from graphinate import constants, converters |
|
6
|
|
|
|
|
7
|
|
|
base_cases = [ |
|
8
|
|
|
('1', '1'), |
|
9
|
|
|
('1.1', '1.1'), |
|
10
|
|
|
(1, 1), |
|
11
|
|
|
(1.1, 1.1), |
|
12
|
|
|
(0, 0), |
|
13
|
|
|
(True, True) |
|
14
|
|
|
] |
|
15
|
|
|
|
|
16
|
|
|
value_handling_cases = [ |
|
17
|
|
|
*base_cases, |
|
18
|
|
|
('Infinity', math.inf), |
|
19
|
|
|
('-Infinity', -math.inf), |
|
20
|
|
|
('+Infinity', math.inf) |
|
21
|
|
|
] |
|
22
|
|
|
|
|
23
|
|
|
inf_handling_cases = [ |
|
24
|
|
|
*base_cases, |
|
25
|
|
|
(math.inf, 'Infinity'), |
|
26
|
|
|
(-math.inf, '-Infinity') |
|
27
|
|
|
] |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
@pytest.mark.parametrize(('case', 'expected'), value_handling_cases) |
|
31
|
|
|
def test_value_to_infnum(case, expected): |
|
32
|
|
|
# act |
|
33
|
|
|
actual = converters.value_to_infnum(case) |
|
34
|
|
|
|
|
35
|
|
|
# assert |
|
36
|
|
|
assert actual == expected |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
@pytest.mark.parametrize(('case', 'expected'), inf_handling_cases) |
|
40
|
|
|
def test_infnum_to_value(case, expected): |
|
41
|
|
|
# act |
|
42
|
|
|
actual = converters.infnum_to_value(case) |
|
43
|
|
|
|
|
44
|
|
|
# assert |
|
45
|
|
|
assert actual == expected |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
label_converter_cases = [ |
|
49
|
|
|
(None, constants.DEFAULT_NODE_DELIMITER, None), |
|
50
|
|
|
(0, constants.DEFAULT_NODE_DELIMITER, "0"), |
|
51
|
|
|
(False, constants.DEFAULT_NODE_DELIMITER, "False"), |
|
52
|
|
|
("", constants.DEFAULT_NODE_DELIMITER, ""), |
|
53
|
|
|
("hello", constants.DEFAULT_NODE_DELIMITER, "hello"), |
|
54
|
|
|
(123, constants.DEFAULT_NODE_DELIMITER, "123"), |
|
55
|
|
|
(True, constants.DEFAULT_NODE_DELIMITER, "True"), |
|
56
|
|
|
((1, "a", True), "-", "1-a-True"), |
|
57
|
|
|
(("node1", 1), "|", "node1|1"), |
|
58
|
|
|
] |
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
@pytest.mark.parametrize(('case', 'delimiter', 'expected'), label_converter_cases) |
|
62
|
|
|
def test_label_converter(case, delimiter, expected): |
|
63
|
|
|
actual = converters.label_converter(case, delimiter=delimiter) |
|
64
|
|
|
assert actual == expected |
|
65
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
def test_encoding(): |
|
68
|
|
|
expected_edge = (("parent_a", "child_a"), ("parent_b", "child_b")) |
|
69
|
|
|
|
|
70
|
|
|
edge_id = converters.encode_edge_id(expected_edge) |
|
71
|
|
|
actual_edge = converters.decode_edge_id(edge_id) |
|
72
|
|
|
|
|
73
|
|
|
assert actual_edge == expected_edge |
|
74
|
|
|
|