ismail9k / vue3-carousel

Vue 3 carousel component
https://ismail9k.github.io/vue3-carousel/
MIT License
660 stars 164 forks source link

mapNumberToRange test fails for value smaller than minimum #302

Closed thormeier closed 1 year ago

thormeier commented 1 year ago

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):

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 https://github.com/ismail9k/vue3-carousel/issues/278, which I should be done with soonish.