-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(7-kyu): kata/simple-maths-test (#596)
- Loading branch information
1 parent
6275b86
commit a502534
Showing
5 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# [Simple Maths Test](https://www.codewars.com/kata/simple-maths-test "https://www.codewars.com/kata/5507309481b8bd3b7e001638") | ||
|
||
Create a function which checks a number for three different properties. | ||
|
||
- is the number prime? | ||
- is the number even? | ||
- is the number a multiple of 10? | ||
|
||
Each should return either true or false, which should be given as an array. | ||
|
||
### Examples | ||
|
||
``` | ||
SimpleMath.numberProperty(7) => new boolean[] {true, false, false} | ||
SimpleMath.numberProperty(10) => new boolean[] {false, true, true} | ||
``` | ||
|
||
The number will always be an integer, either positive or negative. Note that negative numbers cannot be primes, but | ||
they can be multiples of 10: | ||
|
||
``` | ||
SimpleMath.numberProperty(-7) => new boolean[] {false, false, false} | ||
SimpleMath.numberProperty(-10) => new boolean[] {false, true, true} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import static java.math.BigInteger.valueOf; | ||
|
||
interface SimpleMath { | ||
static boolean[] numberProperty(int n) { | ||
return new boolean[]{n > 0 && valueOf(n).isProbablePrime(9), n % 2 == 0, n % 10 == 0}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import static org.junit.jupiter.api.Assertions.assertArrayEquals; | ||
|
||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
|
||
class SimpleMathTests { | ||
@ParameterizedTest | ||
@CsvSource(textBlock = """ | ||
-10, false, true, true | ||
-2, false, true, false | ||
0, false, true, true | ||
1, false, false, false | ||
2, true, true, false | ||
120, false, true, true | ||
125, false, false, false | ||
139, true, false, false | ||
341, false, false, false | ||
""") | ||
void sample(int n, boolean prime, boolean even, boolean decimal) { | ||
assertArrayEquals(new boolean[]{prime, even, decimal}, SimpleMath.numberProperty(n)); | ||
} | ||
} |