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

mapNumberToRange test fails for value smaller than minimum #302

Closed
thormeier opened this issue Apr 18, 2023 · 0 comments · Fixed by #303
Closed

mapNumberToRange test fails for value smaller than minimum #302

thormeier opened this issue Apr 18, 2023 · 0 comments · Fixed by #303

Comments

@thormeier
Copy link
Contributor

Describe the bug
Test src/utils/mapNumberToRange.spec.ts:28:21 fails locally and expects the value to be 5, but it is actually 7.

To Reproduce
Steps to reproduce the behaviour:

  1. Make sure you're using Node 18
  2. Install dependencies
  3. Execute npm run test
  4. See the error

Expected behaviour
Tests should pass

Desktop (please complete the following information):

  • OS: Arch Linux 5.17
  • Browser: None (Node in a terminal)
  • Version: Node v18.13.0

Additional context
The test tests the behaviour of the mapNumberToRange function with a value smaller than the minimum value with the following code:

const val = -4
const min = 0
const max = 10
const results = mapNumberToRange({ val, min, max })

expect(results).toBe(5)

The function itself does a check if the value is greater than the maximum value (in which case it calculates the value as val: val - (max + 1)) and another check to see if the value is smaller than the minimum value (in which case it calculates the value as val: val + (max + 1)).

Since the calculations for both cases only differ by a singular operation (- max vs + max), it does look sensible, so this might only be a typo or an artefact of an older version of the function. However, I could also imagine the calculation being meant as val: val + (min + 1) instead, which would result in a value of 0 (i.e. the minimum), which sounds less credible to me, given that a value greater than the maximum does not result in the maximum being returned either.

My guess is a typo, or am I missing something?

I'm happy to provide a fix here since I'm also working on a potential fix for #278, which I should be done with soonish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant