From 2502847d7cfcf38722759645ac08ee911a0b4db8 Mon Sep 17 00:00:00 2001 From: "Capt. Cutlass" <5120290+ParanoidUser@users.noreply.github.com> Date: Mon, 26 Aug 2024 22:05:02 -0400 Subject: [PATCH] feat(8-kyu): kata/grader --- kata/8-kyu/grader/README.md | 17 +++++++++-------- kata/8-kyu/grader/main/Grader.java | 5 +++++ kata/8-kyu/grader/test/GraderTest.java | 20 ++++++++++++++++++++ kata/8-kyu/index.md | 1 + 4 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 kata/8-kyu/grader/main/Grader.java create mode 100644 kata/8-kyu/grader/test/GraderTest.java diff --git a/kata/8-kyu/grader/README.md b/kata/8-kyu/grader/README.md index cf7c643b..07e1b57f 100644 --- a/kata/8-kyu/grader/README.md +++ b/kata/8-kyu/grader/README.md @@ -2,15 +2,16 @@ Create a function that takes a number as an argument and returns a grade based on that number. -Score | Grade ------------------------------------------|----- -Anything greater than 1 or less than 0.6 | "F" -0.9 or greater | "A" -0.8 or greater | "B" -0.7 or greater | "C" -0.6 or greater | "D" +| Score | Grade | +|------------------------------------------|-------| +| Anything greater than 1 or less than 0.6 | "F" | +| 0.9 or greater | "A" | +| 0.8 or greater | "B" | +| 0.7 or greater | "C" | +| 0.6 or greater | "D" | Examples: + ``` grader(0) should be "F" grader(1.1) should be "F" @@ -18,4 +19,4 @@ grader(0.9) should be "A" grader(0.8) should be "B" grader(0.7) should be "C" grader(0.6) should be "D" -``` +``` \ No newline at end of file diff --git a/kata/8-kyu/grader/main/Grader.java b/kata/8-kyu/grader/main/Grader.java new file mode 100644 index 00000000..911e89a8 --- /dev/null +++ b/kata/8-kyu/grader/main/Grader.java @@ -0,0 +1,5 @@ +interface Grader { + static String grader(double score) { + return "FFFFFFDCBAAF".charAt((int) (score > 1 ? 11 : 10 * score)) + ""; + } +} \ No newline at end of file diff --git a/kata/8-kyu/grader/test/GraderTest.java b/kata/8-kyu/grader/test/GraderTest.java new file mode 100644 index 00000000..69c11350 --- /dev/null +++ b/kata/8-kyu/grader/test/GraderTest.java @@ -0,0 +1,20 @@ +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +class GraderTest { + @ParameterizedTest + @CsvSource(textBlock = """ + 1.1, F + 1, A + 0.9, A + 0.81, B + 0.7, C + 0.6, D + 0.49, F + """) + void sample(double score, String grade) { + assertEquals(grade, Grader.grader(score)); + } +} \ No newline at end of file diff --git a/kata/8-kyu/index.md b/kata/8-kyu/index.md index 6a463975..12474b56 100644 --- a/kata/8-kyu/index.md +++ b/kata/8-kyu/index.md @@ -95,6 +95,7 @@ - [Get Planet Name By ID](get-planet-name-by-id) - [Get the mean of an array](get-the-mean-of-an-array) - [Ghost code?!](ghost-code) +- [Grader](grader) - [Grasshopper - Array Mean](grasshopper-array-mean) - [Grasshopper - Basic Function Fixer](grasshopper-basic-function-fixer) - [Grasshopper - Check for factor](grasshopper-check-for-factor)