Skip to content

Commit

Permalink
Merge pull request #25 from NOHrD-Waterrower/resistancefix
Browse files Browse the repository at this point in the history
Properly deal with equal low and high calibration values
  • Loading branch information
Niek Haarman committed Nov 27, 2020
2 parents 6aa1418 + f3a4c6b commit 8782124
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Expand Up @@ -9,6 +9,8 @@ internal class ResistanceCalculator(
) {

fun calculateResistance(resistanceMeasurement: ResistanceMeasurement): Resistance {
if (calibration.highValue == calibration.lowValue) return Resistance.from(0f)

return Resistance.from(
(resistanceMeasurement.value - calibration.lowValue.value)
.div((calibration.highValue.value - calibration.lowValue.value).toFloat())
Expand Down
Expand Up @@ -74,4 +74,21 @@ internal class ResistanceCalculatorTest {
/* Then */
expect(result).toBe(Resistance.from(100f))
}

@Test
fun `equal low and high calibration results in 0 resistance`() {
/* Given */
val calculator = ResistanceCalculator(
Calibration(
lowValue = ResistanceMeasurement(100),
highValue = ResistanceMeasurement(100),
)
)

/* When */
val result = calculator.calculateResistance(ResistanceMeasurement(100))

/* Then */
expect(result).toBe(Resistance.from(0f))
}
}

0 comments on commit 8782124

Please sign in to comment.