|
1
|
|
|
import dataclasses |
|
2
|
|
|
import math |
|
3
|
|
|
|
|
4
|
|
|
import pytest |
|
5
|
|
|
|
|
6
|
|
|
import graphinate.tools.mutators |
|
7
|
|
|
from graphinate.tools import converters |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
@dataclasses.dataclass |
|
11
|
|
|
class Data: |
|
12
|
|
|
a: int |
|
13
|
|
|
b: str |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
data = Data(1, 'alpha') |
|
17
|
|
|
|
|
18
|
|
|
dictify_cases = [ |
|
19
|
|
|
([0.5, 0.5, 0.5], [0.5, 0.5, 0.5]), |
|
20
|
|
|
({'a': 1, 'b': 2}, {'a': 1, 'b': 2}), |
|
21
|
|
|
((1, 2, 3, 4, 'a'), [1, 2, 3, 4, 'a']), |
|
22
|
|
|
(data, {'a': 1, 'b': 'alpha'}) |
|
23
|
|
|
] |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
@pytest.mark.parametrize(('case', 'expected'), dictify_cases) |
|
27
|
|
|
def test_dictify(case, expected): |
|
28
|
|
|
actual = graphinate.tools.mutators.dictify(case) |
|
29
|
|
|
assert actual == expected |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
dictify_value_as_str_cases = [ |
|
33
|
|
|
([0.5, 0.5, 0.5], ['0.5', '0.5', '0.5']), |
|
34
|
|
|
({'a': 1, 'b': 2}, {'a': '1', 'b': '2'}), |
|
35
|
|
|
((1, 2, 3, 4, 'a'), ['1', '2', '3', '4', 'a']), |
|
36
|
|
|
(data, {'a': '1', 'b': 'alpha'}) |
|
37
|
|
|
] |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
@pytest.mark.parametrize(('case', 'expected'), dictify_value_as_str_cases) |
|
41
|
|
|
def test_dictify__value_to_str(case, expected): |
|
42
|
|
|
actual = graphinate.tools.mutators.dictify(case, value_converter=str) |
|
43
|
|
|
assert actual == expected |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
@pytest.mark.parametrize(('case', 'expected'), |
|
47
|
|
|
[('1', '1'), ('1.1', '1.1'), (1, 1), (1.1, 1.1), (0, 0), (True, True), ('Infinity', math.inf), |
|
48
|
|
|
('-Infinity', -math.inf), ('+Infinity', math.inf)]) |
|
49
|
|
|
def test_value_to_infnum(case, expected): |
|
50
|
|
|
# act |
|
51
|
|
|
actual = converters.value_to_infnum(case) |
|
52
|
|
|
|
|
53
|
|
|
# assert |
|
54
|
|
|
assert actual == expected |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
@pytest.mark.parametrize(('case', 'expected'), |
|
58
|
|
|
[('1', '1'), ('1.1', '1.1'), (1, 1), (1.1, 1.1), (0, 0), (True, True), (math.inf, 'Infinity'), |
|
59
|
|
|
(-math.inf, '-Infinity')]) |
|
60
|
|
|
def test_infnum_to_value(case, expected): |
|
61
|
|
|
# act |
|
62
|
|
|
actual = converters.infnum_to_value(case) |
|
63
|
|
|
|
|
64
|
|
|
# assert |
|
65
|
|
|
assert actual == expected |
|
66
|
|
|
|