Skip to content
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

Branch max score validation #213

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
6 changes: 6 additions & 0 deletions src/main/java/tutorlink/command/AddComponentCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class AddComponentCommand extends Command {

public static final String[] ARGUMENT_PREFIXES = {"c/", "w/", "m/"};
public static final String COMMAND_WORD = "add_component";
private static final double MAX_SCORE = 10000.0;

/**
* Executes the add component command, creating a new component with the specified name,
Expand Down Expand Up @@ -128,6 +129,11 @@ private double parseMaxScore(String maxScoreNumber) throws IllegalValueException
if (maxScore < 0.0) {
throw new IllegalValueException(Commons.ERROR_INVALID_MAX_SCORE);
}

if (maxScore > MAX_SCORE) {
throw new IllegalValueException(Commons.ERROR_INVALID_MAX_SCORE);
}

return maxScore;
} catch (NumberFormatException e) {
throw new IllegalValueException(Commons.ERROR_INVALID_MAX_SCORE);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/tutorlink/commons/Commons.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class Commons {
"in list!";
public static final String ERROR_INVALID_WEIGHTAGE = "Error! Weightage must be integer that is between 0 and 100!";
public static final String ERROR_INVALID_MAX_SCORE =
"Error! Max Score must be double that is more than or equal to 0!";
"Error! Max Score must be double that is between 0 and 10000!";
//@@author RCPilot1604
public static final String ERROR_INVALID_TOTAL_WEIGHTING = "Error! Total weighting must add up to 100%%.\n" +
"Current weighting (after addition): %s%%";
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/tutorlink/command/AddComponentCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,13 @@ void update_gpa_accordingly () {
command.execute(appState, arguments);
assertEquals(student.getPercentageScore(), 50);
}

@Test
void execute_maxScoreLargerThanMax_exception() {
arguments.put("c/", "Quiz 1");
arguments.put("w/", "100");
arguments.put("m/", "20000");
assertThrows(IllegalValueException.class, () -> command.execute(appState, arguments));
}
}
//@@author
Loading