add tests for normalizeLocation(extrapolate=True)
These fails at the moment with various division-by-zero errors, fix in follow-up commit.
This commit is contained in:
parent
f66ee05f71
commit
1dea06f66f
@ -31,19 +31,104 @@ def test_normalizeLocation():
|
||||
assert normalizeLocation({"wght": 1001}, axes) == {"wght": 0.0}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"axes, location, expected",
|
||||
[
|
||||
# lower != default != upper
|
||||
({"wght": (100, 400, 900)}, {"wght": 1000}, {"wght": 1.2}),
|
||||
({"wght": (100, 400, 900)}, {"wght": 900}, {"wght": 1.0}),
|
||||
({"wght": (100, 400, 900)}, {"wght": 650}, {"wght": 0.5}),
|
||||
({"wght": (100, 400, 900)}, {"wght": 400}, {"wght": 0.0}),
|
||||
({"wght": (100, 400, 900)}, {"wght": 250}, {"wght": -0.5}),
|
||||
({"wght": (100, 400, 900)}, {"wght": 100}, {"wght": -1.0}),
|
||||
({"wght": (100, 400, 900)}, {"wght": 25}, {"wght": -1.25}),
|
||||
# lower == default != upper
|
||||
(
|
||||
{"wght": (400, 400, 900), "wdth": (100, 100, 150)},
|
||||
{"wght": 1000, "wdth": 200},
|
||||
{"wght": 1.2, "wdth": 2.0},
|
||||
),
|
||||
(
|
||||
{"wght": (400, 400, 900), "wdth": (100, 100, 150)},
|
||||
{"wght": 25, "wdth": 25},
|
||||
{"wght": -0.75, "wdth": -1.5},
|
||||
),
|
||||
# lower != default == upper
|
||||
(
|
||||
{"wght": (100, 400, 400), "wdth": (50, 100, 100)},
|
||||
{"wght": 700, "wdth": 150},
|
||||
{"wght": 1.0, "wdth": 1.0},
|
||||
),
|
||||
(
|
||||
{"wght": (100, 400, 400), "wdth": (50, 100, 100)},
|
||||
{"wght": -50, "wdth": 25},
|
||||
{"wght": -1.5, "wdth": -1.5},
|
||||
),
|
||||
# degenerate case with lower == default == upper, normalized location always 0
|
||||
({"wght": (400, 400, 400)}, {"wght": 100}, {"wght": 0.0}),
|
||||
({"wght": (400, 400, 400)}, {"wght": 400}, {"wght": 0.0}),
|
||||
({"wght": (400, 400, 400)}, {"wght": 700}, {"wght": 0.0}),
|
||||
],
|
||||
)
|
||||
def test_normalizeLocation_extrapolate(axes, location, expected):
|
||||
assert normalizeLocation(location, axes, extrapolate=True) == expected
|
||||
|
||||
|
||||
def test_supportScalar():
|
||||
assert supportScalar({}, {}) == 1.0
|
||||
assert supportScalar({"wght": 0.2}, {}) == 1.0
|
||||
assert supportScalar({"wght": 0.2}, {"wght": (0, 2, 3)}) == 0.1
|
||||
assert supportScalar({"wght": 2.5}, {"wght": (0, 2, 4)}) == 0.75
|
||||
assert supportScalar({"wght": 3}, {"wght": (0, 2, 2)}) == 0.0
|
||||
assert supportScalar({"wght": 3}, {"wght": (0, 2, 2)}, extrapolate=True, axisRanges={"wght": (0, 2)}) == 1.5
|
||||
assert supportScalar({"wght": -1}, {"wght": (0, 2, 2)}, extrapolate=True, axisRanges={"wght": (0, 2)}) == -0.5
|
||||
assert supportScalar({"wght": 3}, {"wght": (0, 1, 2)}, extrapolate=True, axisRanges={"wght": (0, 2)}) == -1.0
|
||||
assert supportScalar({"wght": -1}, {"wght": (0, 1, 2)}, extrapolate=True, axisRanges={"wght": (0, 2)}) == -1.0
|
||||
assert supportScalar({"wght": 2}, {"wght": (0, 0.75, 1)}, extrapolate=True, axisRanges={"wght": (0, 1)}) == -4.0
|
||||
assert (
|
||||
supportScalar(
|
||||
{"wght": 3},
|
||||
{"wght": (0, 2, 2)},
|
||||
extrapolate=True,
|
||||
axisRanges={"wght": (0, 2)},
|
||||
)
|
||||
== 1.5
|
||||
)
|
||||
assert (
|
||||
supportScalar(
|
||||
{"wght": -1},
|
||||
{"wght": (0, 2, 2)},
|
||||
extrapolate=True,
|
||||
axisRanges={"wght": (0, 2)},
|
||||
)
|
||||
== -0.5
|
||||
)
|
||||
assert (
|
||||
supportScalar(
|
||||
{"wght": 3},
|
||||
{"wght": (0, 1, 2)},
|
||||
extrapolate=True,
|
||||
axisRanges={"wght": (0, 2)},
|
||||
)
|
||||
== -1.0
|
||||
)
|
||||
assert (
|
||||
supportScalar(
|
||||
{"wght": -1},
|
||||
{"wght": (0, 1, 2)},
|
||||
extrapolate=True,
|
||||
axisRanges={"wght": (0, 2)},
|
||||
)
|
||||
== -1.0
|
||||
)
|
||||
assert (
|
||||
supportScalar(
|
||||
{"wght": 2},
|
||||
{"wght": (0, 0.75, 1)},
|
||||
extrapolate=True,
|
||||
axisRanges={"wght": (0, 1)},
|
||||
)
|
||||
== -4.0
|
||||
)
|
||||
with pytest.raises(TypeError):
|
||||
supportScalar({"wght": 2}, {"wght": (0, 0.75, 1)}, extrapolate=True, axisRanges=None)
|
||||
supportScalar(
|
||||
{"wght": 2}, {"wght": (0, 0.75, 1)}, extrapolate=True, axisRanges=None
|
||||
)
|
||||
|
||||
|
||||
def test_model_extrapolate():
|
||||
|
Loading…
x
Reference in New Issue
Block a user