Skip to content

Conversation

@emancilla77
Copy link

Closes: #44

@jody jody requested a review from Copilot November 1, 2025 22:12
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a CodeGenerator class to generate random 4-digit codes for the MasterMind game and introduces comprehensive unit tests to verify the code generation behavior.

  • Adds CodeGenerator class with generateCode() method that creates random 4-digit codes using digits 0-9
  • Adds MasterMindGameTest with three test cases validating code length, symbol validity, and randomness distribution

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
MasterMindGame.java Adds CodeGenerator class with static method to generate random 4-digit codes and imports java.util.*
MasterMindGameTest.java New test file with three tests validating code generation properties

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

void isExactlyFourSymbols() {

String code = CodeGenerator.generateCode();
assertEquals(4, code.length(), "Code should be 4 symbol long");
Copy link

Copilot AI Nov 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling of 'symbol' to 'symbols' in the error message.

Suggested change
assertEquals(4, code.length(), "Code should be 4 symbol long");
assertEquals(4, code.length(), "Code should be 4 symbols long");

Copilot uses AI. Check for mistakes.
Comment on lines +31 to +38
String code = "";

for (int i=0; i < 4; i++) {
int index = random.nextInt(numbers.length());
code = code + numbers.charAt(index);
}

return code;
Copy link

Copilot AI Nov 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String concatenation in a loop is inefficient. Use StringBuilder instead to avoid creating multiple intermediate String objects.

Suggested change
String code = "";
for (int i=0; i < 4; i++) {
int index = random.nextInt(numbers.length());
code = code + numbers.charAt(index);
}
return code;
StringBuilder code = new StringBuilder();
for (int i=0; i < 4; i++) {
int index = random.nextInt(numbers.length());
code.append(numbers.charAt(index));
}
return code.toString();

Copilot uses AI. Check for mistakes.

class CodeGenerator {
public static String generateCode() {
Random random = new Random();
Copy link

Copilot AI Nov 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating a new Random instance on every method call is inefficient. Consider making it a static field or use ThreadLocalRandom.current() for better performance.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@jody jody left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verify that coding conventions are followed.

Here's a report excerpt from Checkstyle (via ant checkstyle):

File ConsoleGameHub/MasterMindGame.java
Error Description :: Line
Using the '.*' form of import should be avoided - java.util.*.:: 2
Missing a Javadoc comment. :: 27 
Utility classes should not have a public or default constructor. :: 27
Missing a Javadoc comment. :: 28
'=' is not preceded with whitespace. :: 33
'=' is not followed by whitespace. :: 33
'4' is a magic number. :: 33

File ConsoleGameHub/MasterMindGameTest.java
Error Description :: Line
File does not end with a newline. :: 0
Using the '.*' form of import should be avoided - org.junit.jupiter.api.Assertions.*. :: 2
Using the '.*' form of import should be avoided - java.util.*. :: 4
Using the '.*' form of import should be avoided - java.util.regex.*. :: 5
Line has trailing spaces. :: 10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[USER STORY] Generate a random, length 4, secret code for Mastermind

3 participants