Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review uses of Jasmine toBeCloseTo #12273

Open
javagl opened this issue Oct 30, 2024 · 0 comments
Open

Review uses of Jasmine toBeCloseTo #12273

javagl opened this issue Oct 30, 2024 · 0 comments
Labels
cleanup good first issue An opportunity for first time contributors onramping test failure

Comments

@javagl
Copy link
Contributor

javagl commented Oct 30, 2024

Some specs use the Jasmine toBeCloseTo function to check whether an actual value is close to an expected value. The function receives a precision parameter that is documented as "The number of decimal points to check". This is used internally, roughly: as an exponent of 10, to basically "shift" the values into the right range.

Some of the specs seem to assume that this precision parameter is supposed to be an "epsilon". One example (just a random search result) is here, where CesiumMath.EPSILON10 is passed in as the 'precision'. This essentially acts like an epsilon of 0.5 (!). Specifically, a test like

const expected = 0.1;
const actual = 0.3;
const EPSILON10 = 0.0000000001;
expect(actual).toBeCloseTo(expected, EPSILON10);

will pass, which is certainly not expected.

Other places seem to use the precision parameter properly (e.g. with values like 2 or 3).

The Testing Guide recommends to use the (Cesium custom) matcher toEqualEpsilon. I think that in many cases where someone passed in some epsilon to toBeCloseTo, this call can just be replaced with toEqualEpsilon. But where exactly the wrong assumption about that parameter was made has to be reviewed.

@ggetz ggetz added cleanup good first issue An opportunity for first time contributors onramping test failure labels Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup good first issue An opportunity for first time contributors onramping test failure
Projects
None yet
Development

No branches or pull requests

2 participants