|
| 1 | +# Copyright 2020 MONAI Consortium |
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | +# you may not use this file except in compliance with the License. |
| 4 | +# You may obtain a copy of the License at |
| 5 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +# Unless required by applicable law or agreed to in writing, software |
| 7 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 8 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 9 | +# See the License for the specific language governing permissions and |
| 10 | +# limitations under the License. |
| 11 | + |
| 12 | +import unittest |
| 13 | + |
| 14 | +from parameterized import parameterized |
| 15 | + |
| 16 | +from monai.utils import list_to_dict |
| 17 | + |
| 18 | +TEST_CASE_1 = [ |
| 19 | + ["a=1", "b=2", "c=3", "d=4"], |
| 20 | + {"a": 1, "b": 2, "c": 3, "d": 4}, |
| 21 | +] |
| 22 | + |
| 23 | +TEST_CASE_2 = [ |
| 24 | + ["a=a", "b=b", "c=c", "d=d"], |
| 25 | + {"a": "a", "b": "b", "c": "c", "d": "d"}, |
| 26 | +] |
| 27 | + |
| 28 | +TEST_CASE_3 = [ |
| 29 | + ["a=0.1", "b=0.2", "c=0.3", "d=0.4"], |
| 30 | + {"a": 0.1, "b": 0.2, "c": 0.3, "d": 0.4}, |
| 31 | +] |
| 32 | + |
| 33 | +TEST_CASE_4 = [ |
| 34 | + ["a=True", "b=TRUE", "c=false", "d=FALSE"], |
| 35 | + {"a": True, "b": True, "c": False, "d": False}, |
| 36 | +] |
| 37 | + |
| 38 | +TEST_CASE_5 = [ |
| 39 | + ["a='1'", "b=2 ", " c = 3", "d='test'", "'e'=0", "f", "g=None"], |
| 40 | + {"a": 1, "b": 2, "c": 3, "d": "test", "e": 0, "f": None, "g": None}, |
| 41 | +] |
| 42 | + |
| 43 | + |
| 44 | +class TestListToDict(unittest.TestCase): |
| 45 | + @parameterized.expand([TEST_CASE_1, TEST_CASE_2, TEST_CASE_3, TEST_CASE_4, TEST_CASE_5]) |
| 46 | + def test_value_shape(self, input, output): |
| 47 | + result = list_to_dict(input) |
| 48 | + self.assertDictEqual(result, output) |
| 49 | + |
| 50 | + |
| 51 | +if __name__ == "__main__": |
| 52 | + unittest.main() |
0 commit comments