From 4b59ead3dc51ab688e40b8b978910578c009f918 Mon Sep 17 00:00:00 2001 From: "g.monteynard" <gdemonteynard@takima.fr> Date: Fri, 7 Jul 2023 22:55:21 +0200 Subject: [PATCH] =?UTF-8?q?V1=20du=20Kata=20apres=20les=203=20heures=20?= =?UTF-8?q?=C3=A0=20Takima?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .editorconfig | 2 + .gitignore | 3 + README.md | 93 +----- pom.xml | 34 ++ src/main/java/CalculateScore.java | 6 + src/main/java/YatzyCategory.java | 165 ++++++++++ src/test/java/YatzyTest.java | 511 ++++++++++++++++++++++++++++++ 7 files changed, 722 insertions(+), 92 deletions(-) create mode 100644 .editorconfig create mode 100644 .gitignore create mode 100644 pom.xml create mode 100644 src/main/java/CalculateScore.java create mode 100644 src/main/java/YatzyCategory.java create mode 100644 src/test/java/YatzyTest.java diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..930c491 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,2 @@ +[*] +indent_size = 4 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e717935 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.iml +.idea +/target diff --git a/README.md b/README.md index 75c67d8..dc3ae35 100644 --- a/README.md +++ b/README.md @@ -1,92 +1 @@ -# Yatzy-Refactoring-Kata - - - -## Getting started - -To make it easy for you to get started with GitLab, here's a list of recommended next steps. - -Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! - -## Add your files - -- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files -- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: - -``` -cd existing_repo -git remote add origin https://gitlab.takima.io/gdemonteynard/yatzy-refactoring-kata.git -git branch -M main -git push -uf origin main -``` - -## Integrate with your tools - -- [ ] [Set up project integrations](https://gitlab.takima.io/gdemonteynard/yatzy-refactoring-kata/-/settings/integrations) - -## Collaborate with your team - -- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) -- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) -- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) -- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) -- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) - -## Test and Deploy - -Use the built-in continuous integration in GitLab. - -- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) -- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) -- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) -- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) -- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) - -*** - -# Editing this README - -When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template. - -## Suggestions for a good README -Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. - -## Name -Choose a self-explaining name for your project. - -## Description -Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. - -## Badges -On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. - -## Visuals -Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. - -## Installation -Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. - -## Usage -Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. - -## Support -Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. - -## Roadmap -If you have ideas for releases in the future, it is a good idea to list them in the README. - -## Contributing -State if you are open to contributions and what your requirements are for accepting them. - -For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. - -You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. - -## Authors and acknowledgment -Show your appreciation to those who have contributed to the project. - -## License -For open source projects, say how it is licensed. - -## Project status -If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. +Kata for DataNumia, based on this [Yatzy-Refactoring-Kata](https://github.com/emilybache/Yatzy-Refactoring-Kata) \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..67744db --- /dev/null +++ b/pom.xml @@ -0,0 +1,34 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>com.github.emilybache</groupId> + <artifactId>yatzy-refactoring-kata</artifactId> + <version>1.0.0</version> + + <properties> + <maven.compiler.release>11</maven.compiler.release> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <dependencies> + + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter</artifactId> + <version>RELEASE</version> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <pluginManagement> + <plugins> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.8.1</version> + </plugin> + </plugins> + </pluginManagement> + </build> +</project> diff --git a/src/main/java/CalculateScore.java b/src/main/java/CalculateScore.java new file mode 100644 index 0000000..8828a37 --- /dev/null +++ b/src/main/java/CalculateScore.java @@ -0,0 +1,6 @@ +import java.util.LinkedHashSet; +import java.util.List; + +public interface CalculateScore { + int getScore(List<Integer> dice); +} diff --git a/src/main/java/YatzyCategory.java b/src/main/java/YatzyCategory.java new file mode 100644 index 0000000..fbfde64 --- /dev/null +++ b/src/main/java/YatzyCategory.java @@ -0,0 +1,165 @@ +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.function.Function; +import java.util.stream.Collectors; + +public enum YatzyCategory { + Yatzy { + public int getScore(List<Integer> dice) { + if (dice.stream().distinct().count() == 1) { + return 50; + } + return 0; + } + }, + Chance { + @Override + public int getScore(List<Integer> dice) { + return dice.stream().reduce(0, Integer::sum); + } + }, + Ones { + @Override + public int getScore(List<Integer> dice) { + return scoreSingle(1, dice); + } + }, + Twos { + @Override + public int getScore(List<Integer> dice) { + return scoreSingle(2, dice); + } + }, + Threes { + @Override + public int getScore(List<Integer> dice) { + return scoreSingle(3, dice); + } + }, + Fours { + @Override + public int getScore(List<Integer> dice) { + return scoreSingle(4, dice); + } + }, + Fives { + @Override + public int getScore(List<Integer> dice) { + return scoreSingle(5, dice); + } + }, + Sixes { + @Override + public int getScore(List<Integer> dice) { + return scoreSingle(6, dice); + } + }, + Pair { + @Override + public int getScore(List<Integer> dice) { + Map<Integer, Long> grouped = groupByValue(dice); + return grouped.entrySet().stream() + .filter(entry -> entry.getValue() >= 2) + .map(entry -> entry.getKey() * 2) + .max(Integer::compareTo) + .orElse(0); + } + }, + TwoPairs { + @Override + public int getScore(List<Integer> dice) { + Map<Integer, Long> grouped = groupByValue(dice); + List<Integer> listOfPairs = grouped.entrySet().stream() + .filter(entry -> entry.getValue() >= 2) + .map(entry -> entry.getKey() * 2) + .collect(Collectors.toList()); + + if (listOfPairs.size() == 2) { + return listOfPairs.stream().reduce(0, Integer::sum); + } else { + return 0; + } + + } + }, + ThreeOfAKind { + @Override + public int getScore(List<Integer> dice) { + return XOfAKing(dice, 3); + } + }, + FourOfAKind { + @Override + public int getScore(List<Integer> dice) { + return XOfAKing(dice, 4); + } + + }, + SmallStraight { + @Override + public int getScore(List<Integer> dice) { + return straight(dice, 1); + } + }, + LargeStraight { + @Override + public int getScore(List<Integer> dice) { + return straight(dice, 2); + } + }, + FullHouse { + @Override + public int getScore(List<Integer> dice) { + Map<Integer, Long> grouped = groupByValue(dice); + boolean hasTwo = false; + boolean hasThree = false; + for (Map.Entry<Integer, Long> entry : grouped.entrySet()) { + if (entry.getValue() == 2) { + hasTwo = true; + } else if (entry.getValue() == 3) { + hasThree = true; + } + } + if (hasTwo && hasThree) { + return dice.stream().reduce(0, Integer::sum); + } + return 0; + } + }; + + private static int straight(List<Integer> dice, Integer min) { + + List<Integer> sorted = dice.stream().sorted().collect(Collectors.toList()); + if (!Objects.equals(sorted.get(0), min)) { + return 0; + } + //If next number is 1 more than previous, then it's a straight + for (int i = 0; i < sorted.size() - 1; i++) { + if (sorted.get(i) + 1 != sorted.get(i + 1)) { + return 0; + } + } + return sorted.stream().reduce(0, Integer::sum); + } + + private static Map<Integer, Long> groupByValue(List<Integer> dice) { + return dice.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); + } + + private static int XOfAKing(List<Integer> dice, int groupLength) { + Map<Integer, Long> grouped = groupByValue(dice); + return grouped.entrySet().stream() + .filter(entry -> entry.getValue() >= groupLength) + .map(entry -> entry.getKey() * groupLength) + .findFirst() + .orElse(0); + } + + private static int scoreSingle(int number, List<Integer> dice) { + return dice.stream().filter(die -> die == number).reduce(0, Integer::sum); + } + + public abstract int getScore(List<Integer> dice); + +} diff --git a/src/test/java/YatzyTest.java b/src/test/java/YatzyTest.java new file mode 100644 index 0000000..228291d --- /dev/null +++ b/src/test/java/YatzyTest.java @@ -0,0 +1,511 @@ +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; + + +public class YatzyTest { + + @DisplayName("Chance") + @Nested + class Chance { + @Test + @DisplayName("should sum all dice correctly when all dice are different") + public void chanceScoreSum() { + List<Integer> dice = List.of(2, 3, 4, 5, 1); + int expected = 15; + int actual = YatzyCategory.Chance.getScore(dice); + assertEquals(expected, actual); + } + + @Test + @DisplayName("should sum all dice correctly when some dice are the same") + public void chanceScoreSumWithDuplicates() { + List<Integer> dice = List.of(3, 3, 4, 5, 1); + int expected = 16; + int actual = YatzyCategory.Chance.getScore(dice); + assertEquals(expected, actual); + } + + } + + @Nested + @DisplayName("Yatzy") + class Yahtzee { + @Test + @DisplayName("should score 50 when all dice are the same") + public void yatzyScores50() { + List<Integer> dice = List.of(6, 6, 6, 6, 6); + int expected = 50; + int actual = YatzyCategory.Yatzy.getScore(dice); + assertEquals(expected, actual); + } + + @Test + @DisplayName("should score 0 when all dice are not the same") + public void yatzyScores0() { + List<Integer> dice = List.of(6, 6, 6, 6, 3); + int expected = 0; + int actual = YatzyCategory.Yatzy.getScore(dice); + assertEquals(expected, actual); + } + } + + @Nested + @DisplayName("Ones") + class Ones { + @Test + @DisplayName("should score 0 when 0 'ones' are rolled") + public void onesScores0() { + List<Integer> dice = List.of(6, 2, 2, 4, 5); + int expected = 0; + int actual = YatzyCategory.Ones.getScore(dice); + assertEquals(expected, actual); + } + + @Test + @DisplayName("should score 1 when 1 'ones' are rolled") + public void onesScores1() { + List<Integer> dice = List.of(1, 2, 3, 4, 5); + int expected = 1; + int actual = YatzyCategory.Ones.getScore(dice); + assertEquals(expected, actual); + } + + @Test + @DisplayName("should score 2 when 2 'ones' are rolled") + public void onesScores2() { + List<Integer> dice = List.of(1, 2, 1, 4, 5); + int expected = 2; + int actual = YatzyCategory.Ones.getScore(dice); + assertEquals(expected, actual); + } + + @Test + @DisplayName("should score 4 when 4 'ones' are rolled") + public void onesScores4() { + List<Integer> dice = List.of(1, 2, 1, 1, 1); + int expected = 4; + int actual = YatzyCategory.Ones.getScore(dice); + assertEquals(expected, actual); + } + + } + + @Nested + @DisplayName("Twos") + class Twos { + @Test + @DisplayName("should score 4 when 2 'twos' are rolled") + public void twosScores4() { + List<Integer> dice = List.of(1, 2, 3, 2, 6); + int expected = 4; + int actual = YatzyCategory.Twos.getScore(dice); + assertEquals(expected, actual); + } + + @Test + @DisplayName("should score 10 when 5 'twos' are rolled") + public void twosScores10() { + List<Integer> dice = List.of(2, 2, 2, 2, 2); + int expected = 10; + int actual = YatzyCategory.Twos.getScore(dice); + assertEquals(expected, actual); + } + + } + + @Nested + @DisplayName("Threes") + class Threes { + @Test + @DisplayName("should score 6 when 2 'threes' are rolled") + public void threesScores6() { + List<Integer> dice = List.of(1, 2, 3, 2, 3); + int expected = 6; + int actual = YatzyCategory.Threes.getScore(dice); + assertEquals(expected, actual); + } + + @Test + @DisplayName("should score 6 when 2 'threes' are rolled") + public void threesScores12() { + List<Integer> dice = List.of(2, 3, 3, 3, 3); + int expected = 12; + int actual = YatzyCategory.Threes.getScore(dice); + assertEquals(expected, actual); + } + + } + + @Nested + @DisplayName("Fours") + class Fours { + @Test + @DisplayName("should score 12 when 3 'threes' are rolled") + public void foursScores12() { + List<Integer> dice = List.of(4, 4, 4, 5, 5); + int expected = 12; + int actual = YatzyCategory.Fours.getScore(dice); + assertEquals(expected, actual); + } + + @Test + @DisplayName("should score 8 when 2 'fours' are rolled") + public void foursScores8() { + List<Integer> dice = List.of(4, 4, 5, 5, 5); + int expected = 8; + int actual = YatzyCategory.Fours.getScore(dice); + assertEquals(expected, actual); + } + + @Test + @DisplayName("should score 4 when 1 'fours' are rolled") + public void foursScores4() { + List<Integer> dice = List.of(4, 5, 5, 5, 5); + int expected = 4; + int actual = YatzyCategory.Fours.getScore(dice); + assertEquals(expected, actual); + } + + } + + @Nested + @DisplayName("Fives") + class Fives { + @Test + @DisplayName("should score 10 when 2 'fives' are rolled") + public void fivesScores10() { + List<Integer> dice = List.of(4, 4, 4, 5, 5); + int expected = 10; + int actual = YatzyCategory.Fives.getScore(dice); + assertEquals(expected, actual); + } + + @Test + @DisplayName("should score 15 when 3 'fives' are rolled") + public void fivesScores15() { + List<Integer> dice = List.of(4, 4, 5, 5, 5); + int expected = 15; + int actual = YatzyCategory.Fives.getScore(dice); + assertEquals(expected, actual); + } + + @Test + @DisplayName("should score 20 when 4 'fives' are rolled") + public void fivesScores5() { + List<Integer> dice = List.of(4, 5, 5, 5, 5); + int expected = 20; + int actual = YatzyCategory.Fives.getScore(dice); + assertEquals(expected, actual); + } + + } + + @Nested + @DisplayName("Sixes") + class Sixes { + @Test + @DisplayName("should score 0 when 2 'sixes' are rolled") + public void sixesScores0() { + List<Integer> dice = List.of(4, 4, 4, 5, 5); + int expected = 0; + int actual = YatzyCategory.Sixes.getScore(dice); + assertEquals(expected, actual); + } + + @Test + @DisplayName("should score 6 when 1 'sixes' are rolled") + public void sixesScores6() { + List<Integer> dice = List.of(4, 4, 6, 5, 5); + int expected = 6; + int actual = YatzyCategory.Sixes.getScore(dice); + assertEquals(expected, actual); + } + + @Test + @DisplayName("should score 18 when 3 'sixes' are rolled") + public void sixesScores18() { + List<Integer> dice = List.of(6, 5, 6, 6, 5); + int expected = 18; + int actual = YatzyCategory.Sixes.getScore(dice); + assertEquals(expected, actual); + } + + } + + @Nested + @DisplayName("One Pair") + class OnePair { + @Test + @DisplayName("should score 6 when 2 'three' are rolled") + public void onePairScores6() { + List<Integer> dice = List.of(3, 4, 3, 5, 6); + int expected = 6; + int actual = YatzyCategory.Pair.getScore(dice); + assertEquals(expected, actual); + } + + @Test + @DisplayName("should score 10 when 2 'five' and 3 'three' are rolled") + public void onePairScores10() { + List<Integer> dice = List.of(5, 3, 3, 3, 5); + int expected = 10; + int actual = YatzyCategory.Pair.getScore(dice); + assertEquals(expected, actual); + } + + @Test + @DisplayName("should score 12 when 3 'six' are rolled") + public void onePairScores12() { + List<Integer> dice = List.of(5, 6, 6, 6, 3); + int expected = 12; + int actual = YatzyCategory.Pair.getScore(dice); + assertEquals(expected, actual); + } + + @Test + @DisplayName("should score 0 when any pair") + public void noPair() { + List<Integer> dice = List.of(4, 1, 2, 3, 5); + int expected = 0; + int actual = YatzyCategory.Pair.getScore(dice); + assertEquals(expected, actual); + } + } + + @Nested + @DisplayName("Two Pairs") + class TwoPairs { + @Test + @DisplayName("should score 16 when 2 'threes' and 2 'fives' are rolled") + public void twoPairsScores16() { + List<Integer> dice = List.of(3, 3, 5, 4, 5); + int expected = 16; + int actual = YatzyCategory.TwoPairs.getScore(dice); + assertEquals(expected, actual); + } + + @Test + @DisplayName("should score 16 when 2 'threes' and 3 'fives' are rolled") + public void aPairAndATriplescores16() { + List<Integer> dice = List.of(3, 3, 5, 5, 5); + int expected = 16; + int actual = YatzyCategory.TwoPairs.getScore(dice); + assertEquals(expected, actual); + } + + @Test + @DisplayName("should score 0 when no pair") + public void noPair() { + List<Integer> dice = List.of(4, 1, 2, 3, 5); + int expected = 0; + int actual = YatzyCategory.TwoPairs.getScore(dice); + assertEquals(expected, actual); + } + + @Test + @DisplayName("should score 0 when one pair") + public void onePair() { + List<Integer> dice = List.of(4, 4, 2, 3, 5); + int expected = 0; + int actual = YatzyCategory.TwoPairs.getScore(dice); + assertEquals(expected, actual); + } + + } + + @Nested + @DisplayName("Three of a kind") + class ThreeOfAKind { + @Test + @DisplayName("should score 9 when 3 'threes' are rolled") + public void threeOfAKindScores9() { + List<Integer> dice = List.of(3, 3, 3, 4, 5); + int expected = 9; + int actual = YatzyCategory.ThreeOfAKind.getScore(dice); + assertEquals(expected, actual); + } + + @Test + @DisplayName("should score 15 when 3 'fives' are rolled") + public void threeOfAKindScores15() { + List<Integer> dice = List.of(4, 4, 5, 5, 5); + int expected = 15; + int actual = YatzyCategory.ThreeOfAKind.getScore(dice); + assertEquals(expected, actual); + } + + @Test + @DisplayName("should score 9 when 4 'threes' are rolled") + public void threeOfAKindWith4SameScores9() { + List<Integer> dice = List.of(3, 3, 3, 3, 5); + int expected = 9; + int actual = YatzyCategory.ThreeOfAKind.getScore(dice); + assertEquals(expected, actual); + } + + @Test + @DisplayName("should score 0 when no three of a kind") + public void noThreeOfAKind() { + List<Integer> dice = List.of(4, 4, 2, 5, 5); + int expected = 0; + int actual = YatzyCategory.ThreeOfAKind.getScore(dice); + assertEquals(expected, actual); + } + } + + @Nested + @DisplayName("Four of a kind") + class FourOfAKind { + @Test + @DisplayName("should score 12 when 4 'threes' are rolled") + public void fourOfAKindScores12() { + List<Integer> dice = List.of(3, 3, 3, 3, 5); + int expected = 12; + int actual = YatzyCategory.FourOfAKind.getScore(dice); + assertEquals(expected, actual); + } + + @Test + @DisplayName("should score 20 when 4 'fives' are rolled") + public void fourOfAKindScores20() { + List<Integer> dice = List.of(5, 4, 5, 5, 5); + int expected = 20; + int actual = YatzyCategory.FourOfAKind.getScore(dice); + assertEquals(expected, actual); + } + + @Test + @DisplayName("should score 12 when 5 'threes' are rolled") + public void fourOfAKindWith5SameScores12() { + List<Integer> dice = List.of(3, 3, 3, 3, 3); + int expected = 12; + int actual = YatzyCategory.FourOfAKind.getScore(dice); + assertEquals(expected, actual); + } + + @Test + @DisplayName("should score 0 when no four of a kind") + public void noFourOfAKind() { + List<Integer> dice = List.of(4, 4, 2, 5, 5); + int expected = 0; + int actual = YatzyCategory.FourOfAKind.getScore(dice); + assertEquals(expected, actual); + } + } + + @Nested + @DisplayName("Small Straight") + class SmallStraight { + @Test + @DisplayName("should score 15 when 1,2,3,4,5 are rolled") + public void smallStraightScores15() { + List<Integer> dice = List.of(1, 2, 3, 4, 5); + int expected = 15; + int actual = YatzyCategory.SmallStraight.getScore(dice); + assertEquals(expected, actual); + } + + @Test + @DisplayName("should score 15 when 2,3,4,5,1 are rolled") + public void smallStraightScores15UnOrdered() { + List<Integer> dice = List.of(2, 3, 4, 5, 1); + int expected = 15; + int actual = YatzyCategory.SmallStraight.getScore(dice); + assertEquals(expected, actual); + } + + @Test + @DisplayName("should score 0 when 1,2,2,4,5 are rolled") + public void smallStraightScores0() { + List<Integer> dice = List.of(1, 2, 2, 4, 5); + int expected = 0; + int actual = YatzyCategory.SmallStraight.getScore(dice); + assertEquals(expected, actual); + } + + @Test + @DisplayName("should score 0 when 2,3,4,5,6 are rolled") + public void largeStraightScores0() { + List<Integer> dice = List.of(2, 3, 4, 5, 6); + int expected = 0; + int actual = YatzyCategory.SmallStraight.getScore(dice); + assertEquals(expected, actual); + } + } + + @Nested + @DisplayName("Large Straight") + class LargeStraight { + @Test + @DisplayName("should score 20 when 2,3,4,5,6 are rolled") + public void largeStraightScores20() { + List<Integer> dice = List.of(2, 3, 4, 5, 6); + int expected = 20; + int actual = YatzyCategory.LargeStraight.getScore(dice); + assertEquals(expected, actual); + } + + @Test + @DisplayName("should score 20 when 6,2,3,4,5 are rolled") + public void largeStraightScores20UnOrdered() { + List<Integer> dice = List.of(6, 2, 3, 4, 5); + int expected = 20; + int actual = YatzyCategory.LargeStraight.getScore(dice); + assertEquals(expected, actual); + } + + @Test + @DisplayName("should score 0 when 1,2,2,4,5 are rolled") + public void largeStraightScores0() { + List<Integer> dice = List.of(1, 2, 2, 4, 5); + int expected = 0; + int actual = YatzyCategory.LargeStraight.getScore(dice); + assertEquals(expected, actual); + } + + @Test + @DisplayName("should score 0 when 1,2,3,4,5 are rolled") + public void smallStraightScores0() { + List<Integer> dice = List.of(1, 2, 3, 4, 5); + int expected = 0; + int actual = YatzyCategory.LargeStraight.getScore(dice); + assertEquals(expected, actual); + } + } + + @Nested + @DisplayName("Full House") + class FullHouse { + @Test + @DisplayName("should score 18 when 6,2,2,2,6 are rolled") + public void fullHouseScores18() { + List<Integer> dice = List.of(6, 2, 2, 2, 6); + int expected = 18; + int actual = YatzyCategory.FullHouse.getScore(dice); + assertEquals(expected, actual); + } + + @Test + @DisplayName("should score 0 when 2,3,4,5,6 are rolled") + public void fullHouseScores0() { + List<Integer> dice = List.of(2, 3, 4, 5, 6); + int expected = 0; + int actual = YatzyCategory.FullHouse.getScore(dice); + assertEquals(expected, actual); + } + + @Test + @DisplayName("should score 0 when two pairs are rolled") + public void fullHouseScores0WhenTwoPairs() { + List<Integer> dice = List.of(2, 2, 3, 3, 4); + int expected = 0; + int actual = YatzyCategory.FullHouse.getScore(dice); + assertEquals(expected, actual); + } + } +} -- GitLab