|
| 1 | +import pytest |
| 2 | +from collections import OrderedDict |
| 3 | + |
| 4 | +from ..crunch import crunch |
| 5 | + |
| 6 | + |
| 7 | +@pytest.mark.parametrize("description,uncrunched,crunched", [ |
| 8 | + ['number primitive', 0, [0]], |
| 9 | + ['boolean primitive', True, [True]], |
| 10 | + ['string primitive', "string", ["string"]], |
| 11 | + ['empty array', [], [[]]], |
| 12 | + ['single-item array', [None], [None, [0]]], |
| 13 | + ['multi-primitive all distinct array', [None, 0, True, "string"], [None, 0, True, "string", [0, 1, 2, 3]]], |
| 14 | + ['multi-primitive repeated array', [True, True, True, True], [True, [0, 0, 0, 0]]], |
| 15 | + ['one-level nested array', [[1, 2, 3]], [1, 2, 3, [0, 1, 2], [3]]], |
| 16 | + ['two-level nested array', [[[1, 2, 3]]], [1, 2, 3, [0, 1, 2], [3], [4]]], |
| 17 | + ['empty object', {}, [{}]], |
| 18 | + ['single-item object', {'a': None}, [None, {'a': 0}]], |
| 19 | + [ |
| 20 | + 'multi-item all distinct object', |
| 21 | + OrderedDict([('a', None), ('b', 0), ('c', True), ('d', 'string')]), |
| 22 | + [None, 0, True, "string", {'a': 0, 'b': 1, 'c': 2, 'd': 3}] |
| 23 | + ], |
| 24 | + [ |
| 25 | + 'multi-item repeated object', |
| 26 | + OrderedDict([('a', True), ('b', True), ('c', True), ('d', True)]), |
| 27 | + [True, {'a': 0, 'b': 0, 'c': 0, 'd': 0}] |
| 28 | + ], |
| 29 | + [ |
| 30 | + 'complex array', |
| 31 | + [ |
| 32 | + OrderedDict([('a', True), ('b', [1, 2, 3])]), |
| 33 | + [1, 2, 3] |
| 34 | + ], |
| 35 | + [True, 1, 2, 3, [1, 2, 3], {'a': 0, 'b': 4}, [5, 4]] |
| 36 | + ], |
| 37 | + [ |
| 38 | + 'complex object', |
| 39 | + OrderedDict([ |
| 40 | + ('a', True), |
| 41 | + ('b', [1, 2, 3]), |
| 42 | + ('c', OrderedDict([('a', True), ('b', [1, 2, 3])])) |
| 43 | + ]), |
| 44 | + [True, 1, 2, 3, [1, 2, 3], {'a': 0, 'b': 4}, {'a': 0, 'b': 4, 'c': 5}] |
| 45 | + ], |
| 46 | +]) |
| 47 | +def test_crunch(description, uncrunched, crunched): |
| 48 | + assert crunch(uncrunched) == crunched |
0 commit comments