From 6afac927f53e988896622fb445bb301fd01a5e48 Mon Sep 17 00:00:00 2001 From: "Capt. Cutlass" <5120290+ParanoidUser@users.noreply.github.com> Date: Thu, 4 Jul 2024 18:51:13 -0400 Subject: [PATCH 1/2] feat(7-kyu): kata/simple-maths-test --- docs/README.md | 2 +- kata/7-kyu/index.md | 1 + kata/7-kyu/simple-maths-test/README.md | 24 +++++++++++++++++++ .../simple-maths-test/main/SimpleMath.java | 7 ++++++ .../test/SimpleMathTests.java | 22 +++++++++++++++++ 5 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 kata/7-kyu/simple-maths-test/README.md create mode 100644 kata/7-kyu/simple-maths-test/main/SimpleMath.java create mode 100644 kata/7-kyu/simple-maths-test/test/SimpleMathTests.java diff --git a/docs/README.md b/docs/README.md index 226086a25..83dec6fe1 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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. diff --git a/kata/7-kyu/index.md b/kata/7-kyu/index.md index 0161b0aa4..46416f20d 100644 --- a/kata/7-kyu/index.md +++ b/kata/7-kyu/index.md @@ -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) diff --git a/kata/7-kyu/simple-maths-test/README.md b/kata/7-kyu/simple-maths-test/README.md new file mode 100644 index 000000000..abf2c251b --- /dev/null +++ b/kata/7-kyu/simple-maths-test/README.md @@ -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} +``` \ No newline at end of file diff --git a/kata/7-kyu/simple-maths-test/main/SimpleMath.java b/kata/7-kyu/simple-maths-test/main/SimpleMath.java new file mode 100644 index 000000000..8b7014770 --- /dev/null +++ b/kata/7-kyu/simple-maths-test/main/SimpleMath.java @@ -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}; + } +} \ No newline at end of file diff --git a/kata/7-kyu/simple-maths-test/test/SimpleMathTests.java b/kata/7-kyu/simple-maths-test/test/SimpleMathTests.java new file mode 100644 index 000000000..1d185c682 --- /dev/null +++ b/kata/7-kyu/simple-maths-test/test/SimpleMathTests.java @@ -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)); + } +} \ No newline at end of file From 61e780350782edd45494ca023426e6809c3595bb Mon Sep 17 00:00:00 2001 From: "Capt. Cutlass" <5120290+ParanoidUser@users.noreply.github.com> Date: Thu, 4 Jul 2024 18:56:44 -0400 Subject: [PATCH 2/2] chore: nothing