diff --git a/.gitignore b/.gitignore index 871fe81614..fa6282526d 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ src/main/META-INF/ /data /text-ui-test/data +text-ui-test/input.txt diff --git a/src/main/java/tutorlink/command/AddComponentCommand.java b/src/main/java/tutorlink/command/AddComponentCommand.java index ab65c50dd7..c29061cf16 100644 --- a/src/main/java/tutorlink/command/AddComponentCommand.java +++ b/src/main/java/tutorlink/command/AddComponentCommand.java @@ -23,7 +23,7 @@ public CommandResult execute(AppState appState, HashMap hashmap) throw new IllegalValueException(Commons.ERROR_NULL); } - double weightage = convertWeightageToValidDouble(weightageNumber); + int weightage = convertWeightageToValidInt(weightageNumber); double maxScore = convertMaxScoreToValidDouble(maxScoreNumber); appState.components.addComponent(new Component(componentName, maxScore, weightage)); @@ -31,10 +31,10 @@ public CommandResult execute(AppState appState, HashMap hashmap) componentName, weightageNumber, maxScoreNumber)); } - private static double convertWeightageToValidDouble(String weightageNumber) { + private static int convertWeightageToValidInt(String weightageNumber) { try { - double weightage = Double.parseDouble(weightageNumber); - if (weightage < 0.0 || weightage > 1.0) { + int weightage =Integer.parseInt(weightageNumber); + if (weightage < 0 || weightage > 100) { throw new IllegalValueException(Commons.ERROR_INVALID_WEIGHTAGE); } return weightage; diff --git a/src/main/java/tutorlink/command/AddGradeCommand.java b/src/main/java/tutorlink/command/AddGradeCommand.java index e3291b64af..b04c33f6ee 100644 --- a/src/main/java/tutorlink/command/AddGradeCommand.java +++ b/src/main/java/tutorlink/command/AddGradeCommand.java @@ -15,6 +15,8 @@ import tutorlink.result.CommandResult; import tutorlink.student.Student; import java.util.HashMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import static tutorlink.lists.StudentList.STUDENT_NOT_FOUND; @@ -31,6 +33,12 @@ public CommandResult execute(AppState appstate, HashMap hashmap) if (matricNumber == null || componentDescription == null || scoreNumber == null) { throw new IllegalValueException(Commons.ERROR_NULL); } + matricNumber = matricNumber.toUpperCase(); + Pattern pattern = Pattern.compile(Commons.MATRIC_NUMBER_REGEX); + Matcher matcher = pattern.matcher(matricNumber); + if (!matcher.find()) { + throw new IllegalValueException(Commons.ERROR_ILLEGAL_MATRIC_NUMBER); + } Component component = findComponentFromComponents(appstate, componentDescription); @@ -83,7 +91,7 @@ private static Student findStudentFromStudents(AppState appstate, String matricN private static Component findComponentFromComponents(AppState appstate, String componentDescription) { //Get component object using String componentDescription - ComponentList componentFilteredList = appstate.components.findComponent(componentDescription.toUpperCase()); + ComponentList componentFilteredList = appstate.components.findComponent(componentDescription); Component component; if (componentFilteredList.size() == 1) { component = componentFilteredList.getComponentArrayList().get(0); diff --git a/src/main/java/tutorlink/command/AddStudentCommand.java b/src/main/java/tutorlink/command/AddStudentCommand.java index 843d0edc8f..056ddf656d 100644 --- a/src/main/java/tutorlink/command/AddStudentCommand.java +++ b/src/main/java/tutorlink/command/AddStudentCommand.java @@ -7,6 +7,8 @@ import tutorlink.exceptions.IllegalValueException; import tutorlink.exceptions.TutorLinkException; import tutorlink.result.CommandResult; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class AddStudentCommand extends Command { @@ -20,6 +22,12 @@ public CommandResult execute(AppState appState, HashMap hashmap) if (matricNumber == null || name == null) { throw new IllegalValueException(Commons.ERROR_NULL); } + matricNumber = matricNumber.toUpperCase(); + Pattern pattern = Pattern.compile(Commons.MATRIC_NUMBER_REGEX); + Matcher matcher = pattern.matcher(matricNumber); + if (!matcher.find()) { + throw new IllegalValueException(Commons.ERROR_ILLEGAL_MATRIC_NUMBER); + } appState.students.addStudent(matricNumber, name); return new CommandResult(String.format(Commons.ADD_STUDENT_SUCCESS, name, matricNumber)); } diff --git a/src/main/java/tutorlink/command/DeleteGradeCommand.java b/src/main/java/tutorlink/command/DeleteGradeCommand.java index 16b58955d3..4b0061024c 100644 --- a/src/main/java/tutorlink/command/DeleteGradeCommand.java +++ b/src/main/java/tutorlink/command/DeleteGradeCommand.java @@ -1,6 +1,8 @@ package tutorlink.command; import java.util.HashMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import tutorlink.appstate.AppState; import tutorlink.commons.Commons; @@ -24,7 +26,12 @@ public CommandResult execute(AppState appState, HashMap hashmap) if (matricNumber == null || componentDescription == null) { throw new IllegalValueException(Commons.ERROR_NULL); } - + matricNumber = matricNumber.toUpperCase(); + Pattern pattern = Pattern.compile(Commons.MATRIC_NUMBER_REGEX); + Matcher matcher = pattern.matcher(matricNumber); + if (!matcher.find()) { + throw new IllegalValueException(Commons.ERROR_ILLEGAL_MATRIC_NUMBER); + } //Check number of students with matricNumber StudentList filteredList = appState.students.findStudentByMatricNumber(matricNumber); diff --git a/src/main/java/tutorlink/command/DeleteStudentCommand.java b/src/main/java/tutorlink/command/DeleteStudentCommand.java index 40f51a6afd..4ce29d608b 100644 --- a/src/main/java/tutorlink/command/DeleteStudentCommand.java +++ b/src/main/java/tutorlink/command/DeleteStudentCommand.java @@ -1,6 +1,8 @@ package tutorlink.command; import java.util.HashMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import tutorlink.appstate.AppState; import tutorlink.commons.Commons; @@ -19,6 +21,12 @@ public CommandResult execute(AppState appState, HashMap hashmap) if (matricNumber == null) { throw new IllegalValueException(Commons.ERROR_NULL); } + matricNumber = matricNumber.toUpperCase(); + Pattern pattern = Pattern.compile(Commons.MATRIC_NUMBER_REGEX); + Matcher matcher = pattern.matcher(matricNumber); + if (!matcher.find()) { + throw new IllegalValueException(Commons.ERROR_ILLEGAL_MATRIC_NUMBER); + } appState.students.deleteStudent(matricNumber); appState.grades.deleteGradesByMatric(matricNumber); return new CommandResult(String.format(Commons.DELETE_STUDENT_SUCCESS, matricNumber)); diff --git a/src/main/java/tutorlink/commons/Commons.java b/src/main/java/tutorlink/commons/Commons.java index 4b046708b1..2c0904535d 100644 --- a/src/main/java/tutorlink/commons/Commons.java +++ b/src/main/java/tutorlink/commons/Commons.java @@ -5,6 +5,11 @@ public class Commons { public static final String ERROR_NULL = "Error! Null parameter passed!"; //@@author RCPilot1604 + + //Input Validation + public static final String MATRIC_NUMBER_REGEX = "A\\d{7}[A-Z]"; + public static final String ERROR_ILLEGAL_MATRIC_NUMBER = "Error! Ensure matric " + + "number is of the form A\\d{7}[A-Z] (case insensitive)"; //Student public static final String ADD_STUDENT_SUCCESS = "Student %s (%s) added successfully!"; public static final String ERROR_DUPLICATE_STUDENT = @@ -27,7 +32,7 @@ public class Commons { public static final String DELETE_COMPONENT_SUCCESS = "Component %s successfully deleted"; public static final String ERROR_COMPONENT_NOT_FOUND = "Error! Component (Name %s) not found"; public static final String ERROR_DUPLICATE_COMPONENT = "Error! Component (Name %s) already exists in the list!"; - public static final String ERROR_INVALID_WEIGHTAGE = "Error! Weightage must be double that is between 0 and 1!"; + 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!"; diff --git a/src/main/java/tutorlink/component/Component.java b/src/main/java/tutorlink/component/Component.java index 9c3eb95849..075321b501 100644 --- a/src/main/java/tutorlink/component/Component.java +++ b/src/main/java/tutorlink/component/Component.java @@ -4,9 +4,9 @@ public class Component { private String name; private double maxScore; - private double weight; + private int weight; - public Component(String name, double maxScore, double weight) { + public Component(String name, double maxScore, int weight) { this.name = name; this.maxScore = maxScore; this.weight = weight; diff --git a/src/main/java/tutorlink/lists/ComponentList.java b/src/main/java/tutorlink/lists/ComponentList.java index ee1ef8ecc4..aeb6705a23 100644 --- a/src/main/java/tutorlink/lists/ComponentList.java +++ b/src/main/java/tutorlink/lists/ComponentList.java @@ -58,7 +58,8 @@ public void deleteComponent(Component component) throws ComponentNotFoundExcepti @Override public String toString() { - return IntStream.range(0, componentArrayList.size()) + return "\t" + + IntStream.range(0, componentArrayList.size()) .mapToObj(i -> (i + 1) + ": " + componentArrayList.get(i)) .collect(Collectors.joining("\n\t")); } diff --git a/src/main/java/tutorlink/lists/GradeList.java b/src/main/java/tutorlink/lists/GradeList.java index 244b91d679..5abc591bb1 100644 --- a/src/main/java/tutorlink/lists/GradeList.java +++ b/src/main/java/tutorlink/lists/GradeList.java @@ -36,10 +36,9 @@ public GradeList(ArrayList gradeArrayList) { //@@author RCPilot1604 public void deleteGrade(String matricNumber, String componentDescription) throws GradeNotFoundException { matricNumber = matricNumber.toUpperCase(); - componentDescription = componentDescription.toUpperCase(); for (Grade grade : gradeArrayList) { - if (grade.getStudent().getMatricNumber().equals(matricNumber) - && grade.getComponent().getName().toUpperCase().equals(componentDescription)) { + if (grade.getStudent().getMatricNumber().equals(matricNumber.toUpperCase()) + && grade.getComponent().getName().toUpperCase().equals(componentDescription.toUpperCase())) { gradeArrayList.remove(grade); return; } diff --git a/src/main/java/tutorlink/parser/Parser.java b/src/main/java/tutorlink/parser/Parser.java index 92801f8813..64d82eff87 100644 --- a/src/main/java/tutorlink/parser/Parser.java +++ b/src/main/java/tutorlink/parser/Parser.java @@ -10,6 +10,7 @@ import tutorlink.command.FindStudentCommand; import tutorlink.command.InvalidCommand; import tutorlink.command.ListComponentCommand; +import tutorlink.command.ListGradeCommand; import tutorlink.command.ListStudentCommand; import tutorlink.command.AddGradeCommand; @@ -62,6 +63,9 @@ public Command getCommand(String line) { case ListComponentCommand.COMMAND_WORD: return new ListComponentCommand(); + case ListGradeCommand.COMMAND_WORD: + return new ListGradeCommand(); + case ExitCommand.COMMAND_WORD: return new ExitCommand(); // Lists all students diff --git a/src/main/java/tutorlink/storage/ComponentStorage.java b/src/main/java/tutorlink/storage/ComponentStorage.java index 482ced1b4b..fb59d912a8 100644 --- a/src/main/java/tutorlink/storage/ComponentStorage.java +++ b/src/main/java/tutorlink/storage/ComponentStorage.java @@ -33,7 +33,7 @@ private Component getComponentFromFileLine(String fileLine) { String[] stringParts = fileLine.split(READ_DELIMITER); String name = stringParts[0]; double maxScore = Double.parseDouble(stringParts[1]); - double weight = Double.parseDouble(stringParts[2]); + int weight = Integer.parseInt(stringParts[2]); return new Component(name, maxScore, weight); } diff --git a/src/test/java/tutorlink/command/AddComponentCommandTest.java b/src/test/java/tutorlink/command/AddComponentCommandTest.java index 1c464d9447..a5791afbb0 100644 --- a/src/test/java/tutorlink/command/AddComponentCommandTest.java +++ b/src/test/java/tutorlink/command/AddComponentCommandTest.java @@ -4,6 +4,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import tutorlink.appstate.AppState; +import tutorlink.commons.Commons; import tutorlink.exceptions.IllegalValueException; import tutorlink.result.CommandResult; @@ -29,11 +30,11 @@ void setup() { @Test void execute_validArguments_componentAddedSuccessfully() { arguments.put("c/", "Quiz 1"); - arguments.put("w/", "0.3"); + arguments.put("w/", "30"); arguments.put("m/", "100"); CommandResult result = command.execute(appState, arguments); assertNotNull(result); - assertEquals("Component Quiz 1 of weight 0.3, with max score 100 added successfully!", result.toString()); + assertEquals("Component Quiz 1 of weight 30, with max score 100 added successfully!", result.toString()); assertEquals(1, appState.components.getComponentArrayList().size()); } @@ -59,13 +60,13 @@ void execute_missingWeightageArgument_throwsIllegalValueException() { @Test void execute_extraArgument_componentAddedSuccessfully() { arguments.put("c/", "Quiz 1"); - arguments.put("w/", "0.5"); + arguments.put("w/", "50"); arguments.put("m/", "100"); arguments.put("extra/", "extra value"); CommandResult result = command.execute(appState, arguments); assertNotNull(result); - assertEquals("Component Quiz 1 of weight 0.5, with max score 100 added successfully!", result.toString()); + assertEquals("Component Quiz 1 of weight 50, with max score 100 added successfully!", result.toString()); assertEquals(1, appState.components.getComponentArrayList().size()); } @@ -78,7 +79,7 @@ void execute_weightageOutOfRange_throwsIllegalValueException() { IllegalValueException exception = assertThrows(IllegalValueException.class, () -> { command.execute(appState, arguments); }); - assertEquals("Error! Weightage must be double that is between 0 and 1!", exception.getMessage()); + assertEquals(Commons.ERROR_INVALID_WEIGHTAGE, exception.getMessage()); } @Test @@ -90,7 +91,7 @@ void execute_negativeMaxScore_throwsIllegalValueException() { IllegalValueException exception = assertThrows(IllegalValueException.class, () -> { command.execute(appState, arguments); }); - assertEquals("Error! Max Score must be double that is more than or equal to 0!", exception.getMessage()); + assertEquals(Commons.ERROR_INVALID_WEIGHTAGE, exception.getMessage()); } @Test @@ -102,7 +103,7 @@ void execute_weightageNotDouble_throwsIllegalValueException() { IllegalValueException exception = assertThrows(IllegalValueException.class, () -> { command.execute(appState, arguments); }); - assertEquals("Error! Weightage must be double that is between 0 and 1!", exception.getMessage()); + assertEquals(Commons.ERROR_INVALID_WEIGHTAGE, exception.getMessage()); } @Test @@ -114,7 +115,7 @@ void execute_maxScoreNotDouble_throwsIllegalValueException() { IllegalValueException exception = assertThrows(IllegalValueException.class, () -> { command.execute(appState, arguments); }); - assertEquals("Error! Max Score must be double that is more than or equal to 0!", exception.getMessage()); + assertEquals(Commons.ERROR_INVALID_WEIGHTAGE, exception.getMessage()); } } //@@author diff --git a/src/test/java/tutorlink/command/AddGradeCommandTest.java b/src/test/java/tutorlink/command/AddGradeCommandTest.java index 6d0e56565f..160d2bf889 100644 --- a/src/test/java/tutorlink/command/AddGradeCommandTest.java +++ b/src/test/java/tutorlink/command/AddGradeCommandTest.java @@ -41,7 +41,7 @@ void addGrade_allArgumentsComponent_successful() { //Create component String examName = "Exam Under Test"; double examMaxScore = 100.0; - double examWeight = 50.0; + int examWeight = 50; Component exam = new Component(examName,examMaxScore, examWeight); appState.components.addComponent(exam); @@ -83,7 +83,7 @@ void addGrade_missingComponentDescriptionComponent_illegalValueExceptionThrown() //Create component String assignmentName = "Assignment Under Test"; double assignmentMaxScore = 100.0; - double assignmentWeight = 50.0; + int assignmentWeight = 50; Component assignment = new Component(assignmentName,assignmentMaxScore, assignmentWeight); appState.components.addComponent(assignment); @@ -123,7 +123,7 @@ void addGrade_nonDoubleScoreComponent_illegalValueExceptionThrown() { //Create component String examName = "Exam Under Test"; double examMaxScore = 100.0; - double examWeight = 50.0; + int examWeight = 50; Component exam = new Component(examName,examMaxScore, examWeight); appState.components.addComponent(exam); @@ -161,7 +161,7 @@ void addGrade_scoreMoreThanMax_throwIllegalValueException() { //Create component String examName = "Exam Under Test"; double examMaxScore = 100.0; - double examWeight = 50.0; + int examWeight = 50; Component exam = new Component(examName,examMaxScore, examWeight); appState.components.addComponent(exam); @@ -199,7 +199,7 @@ void addGrade_scoreNegative_throwIllegalValueException() { //Create component String examName = "Exam Under Test"; double examMaxScore = 100.0; - double examWeight = 50.0; + int examWeight = 50; Component exam = new Component(examName,examMaxScore, examWeight); appState.components.addComponent(exam); @@ -260,7 +260,7 @@ void addGrade_studentNotFoundComponent_throwStudentNotFoundException() { //Create component String assignmentName = "Assignment Under Test"; double assignmentMaxScore = 100.0; - double assignmentWeight = 50.0; + int assignmentWeight = 50; Component assignment = new Component(assignmentName,assignmentMaxScore, assignmentWeight); appState.components.addComponent(assignment); @@ -298,7 +298,7 @@ void addGrade_duplicateGradeComponentDiffScores_throwDuplicateGradeException() { //Create Component component String examName = "Test"; double examMaxScore = 100.0; - double examWeight = 50.0; + int examWeight = 50; Component exam = new Component(examName,examMaxScore, examWeight); appState.components.addComponent(exam); diff --git a/src/test/java/tutorlink/command/DeleteComponentCommandTest.java b/src/test/java/tutorlink/command/DeleteComponentCommandTest.java index 91df5db05d..136d2cee08 100644 --- a/src/test/java/tutorlink/command/DeleteComponentCommandTest.java +++ b/src/test/java/tutorlink/command/DeleteComponentCommandTest.java @@ -22,9 +22,9 @@ public class DeleteComponentCommandTest { @BeforeEach void setup() { appState = new AppState(); - appState.components.addComponent(new Component("finals", 40.0, 0.4)); - appState.components.addComponent(new Component("iP", 20.0, 0.1)); - appState.components.addComponent(new Component("lectures", 10.0, 0.1)); + appState.components.addComponent(new Component("finals", 40.0, 40)); + appState.components.addComponent(new Component("iP", 20.0, 10)); + appState.components.addComponent(new Component("lectures", 10.0, 10)); } @Test diff --git a/src/test/java/tutorlink/command/DeleteGradeCommandTest.java b/src/test/java/tutorlink/command/DeleteGradeCommandTest.java index bf512318ec..1719540b0c 100644 --- a/src/test/java/tutorlink/command/DeleteGradeCommandTest.java +++ b/src/test/java/tutorlink/command/DeleteGradeCommandTest.java @@ -51,7 +51,7 @@ private GradeList addGradeForTest(Parser parser, AppState appState, String compo //Create component String examName = componentName; double examMaxScore = 100.0; - double examWeight = 50.0; + int examWeight = 50; Component exam = new Component(examName,examMaxScore, examWeight); appState.components.addComponent(exam); diff --git a/src/test/java/tutorlink/command/DeleteStudentCommandTest.java b/src/test/java/tutorlink/command/DeleteStudentCommandTest.java index 19d5cdb3dd..5bec0a0f6e 100644 --- a/src/test/java/tutorlink/command/DeleteStudentCommandTest.java +++ b/src/test/java/tutorlink/command/DeleteStudentCommandTest.java @@ -32,11 +32,11 @@ void setup() { appState.students.addStudent("A2468102C", "Arthur Mueller"); appState.grades.addGrade(new Grade(new Component("Take Home Quiz 1", 10.0, - 0.2), new Student("A1234567X", "John Doe"), 7.0)); + 20), new Student("A1234567X", "John Doe"), 7.0)); appState.grades.addGrade(new Grade(new Component("Take Home Quiz 2", 10.0, - 0.2), new Student("A1234567X", "John Doe"), 9.0)); + 20), new Student("A1234567X", "John Doe"), 9.0)); appState.grades.addGrade(new Grade(new Component("Take Home Quiz 1", 10.0, - 0.2), new Student("A7654321B", "Jane Smith"), 9.0)); + 20), new Student("A7654321B", "Jane Smith"), 9.0)); } @Test diff --git a/src/test/java/tutorlink/component/ComponentTest.java b/src/test/java/tutorlink/component/ComponentTest.java index 92e266ea0d..c69fdc65ad 100644 --- a/src/test/java/tutorlink/component/ComponentTest.java +++ b/src/test/java/tutorlink/component/ComponentTest.java @@ -13,26 +13,26 @@ public class ComponentTest { @BeforeEach void setup() { - assignment = new Component("Assignment 1", 50.0, 0.3); - exam = new Component("Final Exam", 100.0, 0.4); + assignment = new Component("Assignment 1", 50.0, 30); + exam = new Component("Final Exam", 100.0, 40); } @Test void constructor_validInputs_success() { assertEquals("Assignment 1", assignment.getName()); assertEquals(50.0, assignment.getMaxScore()); - assertEquals(0.3, assignment.getWeight()); + assertEquals(30, assignment.getWeight()); } @Test void equals_sameComponent_returnsTrue() { - Component duplicateAssignment = new Component("Assignment 1", 50.0, 0.3); + Component duplicateAssignment = new Component("Assignment 1", 50.0, 30); assertEquals(assignment, duplicateAssignment); } @Test void equals_differentComponent_returnsFalse() { - Component differentAssignment = new Component("Assignment 2", 50.0, 0.3); + Component differentAssignment = new Component("Assignment 2", 50.0, 30); assertNotEquals(assignment, differentAssignment); assertNotEquals(assignment, exam); assertNotEquals(assignment, null); diff --git a/src/test/java/tutorlink/lists/ComponentListTest.java b/src/test/java/tutorlink/lists/ComponentListTest.java index 83f51fe238..0e9543c83f 100644 --- a/src/test/java/tutorlink/lists/ComponentListTest.java +++ b/src/test/java/tutorlink/lists/ComponentListTest.java @@ -19,9 +19,9 @@ class ComponentListTest { @BeforeEach void setup() { componentList = new ComponentList(); - comp1 = new Component("Homework 1", 30, 0.1); - comp2 = new Component("Homework 2", 30, 0.1); - comp3 = new Component("Finals", 100, 0.5); + comp1 = new Component("Homework 1", 30, 10); + comp2 = new Component("Homework 2", 30, 10); + comp3 = new Component("Finals", 100, 50); } @Test @@ -33,7 +33,7 @@ void addComponent_addOneComponent_success() { @Test void addComponent_addDuplicateComponent_exceptionThrown() { componentList.addComponent(comp1); - Component duplicateComp = new Component("Homework 1", 30, 0.1); + Component duplicateComp = new Component("Homework 1", 30, 10); assertThrows(DuplicateComponentException.class, () -> componentList.addComponent(duplicateComp)); } @@ -57,8 +57,8 @@ void findComponent_findExisting_success() { componentList.addComponent(comp3); ComponentList filteredList = componentList.findComponent("homework"); assertEquals(2, filteredList.size()); - String expectedResult = "1: Homework 1, maxScore = 30.0, weight = 0.1\n" + - "\t2: Homework 2, maxScore = 30.0, weight = 0.1"; + String expectedResult = "\t1: Homework 1, maxScore = 30.0, weight = 10\n" + + "\t2: Homework 2, maxScore = 30.0, weight = 10"; assertEquals(expectedResult, filteredList.toString()); } @@ -74,8 +74,8 @@ void findComponent_findNotInList_exceptionThrown() { void toString_test() { componentList.addComponent(comp1); componentList.addComponent(comp3); - String expectedResult = "1: Homework 1, maxScore = 30.0, weight = 0.1\n" + - "\t2: Finals, maxScore = 100.0, weight = 0.5"; + String expectedResult = "\t1: Homework 1, maxScore = 30.0, weight = 10\n" + + "\t2: Finals, maxScore = 100.0, weight = 50"; assertEquals(expectedResult, componentList.toString()); } } diff --git a/src/test/java/tutorlink/lists/GradeListTest.java b/src/test/java/tutorlink/lists/GradeListTest.java index 1dd5677e3c..442d11fd45 100644 --- a/src/test/java/tutorlink/lists/GradeListTest.java +++ b/src/test/java/tutorlink/lists/GradeListTest.java @@ -27,8 +27,8 @@ void setup() { Student student1 = new Student("A1234567B", "John Doe"); Student student2 = new Student("A7654321B", "Jane Smith"); - Component component1 = new Component("Homework", 100, 0.2); - Component component2 = new Component("Exam", 100, 0.5); + Component component1 = new Component("Homework", 100, 20); + Component component2 = new Component("Exam", 100, 50); grade1 = new Grade(component1, student1, 90.0); grade2 = new Grade(component2, student2, 85.0); @@ -59,7 +59,7 @@ void delete_notFound() { gradeList.deleteGrade("A9999999B", "nonexistentComponent"); } catch (GradeNotFoundException e) { assertEquals( - "Error! Grade for component NONEXISTENTCOMPONENT " + + "Error! Grade for component nonexistentComponent " + "for student A9999999B does not exist in the list!", e.getMessage()); } catch (Exception e) { fail("Expected: StudentNotFoundException, Actual: " + e.getMessage()); diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index c848e22600..47a6b9c105 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -10,5 +10,148 @@ Hello! I'm TutorLink What can I do for you? ------------------------------------------------------------- ------------------------- Result ------------------------- +Student Ethan Chua (A0276007H) added successfully! +------------------------------------------------------------- +------------------------- Result ------------------------- +Student John Doe (A9999999Z) added successfully! +------------------------------------------------------------- +------------------------- Result ------------------------- +Student John Smith (A1111111B) added successfully! +------------------------------------------------------------- +------------------------- Error ------------------------- +Error! Ensure matric number is of the form A\d{7}[A-Z] (case insensitive) +------------------------------------------------------------- +------------------------- Error ------------------------- +Error! Invalid command given! +------------------------------------------------------------- +------------------------- Error ------------------------- +Error! Null parameter passed! +------------------------------------------------------------- +------------------------- Error ------------------------- +Error! Null parameter passed! +------------------------------------------------------------- +------------------------- Error ------------------------- +Error! Invalid command given! +------------------------------------------------------------- +------------------------- Result ------------------------- + 1: Ethan Chua (matric no: A0276007H) + 2: John Doe (matric no: A9999999Z) + 3: John Smith (matric no: A1111111B) +------------------------------------------------------------- +------------------------- Error ------------------------- +Error! Invalid command given! +------------------------------------------------------------- +------------------------- Result ------------------------- +Student A0276007H successfully deleted +------------------------------------------------------------- +------------------------- Error ------------------------- +Error! Student (Matric Number A1234567X) not found +------------------------------------------------------------- +------------------------- Error ------------------------- +Error! Invalid command given! +------------------------------------------------------------- +------------------------- Error ------------------------- +Error! Ensure matric number is of the form A\d{7}[A-Z] (case insensitive) +------------------------------------------------------------- +------------------------- Error ------------------------- +Error! Invalid command given! +------------------------------------------------------------- +------------------------- Result ------------------------- + 1: John Doe (matric no: A9999999Z) + 2: John Smith (matric no: A1111111B) +------------------------------------------------------------- +------------------------- Error ------------------------- +Error! Invalid command given! +------------------------------------------------------------- +------------------------- Result ------------------------- +Component Finals of weight 50, with max score 100 added successfully! +------------------------------------------------------------- +------------------------- Result ------------------------- +Component Quiz of weight 5, with max score 20 added successfully! +------------------------------------------------------------- +------------------------- Error ------------------------- +Error! Weightage must be integer that is between 0 and 100! +------------------------------------------------------------- +------------------------- Result ------------------------- +Component Fail of weight 0, with max score 2 added successfully! +------------------------------------------------------------- +------------------------- Error ------------------------- +Error! Weightage must be integer that is between 0 and 100! +------------------------------------------------------------- +------------------------- Error ------------------------- +Error! Weightage must be integer that is between 0 and 100! +------------------------------------------------------------- +------------------------- Error ------------------------- +Error! Weightage must be integer that is between 0 and 100! +------------------------------------------------------------- +------------------------- Result ------------------------- + 1: Finals, maxScore = 100.0, weight = 50 + 2: Quiz, maxScore = 20.0, weight = 5 + 3: Fail, maxScore = 2.0, weight = 0 +------------------------------------------------------------- +------------------------- Error ------------------------- +Error! Invalid command given! +------------------------------------------------------------- +------------------------- Result ------------------------- +Component Quiz successfully deleted +------------------------------------------------------------- +------------------------- Result ------------------------- + 1: Finals, maxScore = 100.0, weight = 50 + 2: Fail, maxScore = 2.0, weight = 0 +------------------------------------------------------------- +------------------------- Error ------------------------- +Error! Invalid command given! +------------------------------------------------------------- +------------------------- Error ------------------------- +Error! Component Quiz does not exist in the list! +------------------------------------------------------------- +------------------------- Result ------------------------- +Student Ethan Chua (A0276007H) added successfully! +------------------------------------------------------------- +------------------------- Error ------------------------- +Error! Invalid command given! +------------------------------------------------------------- +------------------------- Result ------------------------- + 1: John Doe (matric no: A9999999Z) + 2: John Smith (matric no: A1111111B) + 3: Ethan Chua (matric no: A0276007H) +------------------------------------------------------------- +------------------------- Error ------------------------- +Error! Component Quiz does not exist in the list! +------------------------------------------------------------- +------------------------- Error ------------------------- +Error! Component Quiz does not exist in the list! +------------------------------------------------------------- +------------------------- Error ------------------------- +Error! Ensure matric number is of the form A\d{7}[A-Z] (case insensitive) +------------------------------------------------------------- +------------------------- Error ------------------------- +Error! Component Wuiz does not exist in the list! +------------------------------------------------------------- +------------------------- Error ------------------------- +Error! Invalid command given! +------------------------------------------------------------- +------------------------- Result ------------------------- + +------------------------------------------------------------- +------------------------- Error ------------------------- +Error! Invalid command given! +------------------------------------------------------------- +------------------------- Error ------------------------- +Error! Ensure matric number is of the form A\d{7}[A-Z] (case insensitive) +------------------------------------------------------------- +------------------------- Error ------------------------- +Error! Grade for component 123 for student A0276007H does not exist in the list! +------------------------------------------------------------- +------------------------- Error ------------------------- +Error! Grade for component Quiz for student A0276007H does not exist in the list! +------------------------------------------------------------- +------------------------- Error ------------------------- +Error! Grade for component Quiz for student A0276007H does not exist in the list! +------------------------------------------------------------- +------------------------- Error ------------------------- +Error! Invalid command given! +------------------------------------------------------------- +------------------------- Result ------------------------- Goodbye! See you soon! ------------------------------------------------------------- diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index 0abaeaa993..a3756296a8 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -1 +1,49 @@ -bye \ No newline at end of file +add_student i/A0276007H n/Ethan Chua +add_student i/A9999999Z n/John Doe +add_student i/a1111111b n/John Smith +add_student i/A n/failure + +add_student i/A0276007H +add_student n/Ethan Chua + +list_student + +delete_student i/A0276007H +delete_student i/A1234567X + +delete_student i/4567890987654567890 + +list_student + +add_component c/Finals w/50 m/100 +add_component c/Quiz w/5 m/20 +add_component c/Fail w/101 m/1 +add_component c/Fail w/0 m/2 +add_component c/123 w/hello m/byebye +add_component c/FailMax w/2147483647 m/2147483647 +add_component c/FailMax w/-1 m/-1 +list_component + +delete_component c/Quiz +list_component + +add_grade i/A0276007H c/Quiz s/19 +add_student i/A0276007H n/Ethan Chua + +list_student +add_grade i/A0276007H c/Quiz s/19 +add_grade i/A0276007H c/Quiz s/100 +add_grade i/A1 c/Quiz s/19 +add_grade i/A0276007H c/Wuiz s/19 + +list_grade + +delete_grade i/A2 c/Quiz +delete_grade i/A0276007H c/123 +delete_grade i/A0276007H c/Quiz +delete_grade i/A0276007H c/Quiz + +bye + + +