Skip to content

Commit

Permalink
chore: add tolerance to tests comparison (#810)
Browse files Browse the repository at this point in the history
## 🔧 Problem

We have differences in results between local computer and server-ci.
Maybe because of processor architecture (arm64 vs x86).
As a results tests are failing either in local or on server-ci

![image](https://github.com/user-attachments/assets/81b2c57d-a48b-43f8-a73c-30f75b5916a3)


## 🍰 Solution

As a temporary fix, allow more tolerance in tests floating points
comparison. Going from 1e-16 toleranc to 1e-12 seems reasonable and fix
my tests.


## 🏝️ How to test
  • Loading branch information
paulboosz authored Oct 21, 2024
1 parent 0402b55 commit 66f0562
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tests/Data/Food/RecipeTest.elm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ expectImpactEqual expectedImpactUnit =
Unit.impactToFloat expectedImpactUnit
in
Unit.impactToFloat
>> Expect.within (Expect.Relative 0.0000000000000001) expectedImpact
>> Expect.within (Expect.Relative 0.000000000001) expectedImpact


suite : Test
Expand Down
11 changes: 9 additions & 2 deletions tests/server.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,15 @@ describe("API", () => {
scoring: response.status === 200 ? response.body.results.scoring : {},
});
expectStatus(response, 200);
expect(response.body.results.total).toEqual(impacts);
expect(response.body.results.scoring).toEqual(scoring);

// Add tolerance check for impacts
Object.entries(impacts).forEach(([key, value]) => {
expect(response.body.results.total[key]).toBeCloseTo(value, 12);
});

Object.entries(scoring).forEach(([key, value]) => {
expect(response.body.results.scoring[key]).toBeCloseTo(value, 12);
});
});
}
});
Expand Down

0 comments on commit 66f0562

Please sign in to comment.