From b70be91fdd3f1579bc37a6371bd5b58145777601 Mon Sep 17 00:00:00 2001 From: Just van Rossum Date: Sun, 17 Sep 2023 17:30:15 +0200 Subject: [PATCH] Light test of getSourceContributions --- test-js/test-var-model.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test-js/test-var-model.js b/test-js/test-var-model.js index 3d3a23e39..0524b71fa 100644 --- a/test-js/test-var-model.js +++ b/test-js/test-var-model.js @@ -12,6 +12,7 @@ import { piecewiseLinearMap, supportScalar, } from "../src/fontra/client/core/var-model.js"; +import { parametrize } from "./test-support.js"; describe("var-model tests", () => { describe("VariationModel tests", () => { @@ -341,4 +342,25 @@ describe("var-model tests", () => { expect(mapBackward(location, axes)).to.deep.equal({ weight: 10, width: 100 }); }); }); + + describe("getSourceContributions tests", () => { + const locations = [{}, { wght: 1 }, { wdth: 1 }]; + const model = new VariationModel(locations, ["wght", "wdth"]); + parametrize( + "test contrib", + [ + { location: { wght: 0, wdth: 0 }, result: [1, 0, 0] }, + { location: { wght: 0.5, wdth: 0 }, result: [0.5, 0.5, 0] }, + { location: { wght: 1, wdth: 0 }, result: [0, 1, 0] }, + { location: { wght: 0, wdth: 0.5 }, result: [0.5, 0, 0.5] }, + { location: { wght: 0, wdth: 1 }, result: [0, 0, 1] }, + { location: { wght: 1, wdth: 1 }, result: [-1, 1, 1] }, + ], + (testData) => { + expect(model.getSourceContributions(testData.location)).to.deep.equal( + testData.result + ); + } + ); + }); });