1 | package io.github.mathieusoysal.yatzy_mod; | |
2 | ||
3 | import java.util.Collection; | |
4 | import java.util.Collections; | |
5 | import java.util.List; | |
6 | import java.util.stream.IntStream; | |
7 | ||
8 | import io.github.mathieusoysal.Dices; | |
9 | ||
10 | /** | |
11 | * The {@code YatzyModUtils} class provides utility methods for Yatzy game score | |
12 | * calculations. | |
13 | * | |
14 | * @author MathieuSoysal | |
15 | * @see Dices | |
16 | */ | |
17 | class YatzyModUtils { | |
18 | ||
19 | private YatzyModUtils() { | |
20 | } | |
21 | ||
22 | /** | |
23 | * Filters and sums the dice values that match a given number. | |
24 | * | |
25 | * @param diceNumber The number to match. | |
26 | * @param diceResults The set of dice to filter and sum. | |
27 | * @return The sum of dice values that match the given number. | |
28 | */ | |
29 | static int filterAndSum(int diceNumber, Dices diceResults) { | |
30 |
1
1. filterAndSum : replaced int return with 0 for io/github/mathieusoysal/yatzy_mod/YatzyModUtils::filterAndSum → KILLED |
return diceResults.getDicesIntStream() |
31 |
2
1. lambda$filterAndSum$0 : negated conditional → KILLED 2. lambda$filterAndSum$0 : replaced boolean return with true for io/github/mathieusoysal/yatzy_mod/YatzyModUtils::lambda$filterAndSum$0 → KILLED |
.filter(d -> d == diceNumber) |
32 | .sum(); | |
33 | } | |
34 | ||
35 | /** | |
36 | * Checks if the dice values match a specified list when sorted. | |
37 | * | |
38 | * @param dices The set of dice to check. | |
39 | * @param toBeEquals The list of values to compare with the sorted dice values. | |
40 | * @return {@code true} if the dice values match the specified list when sorted, | |
41 | * {@code false} otherwise. | |
42 | */ | |
43 | static boolean isItEqualsWhenDicesIsSorted(Dices dices, List<Integer> toBeEquals) { | |
44 |
2
1. isItEqualsWhenDicesIsSorted : replaced boolean return with false for io/github/mathieusoysal/yatzy_mod/YatzyModUtils::isItEqualsWhenDicesIsSorted → KILLED 2. isItEqualsWhenDicesIsSorted : replaced boolean return with true for io/github/mathieusoysal/yatzy_mod/YatzyModUtils::isItEqualsWhenDicesIsSorted → KILLED |
return dices.getDicesIntStream() |
45 | .sorted().boxed().toList() | |
46 | .equals(toBeEquals); | |
47 | } | |
48 | ||
49 | /** | |
50 | * Filters the dice values that occur at least a specified frequency. | |
51 | * | |
52 | * @param frequency The minimum frequency for dice values. | |
53 | * @param dices The set of dice to filter. | |
54 | * @return An {@code IntStream} containing the filtered dice values. | |
55 | */ | |
56 | static IntStream filterByFrequency(int frequency, Dices dices) { | |
57 | Collection<Integer> diceCollection = dices.getDicesIntStream() | |
58 | .boxed().toList(); | |
59 |
1
1. filterByFrequency : replaced return value with null for io/github/mathieusoysal/yatzy_mod/YatzyModUtils::filterByFrequency → KILLED |
return dices.getDicesIntStream() |
60 |
3
1. lambda$filterByFrequency$1 : changed conditional boundary → KILLED 2. lambda$filterByFrequency$1 : replaced boolean return with true for io/github/mathieusoysal/yatzy_mod/YatzyModUtils::lambda$filterByFrequency$1 → KILLED 3. lambda$filterByFrequency$1 : negated conditional → KILLED |
.filter(v -> Collections.frequency(diceCollection, v) >= frequency); |
61 | } | |
62 | ||
63 | /** | |
64 | * Checks if the dice values contain at least one value with an exact frequency. | |
65 | * | |
66 | * @param frequency The exact frequency to check. | |
67 | * @param dices The set of dice to check. | |
68 | * @return {@code true} if the dice values contain at least one value with the | |
69 | * exact frequency, {@code false} otherwise. | |
70 | */ | |
71 | static boolean containsExactFrequencyDice(int frequency, Dices dices) { | |
72 | Collection<Integer> diceCollection = dices.getDicesIntStream() | |
73 | .boxed().toList(); | |
74 |
2
1. containsExactFrequencyDice : replaced boolean return with true for io/github/mathieusoysal/yatzy_mod/YatzyModUtils::containsExactFrequencyDice → KILLED 2. containsExactFrequencyDice : replaced boolean return with false for io/github/mathieusoysal/yatzy_mod/YatzyModUtils::containsExactFrequencyDice → KILLED |
return dices.getDicesIntStream() |
75 |
2
1. lambda$containsExactFrequencyDice$2 : replaced boolean return with true for io/github/mathieusoysal/yatzy_mod/YatzyModUtils::lambda$containsExactFrequencyDice$2 → KILLED 2. lambda$containsExactFrequencyDice$2 : negated conditional → KILLED |
.anyMatch(v -> Collections.frequency(diceCollection, v) == frequency); |
76 | } | |
77 | } | |
Mutations | ||
30 |
1.1 |
|
31 |
1.1 2.2 |
|
44 |
1.1 2.2 |
|
59 |
1.1 |
|
60 |
1.1 2.2 3.3 |
|
74 |
1.1 2.2 |
|
75 |
1.1 2.2 |