Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Project names are matched exactly, including capitalization and spaces. `view "m
You'll be prompted to enter:
- Project name and description
- Detailed scoring for each category (1-5 scale): each category asks four questions, and its score is their average, rounded to the nearest whole number
- Each answer must be a whole number from 1 to 5. Any other answer prints `Invalid score. Must be between 1 and 5.` (or `Invalid score. Must be a number between 1 and 5.` when it is not a number), and that category's four questions are asked again from the first; answers already given for it are discarded
- Each answer must be a whole number from 1 to 5; spaces before or after it are ignored. Any other answer prints `Invalid score. Must be between 1 and 5.` (or `Invalid score. Must be a number between 1 and 5.` when it is not a number), and that category's four questions are asked again from the first; answers already given for it are discarded
- Entering `q` or `quit` at any prompt (or pressing Ctrl-D) cancels creation without saving anything
- Parpt will then:
- Calculate ICE and RICE scores
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ private int getAverageScore(String[] prompts) throws InvalidScoreException, Crea
int total = 0;
for (String prompt : prompts) {
try {
int score = Integer.parseInt(readInput(prompt));
// Surrounding whitespace is treated as a stray keystroke, as it is for quit tokens
int score = Integer.parseInt(readInput(prompt).trim());
if (!InputValidator.isValidScore(score)) {
throw new InvalidScoreException("Invalid score. Must be between 1 and 5.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,26 @@ void testNonNumericAnswerReprompts() throws Exception {
assertEquals(4, projectService.getProject("Numeric Project").getEffort());
}

@Test
void testScoreAnswerWithSurroundingWhitespaceIsAccepted() throws Exception {
String[] reachPrompts = promptProperties.getReach();
String[] paddedAnswers = {" 3 ", "3\t", " 3", "3 "};
for (int i = 0; i < reachPrompts.length; i++) {
// A second ask quits, so a rejected padded answer fails the assertion instead of looping
when(inputProvider.readLine(reachPrompts[i])).thenReturn(paddedAnswers[i], "q");
}

String output = captureStandardOutput(() -> assertEquals(
"Project created successfully: Padded Project\nICE Score: 125.00\nRICE Score: 15.00",
command.execute("Padded Project", "Padded Description", 5, 5, 5, null, 5)));

assertFalse(output.contains("Invalid score"));
for (String prompt : reachPrompts) {
verify(inputProvider, times(1)).readLine(prompt);
}
assertEquals(3, projectService.getProject("Padded Project").getReach());
}

@Test
void testTakenNameAtPromptIsRejectedBeforeAnyFurtherQuestion() throws Exception {
projectService.createProject("Existing Project", "Original Description", 1, 1, 1, 1, 1);
Expand Down
Loading