Skip to content

Commit 1f36ca1

Browse files
committed
1 parent 30eed8c commit 1f36ca1

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
# [Grasshopper - If/else syntax debug](https://www.codewars.com/kata/grasshopper-if-slash-else-syntax-debug "https://www.codewars.com/kata/57089707fe2d01529f00024a")
22

3-
## If/else syntax debug
3+
While making a game, your partner, Greg, decided to create a function to check if the user is still alive called `checkAlive`/`CheckAlive`/
4+
`check_alive`. Unfortunately, Greg made some errors while creating the function.
45

5-
While making a game, your partner, Greg, decided to create a function to check if the user is still alive called `checkAlive`/`CheckAlive`/`check_alive`. Unfortunately, Greg made some errors while creating the function.
6+
`checkAlive`/`CheckAlive`/`check_alive` should return true if the player's health is greater than 0 or false if it is 0 or below.
67

7-
`checkAlive`/`CheckAlive`/`check_alive` should return true if the player's health is greater than 0 or false if it is 0 or below.
8-
9-
```if-not:csharp
10-
The function receives one parameter `health` which will always be a whole number between -10 and 10.
11-
```
8+
The function receives one parameter `health` which will always be a whole number between -10 and 10.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
interface Solution {
2+
static boolean checkAlive(int health) {
3+
return health > 0;
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import static org.junit.jupiter.api.Assertions.assertFalse;
2+
import static org.junit.jupiter.api.Assertions.assertTrue;
3+
4+
import org.junit.jupiter.params.ParameterizedTest;
5+
import org.junit.jupiter.params.provider.ValueSource;
6+
7+
class SolutionTest {
8+
@ParameterizedTest
9+
@ValueSource(ints = {1, 2, 3, 4, 5, 6, 7, 8, 9})
10+
void alive(int health) {
11+
assertTrue(Solution.checkAlive(health));
12+
}
13+
14+
@ParameterizedTest
15+
@ValueSource(ints = {0, -1, -2, -3, -4, -5, -6, -7, -8, -9})
16+
void dead(int health) {
17+
assertFalse(Solution.checkAlive(health));
18+
}
19+
}

0 commit comments

Comments
 (0)