Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY2021S1#90 from chunyongg/better-testc…
Browse files Browse the repository at this point in the history
…ases

Better testcases
  • Loading branch information
Nijnxw authored Oct 16, 2020
2 parents 6a7bc8a + 385cb12 commit 7e84230
Show file tree
Hide file tree
Showing 13 changed files with 705 additions and 244 deletions.
1 change: 1 addition & 0 deletions src/main/java/seedu/address/commons/core/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class Messages {
public static final String MESSAGE_GROUP_EMPTY = "No such group!";
public static final String MESSAGE_LESSON_LISTED_OVERVIEW = "You are in tutorial group %1$s, lesson %2$s.";
public static final String MESSAGE_STUDENT_EMPTY = "No such student!";
public static final String MESSAGE_DUPLICATE_STUDENT = "Student already exists!";
public static final String MESSAGE_LESSON_EMPTY = "no such lesson!";
public static final String MESSAGE_NOT_VIEWING_A_GROUP = "Group not specified.";
public static final String MESSAGE_NOT_VIEWING_A_LESSON = "Lesson not specified.";
Expand Down
35 changes: 28 additions & 7 deletions src/main/java/seedu/address/logic/commands/AddStudentCommand.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package seedu.address.logic.commands;

import static seedu.address.commons.core.Messages.MESSAGE_DUPLICATE_STUDENT;
import static seedu.address.commons.core.Messages.MESSAGE_GROUP_EMPTY;
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_GRP;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ID;
import static seedu.address.logic.parser.CliSyntax.PREFIX_STUDENT;

import java.util.function.Predicate;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.group.GrpContainsKeywordPredicate;
import seedu.address.model.group.Group;
import seedu.address.model.group.Student;

public class AddStudentCommand extends Command {
Expand All @@ -27,15 +30,16 @@ public class AddStudentCommand extends Command {

private final String studentName;
private final String studentId;
private final GrpContainsKeywordPredicate predicate;
private final Predicate<Group> predicate;

/**
* Creates an AddStudentCommand to add the specified {@code Student}
*
* @param studentName
* @param studentId
* @param predicate
*/
public AddStudentCommand(String studentName, String studentId, GrpContainsKeywordPredicate predicate) {
public AddStudentCommand(String studentName, String studentId, Predicate<Group> predicate) {
requireAllNonNull(studentName, studentId, predicate);
this.studentName = studentName;
this.studentId = studentId;
Expand All @@ -45,13 +49,30 @@ public AddStudentCommand(String studentName, String studentId, GrpContainsKeywor
@Override
public CommandResult execute(Model model) throws CommandException {
Student student = new Student(studentName, studentId);
model.addStudentToGroup(student, predicate);
model.updateFilteredGroupList(predicate);
if (model.getFilteredGroupList().isEmpty()) {
//no such group exists
return new CommandResult(MESSAGE_GROUP_EMPTY);
throw new CommandException(MESSAGE_GROUP_EMPTY);
}
Group targetGroup = model.getFilteredGroupList().get(0);
if (targetGroup.getStudents().contains(student)) {
throw new CommandException(MESSAGE_DUPLICATE_STUDENT);
}
model.addStudentToGroup(student, predicate);
return new CommandResult(
String.format(MESSAGE_SUCCESS, studentName, studentId, model.getFilteredGroupList().get(0).getName()));
}

@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
} else if (obj instanceof AddStudentCommand) {
AddStudentCommand other = (AddStudentCommand) obj;
return studentName.equals(other.studentName) && studentId.equals(other.studentId)
&& predicate.equals(other.predicate);
} else {
return new CommandResult(
String.format(MESSAGE_SUCCESS, studentName, studentId, model.getFilteredGroupList().get(0).getName()));
return false;
}
}
}
23 changes: 18 additions & 5 deletions src/main/java/seedu/address/logic/commands/DelStudentCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_ID;
import static seedu.address.logic.parser.CliSyntax.PREFIX_STUDENT;

import java.util.function.Predicate;

import javafx.collections.ObservableList;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.group.Group;
import seedu.address.model.group.GrpContainsKeywordPredicate;
import seedu.address.model.group.Student;

public class DelStudentCommand extends Command {
Expand All @@ -30,15 +31,15 @@ public class DelStudentCommand extends Command {

private final String studentName;
private final String studentId;
private final GrpContainsKeywordPredicate predicate;
private final Predicate<Group> predicate;

/**
* Creates a DelStudentCommand to remove the specified {@code Student}
* @param studentName Name of Student
* @param studentId Id of Student
* @param predicate Group predicate
*/
public DelStudentCommand(String studentName, String studentId, GrpContainsKeywordPredicate predicate) {
public DelStudentCommand(String studentName, String studentId, Predicate<Group> predicate) {
requireAllNonNull(studentName, studentId, predicate);
this.studentName = studentName;
this.studentId = studentId;
Expand All @@ -53,11 +54,11 @@ public CommandResult execute(Model model) throws CommandException {
ObservableList<Group> groups = model.getFilteredGroupList();
if (groups.isEmpty()) {
//no such group
return new CommandResult(MESSAGE_GROUP_EMPTY);
throw new CommandException(MESSAGE_GROUP_EMPTY);
}
if (!groups.get(0).getStudents().contains(student)) {
//student does not exist
return new CommandResult(MESSAGE_STUDENT_EMPTY);
throw new CommandException(MESSAGE_STUDENT_EMPTY);
} else {
model.removeStudentFromGroup(student, predicate);
model.updateFilteredGroupList(predicate);
Expand All @@ -66,4 +67,16 @@ public CommandResult execute(Model model) throws CommandException {
}
}

@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
} else if (obj instanceof DelStudentCommand) {
DelStudentCommand other = (DelStudentCommand) obj;
return studentName.equals(other.studentName) && studentId.equals(other.studentId)
&& predicate.equals(other.predicate);
} else {
return false;
}
}
}
19 changes: 16 additions & 3 deletions src/main/java/seedu/address/model/group/Student.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
*/
public class Student {
public static final String STUDENT_NAME_ERROR = "Name cannot be empty";
public static final String STUDENT_NUMBER_ERROR = "Student number cannot be empty";
public static final String STUDENT_NUMBER_ERROR = "Student number cannot be empty "
+ "and must follow the format 'eXXXXXXX' "
+ "where X is a digit from 0 to 9";
private String name;
private String studentNumber;

Expand Down Expand Up @@ -40,6 +42,11 @@ public static boolean isValidString(String s) {
public static boolean isValidStudentNumber(String s) {
//8 digits long
s = s.toLowerCase();
boolean matchesLength = s.length() == 8;
boolean matchesChar = s.charAt(0) == 'e';
if (!matchesChar || !matchesLength) {
System.out.println(s);
}
return s.length() == 8 && s.charAt(0) == 'e';
}

Expand All @@ -58,7 +65,13 @@ public String toString() {

@Override
public boolean equals(Object obj) {
Student other = (Student) obj;
return other.getName().equals(getName()) && other.getStudentNumber().equals(getStudentNumber());
if (obj == this) {
return true;
} else if (obj instanceof Student) {
Student other = (Student) obj;
return other.getName().equals(getName()) && other.getStudentNumber().equals(getStudentNumber());
} else {
return false;
}
}
}
Loading

0 comments on commit 7e84230

Please sign in to comment.