This repository has been archived by the owner on Jan 18, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bd8eeb1
commit 1ad6379
Showing
2 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
root = true | ||
|
||
[*.java] | ||
max_line_length = 80 | ||
max_line_length = 80 | ||
indent_style = space | ||
indent_size = 4 |
62 changes: 62 additions & 0 deletions
62
culminating-mastermind/app/src/test/java/mastermind/CodeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package mastermind; | ||
|
||
import mastermind.core.Code; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
import java.util.HashMap; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assumptions.assumeTrue; | ||
|
||
class CodeTest { | ||
@Test | ||
void testGenerateRandomCode() { | ||
final Code randomCode = Code.generateRandomCode(List.of()); | ||
final int expectedCodeLength = Mastermind.CODE_LENGTH; | ||
final var colorArray = randomCode.getColors(); | ||
|
||
assertEquals(expectedCodeLength, colorArray.size()); | ||
} | ||
|
||
@Test | ||
void testCodeFromIndices() { | ||
final Code code = new Code(List.of(0, 1, 2, 3)); | ||
final List<Code.Color> expectedColors = List.of(Code.Color.Green, Code.Color.Red, Code.Color.Blue, | ||
Code.Color.Yellow); | ||
|
||
assertEquals(expectedColors, code.getColors()); | ||
} | ||
|
||
@Test | ||
void testGetColor() { | ||
final Code code = new Code(List.of(0, 1, 2, 3)); | ||
final List<Code.Color> expectedColors = List.of(Code.Color.Green, Code.Color.Red, Code.Color.Blue, | ||
Code.Color.Yellow); | ||
|
||
for (int i = 0; i < Mastermind.CODE_LENGTH; ++i) { | ||
assertEquals(expectedColors.get(i), code.getColor(i)); | ||
} | ||
} | ||
|
||
@Test | ||
void testGetColors() { | ||
final Code code = new Code(List.of(0, 1, 2, 3)); | ||
final List<Code.Color> expectedColors = List.of(Code.Color.Green, Code.Color.Red, Code.Color.Blue, | ||
Code.Color.Yellow); | ||
|
||
assertEquals(expectedColors, code.getColors()); | ||
} | ||
|
||
@Test | ||
void testGetOccurrences() { | ||
final Code code = new Code(List.of(0, 1, 2, 3)); | ||
HashMap<Code.Color, Integer> expectedOccurrences = new HashMap<>(4); | ||
expectedOccurrences.put(Code.Color.Green, 1); | ||
expectedOccurrences.put(Code.Color.Red, 1); | ||
expectedOccurrences.put(Code.Color.Blue, 1); | ||
expectedOccurrences.put(Code.Color.Yellow, 1); | ||
|
||
assumeTrue(code.getOccurrences().equals(expectedOccurrences)); | ||
} | ||
} |