Skip to content

Commit 81579e4

Browse files
committed
add tests
1 parent 6918d87 commit 81579e4

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { expect } from '@open-wc/testing';
2+
import { getInterpolatedIndexOfPositionInWeightMap } from './math.js';
3+
4+
describe('getInterpolatedIndexOfPositionInWeightMap', () => {
5+
it('should return the interpolated index of a value in a weight map', () => {
6+
const weights = [10, 20, 30, 40, 50];
7+
expect(getInterpolatedIndexOfPositionInWeightMap(-10, weights)).to.equal(0);
8+
expect(getInterpolatedIndexOfPositionInWeightMap(0, weights)).to.equal(0);
9+
expect(getInterpolatedIndexOfPositionInWeightMap(5, weights)).to.equal(0.5);
10+
expect(getInterpolatedIndexOfPositionInWeightMap(15, weights)).to.equal(1.25);
11+
expect(getInterpolatedIndexOfPositionInWeightMap(35, weights)).to.equal(2.1666666666666665);
12+
expect(getInterpolatedIndexOfPositionInWeightMap(45, weights)).to.equal(2.5);
13+
expect(getInterpolatedIndexOfPositionInWeightMap(50, weights)).to.equal(2.6666666666666665);
14+
expect(getInterpolatedIndexOfPositionInWeightMap(60, weights)).to.equal(3);
15+
expect(getInterpolatedIndexOfPositionInWeightMap(100, weights)).to.equal(4);
16+
expect(getInterpolatedIndexOfPositionInWeightMap(5000, weights)).to.equal(5);
17+
});
18+
});

0 commit comments

Comments
 (0)