-
Notifications
You must be signed in to change notification settings - Fork 22
Assignment1 #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: Assignment1
Are you sure you want to change the base?
Assignment1 #20
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shows only Program.cs was updated, I would suggest adding unit tests for all your changes as well, to ensure these method changes are doing what you expect. I do like the changes you made though
Assignment Details:
Pull Request title includes "Assignment 1" in the title ✔
Partner has also made a commit ✔ (technically not, but instructor approval is stated)
Pull Request targets Assignment 1 branch ✔
Issue 1: Application no longer crashes ✔
Issue 2: Unit test properly passes
Extra Credit
Come up with a new feature for the application
Issue 3: Add a new feature request implemented
Issue 3: Feature request unit tested ❌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I learned from how you fixed the code and used some of your improvements to enhance my own assignment. One thing I noticed: I don’t see any tests for the new changes (like parsing input, GetGuessIndexFromUser, etc.). Make sure to add some unit tests to cover these.
Assignment Details:
Pull Request title includes "Assignment 1" in the title ✔
Partner has also made a commit ✔
Pull Request targets Assignment 1 branch ✔
Issue 1: Application no longer crashes ✔
Issue 2: Unit test properly passes ❌
Extra Credit:
Come up with a new feature for the application
Issue 3: Add a new feature request implemented ✔
Issue 3: Feature request unit tested ❌
First off great job man! I love how you went back and improved the some of the starter code with better syntax, something I'm definitely gonna go back and do for my projects revisions. With your new implementations, like the others have stated, it would be good practice to test those methods. Great Job! Assignment Details: |
If the trivia file isn’t there, the program will crash with an unclear error. By checking it before that happens, you can let the user know what the issue is.
All in all, it's just dealing with edge cases and isn't specifically necessary for the code in the form that it is right now. If you don't find it necessary- feel free to ignore the advice. |
Right now the code uses a for loop, but since there isn't really any reason to set the specific index and stop at a certain point, foreach might be better. It'll be simpler and cleaner as well.
|
Towards the end of the Program.cs file, there are some unnecessary blank lines. Though this isn't a big deal, it would probably look better without them. Otherwise, the code looks clean, well maintained, and anything else that could be brought up regarding the code would be related to preference, or edge casing which wouldn't even be necessary in this specific program. Looks like good work to me! |
|
||
string answer1 = lines[lineIndex + 1].Trim(); | ||
string answer2 = lines[lineIndex + 2].Trim(); | ||
string answer3 = lines[lineIndex + 3].Trim(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're doing the same operation 3 times here, this could be done better with a for loop which would cut down on repetition and make it easier to add more answer options in the future. This change would also require updating how you assign the answers to your question object.
There was a problem hiding this 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 refactors a Princess Bride trivia game application with improvements to user input handling, string formatting, and code organization. The changes focus on making the code more robust and maintainable.
- Improved string formatting by replacing concatenation with string interpolation
- Enhanced input validation and error handling for user guesses and question data
- Added better parsing logic with type safety and data validation
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
public static bool DisplayResult(string userGuess, Question question) | ||
{ | ||
|
||
if (!int.TryParse((userGuess ?? string.Empty).Trim(), out int guess1Based)) | ||
{ | ||
Console.WriteLine("Please enter 1, 2, or 3:"); | ||
return false; | ||
} | ||
return DisplayResult(guess1Based, question); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method creates a duplicate overload that's only used internally and adds confusion. The validation logic should be moved to GetGuessIndexFromUser() which already handles this properly, and this overload should be removed to avoid code duplication.
public static bool DisplayResult(string userGuess, Question question) | |
{ | |
if (!int.TryParse((userGuess ?? string.Empty).Trim(), out int guess1Based)) | |
{ | |
Console.WriteLine("Please enter 1, 2, or 3:"); | |
return false; | |
} | |
return DisplayResult(guess1Based, question); | |
} |
Copilot uses AI. Check for mistakes.
if (!int.TryParse(question.CorrectAnswerIndex?.Trim(), out int correct1Based)) | ||
{ | ||
Console.WriteLine("Question data invalid."); | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The validation of question data should occur during loading in LoadQuestions() rather than during each question display. This would fail fast on invalid data and avoid repeated validation during gameplay.
Copilot uses AI. Check for mistakes.
|
||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Remove the excessive blank lines before the return statement. This violates common C# formatting conventions and reduces code readability.
Copilot uses AI. Check for mistakes.
Pull Request title includes "Assignment 1" in the title ✔ It looks like most of the formatting issues have already been addressed by other reviews, and still nothing bad for a one-day turnaround. The added feature is also a nice touch, but as observed, test-driven development makes writing the code first a bit like putting the chicken before the egg (so to speak). |
SummarySummary
CoveragePrincessBrideTrivia - 51%
|
Thanks for the notes guys I have a very bad habit of never writing tests even though I know the importance of it so wrote a couple tests to cover the things I added such as making sure not to crash on dividing by zero and checking the override function as well. |
Thank you for the helpful advice! I'll make sure to be careful |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignment Details
- Pull Request title includes "Assignment 1" in the title ✔
- Partner has also made a commit ✔❌ not necessary with one partner
- Pull Request targets Assignment 1 branch ✔
- Issue 1: Application no longer crashes ✔
- Issue 2: Unit test properly passes ✔
Extra Credit
- Come up with a new feature for the application
- Issue 3: Add a new feature request implemented ✔
- Issue 3: Feature request unit tested ✔
[TestMethod] | ||
public void DisplayResult_IntOverload_ReturnsTrueWhenGuessMatches() | ||
{ | ||
|
||
var q = new Question { CorrectAnswerIndex = "3" }; | ||
bool result = Program.DisplayResult(3, q); | ||
Assert.IsTrue(result); | ||
} | ||
|
||
[TestMethod] | ||
public void DisplayResult_IntOverload_ReturnsFalseWhenGuessDoesNotMatch() | ||
{ | ||
var q = new Question { CorrectAnswerIndex = "2" }; | ||
bool result = Program.DisplayResult(1, q); | ||
Assert.IsFalse(result); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like formatting/indentation is off here. I see a few other places as well. Maybe look into auto formatting or the format shortcut for Visual Studio or VS Code or whatever editor you use :)
|
||
|
||
public static bool DisplayResult(string userGuess, Question question) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ex: Same weird formatting here. This'll be the last reference I make, though I see more.
int lineIndex = i * 5; | ||
string questionText = lines[lineIndex]; | ||
|
||
string answer1 = lines[lineIndex + 1]; | ||
string answer2 = lines[lineIndex + 2]; | ||
string answer3 = lines[lineIndex + 3]; | ||
|
||
string correctAnswerIndex = lines[lineIndex + 4]; | ||
|
||
Question question = new(); | ||
question.Text = questionText; | ||
question.Answers = new string[3]; | ||
question.Answers[0] = answer1; | ||
question.Answers[1] = answer2; | ||
question.Answers[2] = answer3; | ||
question.CorrectAnswerIndex = correctAnswerIndex; | ||
int lineIndex = i * block; | ||
|
||
string questionText = lines[lineIndex].Trim(); | ||
|
||
string answer1 = lines[lineIndex + 1].Trim(); | ||
string answer2 = lines[lineIndex + 2].Trim(); | ||
string answer3 = lines[lineIndex + 3].Trim(); | ||
|
||
string correctAnswerIndex = lines[lineIndex + 4].Trim(); | ||
|
||
Question question = new() | ||
{ | ||
Text = questionText, | ||
Answers = new[] { answer1, answer2, answer3 }, | ||
// store the raw 1-based index string; we parse later | ||
CorrectAnswerIndex = correctAnswerIndex | ||
}; | ||
|
||
|
||
questions[i] = question; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the refactoring here. Definitely makes sense, but also agree with Korbin on possibly doing a for loop for the three answers. It's about the same amount of work, but it'd be cleaner IMO.
Question[] questions = new Question[lines.Length / 5]; | ||
// Each question block is 5 lines: Q, A1, A2, A3, CorrectIndex | ||
int block = 5; | ||
if (lines.Length % block != 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious what would happen if there was an extra newline. Might break this.
} | ||
} | ||
|
||
public static bool DisplayResult(int userGuessIndex1Based, Question question) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I probably would use "One" here instead of "1". I'm not sure there's a guideline against having numbers in variable names (@BenjaminMichaelis correct me if I'm wrong), but it'd be clearer to swap to "One". It took me a couple reads to see that it was a "1" and not a lower-case "L" or upper-case "i".
@BraydenMcMahon make sure to respond to/resolve all peer review comments - including Copilot's review. |
Didnt have a partner since working on a teams problem and Benjamin said that was ok in class today just for this one.