Skip to content

Commit

Permalink
feat(7-kyu): kata/simple-maths-test (#596)
Browse files Browse the repository at this point in the history
  • Loading branch information
ParanoidUser committed Jul 4, 2024
1 parent 6275b86 commit a502534
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ slug.

| [1 kyu](/kata/1-kyu/index.md) | [2 kyu](/kata/2-kyu/index.md) | [3 kyu](/kata/3-kyu/index.md) | [4 kyu](/kata/4-kyu/index.md) | [5 kyu](/kata/5-kyu/index.md) | [6 kyu](/kata/6-kyu/index.md) | [7 kyu](/kata/7-kyu/index.md) | [8 kyu](/kata/8-kyu/index.md) | [beta](/kata/beta/index.md) | [retired](/kata/retired/index.md) |
|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:---------------------------:|:---------------------------------:|
| 0 | 1 | 2 | 26 | 48 | 426 | 571 | 210 | 56 | 79 |
| 0 | 1 | 2 | 26 | 48 | 426 | 572 | 210 | 56 | 79 |

**Note:** The source code is written in Java 17 and may use language features that are incompatible
with Java 8, 11.
Expand Down
1 change: 1 addition & 0 deletions kata/7-kyu/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@
- [Simple Fun #74: Growing Plant](simple-fun-number-74-growing-plant)
- [Simple Fun #9: Array Packing](simple-fun-number-9-array-packing)
- [Simple letter removal](simple-letter-removal)
- [Simple Maths Test](simple-maths-test)
- [Simple remove duplicates](simple-remove-duplicates)
- [Simple Socket Client](simple-socket-client)
- [Simple string characters](simple-string-characters)
Expand Down
24 changes: 24 additions & 0 deletions kata/7-kyu/simple-maths-test/README.md
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}
```
7 changes: 7 additions & 0 deletions kata/7-kyu/simple-maths-test/main/SimpleMath.java
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};
}
}
22 changes: 22 additions & 0 deletions kata/7-kyu/simple-maths-test/test/SimpleMathTests.java
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));
}
}

0 comments on commit a502534

Please sign in to comment.