|
| 1 | +import pytest |
| 2 | +from coremltools.converters.mil.input_types import RangeDim |
| 3 | + |
| 4 | +def test_rangedim_default_within_bounds(): |
| 5 | + dim = RangeDim(lower_bound=0, upper_bound=10, default=5) |
| 6 | + assert dim.default == 5 |
| 7 | + |
| 8 | +def test_rangedim_default_falls_back_to_lower_bound(): |
| 9 | + dim = RangeDim(lower_bound=1, upper_bound=5) |
| 10 | + assert dim.default == 1 |
| 11 | + |
| 12 | +def test_rangedim_raises_if_default_below_lower(): |
| 13 | + with pytest.raises(ValueError, match=r"less than minimum value"): |
| 14 | + RangeDim(lower_bound=3, upper_bound=10, default=2) |
| 15 | + |
| 16 | +def test_rangedim_raises_if_default_above_upper(): |
| 17 | + with pytest.raises(ValueError, match=r"greater than maximum value"): |
| 18 | + RangeDim(lower_bound=0, upper_bound=5, default=6) |
| 19 | + |
| 20 | +def test_rangedim_ior_merges_bounds_and_adjusts_default(): |
| 21 | + dim1 = RangeDim(lower_bound=0, upper_bound=10, default=5) |
| 22 | + dim2 = RangeDim(lower_bound=2, upper_bound=8, default=3) |
| 23 | + dim1 |= dim2 |
| 24 | + assert dim1.lower_bound == 0 # keep this unless your __ior__ updates it |
| 25 | + assert dim1.upper_bound == 10 # same here unless logic changes |
| 26 | + assert dim1.default >= dim1.lower_bound |
| 27 | + assert dim1.default <= dim1.upper_bound |
0 commit comments