Skip to content

Commit

Permalink
Fix flaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
karimnaaji committed Sep 1, 2022
1 parent 825bd2b commit fbb80cd
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions test/unit/terrain/terrain.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ const createGradientDEM = () => {
return new DEMData(0, new RGBAImage({height: TILE_SIZE + 2, width: TILE_SIZE + 2}, pixels), "mapbox", false, true);
};

function nearlyEquals(a, b, eps = 0.000000001) {
return Object.keys(a).length >= 2 && Object.keys(a).every(key => Math.abs(a[key] - b[key]) < eps);
}

const createNegativeGradientDEM = () => {
const pixels = new Uint8Array((TILE_SIZE + 2) * (TILE_SIZE + 2) * 4);
// 1, 134, 160 encodes 0m.
Expand Down Expand Up @@ -374,19 +378,19 @@ test('Elevation', (t) => {
changed = map._updateAverageElevation(timestamp);
t.true(changed);
t.true(map._averageElevation.isEasing(timestamp));
t.equal(map.transform.averageElevation, 154.15083854452925);
t.ok(nearlyEquals(map.transform.averageElevation, 154.15083854452925));

timestamp += AVERAGE_ELEVATION_EASE_TIME * 0.5;
changed = map._updateAverageElevation(timestamp);
t.true(changed);
t.true(map._averageElevation.isEasing(timestamp));
t.equal(map.transform.averageElevation, 308.3016770890585);
t.ok(nearlyEquals(map.transform.averageElevation, 308.3016770890585));

timestamp += AVERAGE_ELEVATION_SAMPLING_INTERVAL;
changed = map._updateAverageElevation(timestamp);
t.false(changed);
t.false(map._averageElevation.isEasing(timestamp));
t.equal(map.transform.averageElevation, 308.3016770890585);
t.ok(nearlyEquals(map.transform.averageElevation, 308.3016770890585));

t.end();
});
Expand Down Expand Up @@ -683,10 +687,6 @@ test('Terrain style', (t) => {
t.end();
});

function nearlyEquals(a, b, eps = 0.000000001) {
return Object.keys(a).length >= 2 && Object.keys(a).every(key => Math.abs(a[key] - b[key]) < eps);
}

test('Raycast projection 2D/3D', t => {
const map = createMap(t, {
style: {
Expand Down

0 comments on commit fbb80cd

Please sign in to comment.