|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +import pytest |
| 4 | +from numpy import array_equal |
| 5 | +from pyleecan.Classes.ParamExplorerInterval import ParamExplorerInterval |
| 6 | +from pyleecan.Classes.ParamExplorerSet import ParamExplorerSet |
| 7 | + |
| 8 | +param_test = list() |
| 9 | +param_test.append( |
| 10 | + { |
| 11 | + "obj": ParamExplorerInterval( |
| 12 | + min_value=0, max_value=4, N=5, type_value_gen=0, type_value=0 |
| 13 | + ), |
| 14 | + "value": [0, 1, 2, 3, 4], |
| 15 | + "min": 0, |
| 16 | + "max": 4, |
| 17 | + "N": 5, |
| 18 | + } |
| 19 | +) |
| 20 | +param_test.append( |
| 21 | + { |
| 22 | + "obj": ParamExplorerInterval( |
| 23 | + min_value=0, max_value=4.5, N=3, type_value_gen=0, type_value=0 |
| 24 | + ), |
| 25 | + "value": [0, 2.25, 4.5], |
| 26 | + "min": 0, |
| 27 | + "max": 4.5, |
| 28 | + "N": 3, |
| 29 | + } |
| 30 | +) |
| 31 | +param_test.append( |
| 32 | + { |
| 33 | + "obj": ParamExplorerInterval( |
| 34 | + min_value=0, max_value=4.5, N=3, type_value_gen=0, type_value=1 |
| 35 | + ), |
| 36 | + "value": [0, 2, 4], |
| 37 | + "min": 0, |
| 38 | + "max": 4, |
| 39 | + "N": 3, |
| 40 | + } |
| 41 | +) |
| 42 | +param_test.append( |
| 43 | + { |
| 44 | + "obj": ParamExplorerSet(value=[10, 5, 2, 20]), |
| 45 | + "value": [10, 5, 2, 20], |
| 46 | + "min": 2, |
| 47 | + "max": 20, |
| 48 | + "N": 4, |
| 49 | + } |
| 50 | +) |
| 51 | +param_test.append( |
| 52 | + { |
| 53 | + "obj": ParamExplorerSet(value=["test", "test2"]), |
| 54 | + "value": ["test", "test2"], |
| 55 | + "min": None, |
| 56 | + "max": None, |
| 57 | + "N": 2, |
| 58 | + } |
| 59 | +) |
| 60 | + |
| 61 | + |
| 62 | +@pytest.mark.METHODS |
| 63 | +class Test_ParamExplorer(object): |
| 64 | + @pytest.mark.parametrize("test_dict", param_test) |
| 65 | + def test_get_value(self, test_dict): |
| 66 | + """Check that values are correctly generated""" |
| 67 | + |
| 68 | + obj = test_dict["obj"] |
| 69 | + value = obj.get_value() |
| 70 | + assert array_equal(value, test_dict["value"]) |
| 71 | + |
| 72 | + @pytest.mark.parametrize("test_dict", param_test) |
| 73 | + def test_get_min(self, test_dict): |
| 74 | + """Check that min is correctly returned""" |
| 75 | + |
| 76 | + obj = test_dict["obj"] |
| 77 | + result = obj.get_min() |
| 78 | + assert result == test_dict["min"] |
| 79 | + |
| 80 | + @pytest.mark.parametrize("test_dict", param_test) |
| 81 | + def test_get_max(self, test_dict): |
| 82 | + """Check that max is correctly returned""" |
| 83 | + |
| 84 | + obj = test_dict["obj"] |
| 85 | + result = obj.get_max() |
| 86 | + assert result == test_dict["max"] |
| 87 | + |
| 88 | + @pytest.mark.parametrize("test_dict", param_test) |
| 89 | + def test_get_N(self, test_dict): |
| 90 | + """Check that N is correctly returned""" |
| 91 | + |
| 92 | + obj = test_dict["obj"] |
| 93 | + result = obj.get_N() |
| 94 | + assert result == test_dict["N"] |
0 commit comments