| Total Complexity | 4 |
| Total Lines | 61 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 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 | @pytest.mark.parametrize('case', [0, None, "", False]) |
||
| 49 | def test_label_converter__value__falsy(case): |
||
| 50 | actual = converters.label_converter(case, delimiter=constants.DEFAULT_NODE_DELIMITER) |
||
| 51 | assert actual == case |
||
| 52 | |||
| 53 | |||
| 54 | def test_encoding(): |
||
| 55 | expected_edge = (("parent_a", "child_a"), ("parent_b", "child_b")) |
||
| 56 | |||
| 57 | edge_id = converters.encode_edge_id(expected_edge) |
||
| 58 | actual_edge = converters.decode_edge_id(edge_id) |
||
| 59 | |||
| 60 | assert actual_edge == expected_edge |
||
| 61 |