Skip to content

Commit

Permalink
feat(8-kyu): kata/grader
Browse files Browse the repository at this point in the history
  • Loading branch information
ParanoidUser committed Aug 27, 2024
1 parent ea37aa9 commit 2502847
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
17 changes: 9 additions & 8 deletions kata/8-kyu/grader/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@

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"
grader(0.9) should be "A"
grader(0.8) should be "B"
grader(0.7) should be "C"
grader(0.6) should be "D"
```
```
5 changes: 5 additions & 0 deletions kata/8-kyu/grader/main/Grader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
interface Grader {
static String grader(double score) {
return "FFFFFFDCBAAF".charAt((int) (score > 1 ? 11 : 10 * score)) + "";
}
}
20 changes: 20 additions & 0 deletions kata/8-kyu/grader/test/GraderTest.java
Original file line number Diff line number Diff line change
@@ -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));
}
}
1 change: 1 addition & 0 deletions kata/8-kyu/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2502847

Please sign in to comment.