Title
k

KotlinLeaner

03/06/2023, 4:59 PM
Hi guys, just general knowledge question about test case. How may test should case will be used in this piece of code
``````internal fun checkRange(valueOne: Int, valueTwo: Int): Boolean {
val rangeInValueOne = 0..10
val rangeInValueTwo = 20..30
return (valueOne in rangeInValueOne && valueTwo in rangeInValueTwo)
}``````
?
I think 4 will be good?
If we go truth table
``````rangeInValueOne = true
rangeInValueTwo = true

rangeInValueOne = false
rangeInValueTwo = false

rangeInValueOne = false
rangeInValueTwo = true

rangeInValueOne = true
rangeInValueTwo = false``````
Is I am right?
j

Jacob

03/06/2023, 5:03 PM
Some would say that every range check could have 4 tests.: At the lower bound and IN. At the Lower bound but Out, At the higher bound and IN. At the higher bound but Out,
Some might argue in the opposite direction, If you tested (true, false) and (false, true) do you really need to test (false, false)? There's no one right answer
a false false test only proves that the code didn't do a xor. xors don't just happen by accident
In terms of coverage, it's not covering a new branch since the code short circuits on the first false
k

KotlinLeaner

03/06/2023, 5:11 PM
So what is the right way to do test. I am just want feedback for you guys.
What do you suggest to test in this function?
j

Jacob

03/06/2023, 5:17 PM
(0, 20) -> true (10, 30) -> true (-1, 20) -> false (11, 20) -> false (0, 19) -> false (0, 31) -> false