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

Write more testcases & allow Name to contains non-alphanumeric char #123

Merged
merged 5 commits into from
Oct 25, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private static Lesson createEditedLesson(Lesson lessonToEdit, EditLessonDescript
assert lessonToEdit != null;

Code updatedCode = editLessonDescriptor.getCode().orElse(lessonToEdit.getCode());
Type updatedType = editLessonDescriptor.getType().orElse(lessonToEdit.getType());;
Type updatedType = editLessonDescriptor.getType().orElse(lessonToEdit.getType());
LessonDateTime updatedDate = editLessonDescriptor.getDate().orElse(lessonToEdit.getDate());

return new Lesson(updatedCode, updatedType, updatedDate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ public class AddModuleCommand extends Command {
public static final String MESSAGE_USAGE = Module.TYPE + " " + COMMAND_WORD + ": Adds a module to the app "
+ "Parameters: "
+ PREFIX_CODE + "CODE "
+ PREFIX_NAME + "NAME ";
+ PREFIX_NAME + "NAME "
+ "\nExample: " + Module.TYPE + " " + COMMAND_WORD + " "
+ PREFIX_CODE + "CS1231S"
+ PREFIX_NAME + "Discrete Structures";

public static final String MESSAGE_SUCCESS = "New module added: %1$s";
public static final String MESSAGE_DUPLICATE_MODULE = "This module already exists";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public DeleteLessonCommand parse(String args) throws ParseException {
return new DeleteLessonCommand(index);
} catch (ParseException pe) {
throw new ParseException(
String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT, DeleteLessonCommand.MESSAGE_USAGE), pe);
String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT, DeleteLessonCommand.MESSAGE_USAGE), pe);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public EditLessonCommand parse(String args) throws ParseException {
index = ParserUtil.parseIndex(argMultimap.getPreamble());
} catch (ParseException pe) {
throw new ParseException(String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT,
EditLessonCommand.MESSAGE_USAGE), pe);
EditLessonCommand.MESSAGE_USAGE), pe);
}

EditLessonDescriptor editLessonDescriptor = new EditLessonDescriptor();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/trackitnus/model/commons/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
public class Name {

public static final String MESSAGE_CONSTRAINTS =
"Names should only contain alphanumeric characters and spaces, and it should not be blank";
"Names should be a non-empty string and should not contain '/'";

/*
* The first character of the address must not be a whitespace,
* The first character of the name must not be a whitespace,
* otherwise " " (a blank string) becomes a valid input.
*/
public static final String VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*";
public static final String VALIDATION_REGEX = "[^/ ][^/]+";

public final String fullName;

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/trackitnus/model/lesson/LessonComparator.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ public class LessonComparator implements Comparator<Lesson> {
/**
* Compares 2 lessons in chronological order to facilitate sorting.
*
* @param firstLesson First lesson to compare.
* @param firstLesson First lesson to compare.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the extra space supposed to be there?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, it's the formatter of IntelliJ, it auto-align the comments of params

* @param secondLesson Second lesson to compare.
* @return an int < 0 if firstLesson is "less than" secondLesson.
*/
@Override
public int compare(Lesson firstLesson, Lesson secondLesson) {
int res = firstLesson.getDate().compareTo(secondLesson.getDate());
return res == 0
? firstLesson.toString().compareTo(secondLesson.toString())
: res;
? firstLesson.toString().compareTo(secondLesson.toString())
: res;
}
}
12 changes: 6 additions & 6 deletions src/main/java/trackitnus/model/lesson/LessonDateTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public int compareTo(LessonDateTime other) {
Integer currentToOther = LessonWeekday.distanceTo(currentWeekday, other.getWeekday());
int result = currentToThis.compareTo(currentToOther);
return result == 0
? this.getStartTime().compareTo(other.getStartTime())
: result;
? this.getStartTime().compareTo(other.getStartTime())
: result;
}
}

Expand All @@ -73,14 +73,14 @@ public boolean equals(Object other) {

LessonDateTime otherDate = (LessonDateTime) other;
return otherDate.weekday.equals(weekday)
&& otherDate.startTime.equals(startTime)
&& otherDate.endTime.equals(endTime);
&& otherDate.startTime.equals(startTime)
&& otherDate.endTime.equals(endTime);
}

@Override
public String toString() {
return weekday.name() + " "
+ startTime.format(FORMATTER) + "-"
+ endTime.format(FORMATTER);
+ startTime.format(FORMATTER) + "-"
+ endTime.format(FORMATTER);
}
}
3 changes: 2 additions & 1 deletion src/main/java/trackitnus/model/lesson/LessonWeekday.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public enum LessonWeekday {
Fri,
Sat;
private static final int SIZE = 7;

public static LessonWeekday getLessonWeekDay(LocalDate date) {
DayOfWeek dayOfWeek = date.getDayOfWeek();
switch (dayOfWeek) {
Expand All @@ -31,7 +32,7 @@ public static LessonWeekday getLessonWeekDay(LocalDate date) {
return Sat;
default:
throw new AssertionError(
"Unexpected error: Unable to retrieve weekday from LocalDate.");
"Unexpected error: Unable to retrieve weekday from LocalDate.");
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/trackitnus/model/module/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ public String toString() {
}

/**
* Returns true if the two modules are the same
* This methods is here for to act as a compatibility layer for UniqueModuleList
* Returns true if both modules have the same code
* This defines a weaker notion of equality between two modules.
*/
public boolean isSameModule(Module module) {
return this.equals(module);
return this.code.equals(module.code);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static trackitnus.logic.commands.CommandTestUtil.assertCommandFailure;
import static trackitnus.logic.commands.CommandTestUtil.assertCommandSuccess;
import static trackitnus.testutil.TypicalTrackIter.getTypicalTrackIter;
import static trackitnus.testutil.typical.TypicalTrackIter.getTypicalTrackIter;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,18 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Optional;
import java.util.function.Predicate;

import org.junit.jupiter.api.Test;

import javafx.collections.ObservableList;
import trackitnus.commons.core.GuiSettings;
import trackitnus.commons.core.index.Index;
import trackitnus.logic.commands.CommandResult;
import trackitnus.logic.commands.exceptions.CommandException;
import trackitnus.model.Model;
import trackitnus.model.ReadOnlyTrackIter;
import trackitnus.model.ReadOnlyUserPrefs;
import trackitnus.model.TrackIter;
import trackitnus.model.commons.Code;
import trackitnus.model.contact.Contact;
import trackitnus.model.lesson.Lesson;
import trackitnus.model.lesson.Type;
import trackitnus.model.module.Module;
import trackitnus.model.task.Task;
import trackitnus.testutil.Assert;
import trackitnus.testutil.ModelStub;
import trackitnus.testutil.builder.ContactBuilder;

public class AddContactCommandTest {
Expand Down Expand Up @@ -82,192 +70,6 @@ public void equals() {
// different contact -> returns false
assertFalse(addAliceCommand.equals(addBobCommand));
}

/**
* A default model stub that have all of the methods failing.
*/
private class ModelStub implements Model {
@Override
public ReadOnlyUserPrefs getUserPrefs() {
throw new AssertionError("This method should not be called.");
}

@Override
public void setUserPrefs(ReadOnlyUserPrefs userPrefs) {
throw new AssertionError("This method should not be called.");
}

@Override
public GuiSettings getGuiSettings() {
throw new AssertionError("This method should not be called.");
}

@Override
public void setGuiSettings(GuiSettings guiSettings) {
throw new AssertionError("This method should not be called.");
}

@Override
public Path getTrackIterFilePath() {
throw new AssertionError("This method should not be called.");
}

@Override
public void setTrackIterFilePath(Path trackIterFilePath) {
throw new AssertionError("This method should not be called.");
}

@Override
public void addContact(Contact contact) {
throw new AssertionError("This method should not be called.");
}

@Override
public ReadOnlyTrackIter getTrackIter() {
throw new AssertionError("This method should not be called.");
}

@Override
public void setTrackIter(ReadOnlyTrackIter trackIt) {
throw new AssertionError("This method should not be called.");
}

@Override
public boolean hasContact(Contact contact) {
throw new AssertionError("This method should not be called.");
}

@Override
public void deleteContact(Contact target) {
throw new AssertionError("This method should not be called.");
}

@Override
public void setContact(Contact target, Contact editedContact) {
throw new AssertionError("This method should not be called.");
}

@Override
public ObservableList<Contact> getFilteredContactList() {
throw new AssertionError("This method should not be called.");
}

@Override
public void updateFilteredContactList(Predicate<Contact> predicate) {
throw new AssertionError("This method should not be called.");
}

@Override
public boolean hasModule(Module task) {
throw new AssertionError("This method should not be called.");
}

@Override
public Optional<Module> getModule(Code code) {
throw new AssertionError("This method should not be called.");
}

@Override
public void deleteModule(Module target) {
throw new AssertionError("This method should not be called.");
}

@Override
public void addModule(Module module) {
throw new AssertionError("This method should not be called.");
}

@Override
public void setModule(Module target, Module editedTask) {
throw new AssertionError("This method should not be called.");
}

@Override
public ObservableList<Module> getFilteredModuleList() {
throw new AssertionError("This method should not be called.");
}

@Override
public void updateFilteredModuleList(Predicate<Module> predicate) {
throw new AssertionError("This method should not be called.");
}

@Override
public boolean hasTask(Task task) {
throw new AssertionError("This method should not be called.");
}

@Override
public void deleteTask(Task target) {
throw new AssertionError("This method should not be called.");
}

@Override
public void addTask(Task task) {
throw new AssertionError("This method should not be called.");
}

@Override
public void setTask(Task target, Task editedTask) {
throw new AssertionError("This method should not be called.");
}

@Override
public ObservableList<Task> getFilteredTaskList() {
throw new AssertionError("This method should not be called.");
}

@Override
public void updateFilteredTaskList(Predicate<Task> predicate) {
throw new AssertionError("This method should not be called.");
}

@Override
public boolean hasLesson(Lesson lesson) {
throw new AssertionError("This method should not be called.");
}

@Override
public void deleteLesson(Lesson target) {
throw new AssertionError("This method should not be called.");
}

@Override
public void addLesson(Lesson lesson) {
throw new AssertionError("This method should not be called.");
}

@Override
public void setLesson(Lesson target, Lesson editedLesson) {
throw new AssertionError("This method should not be called.");
}

@Override
public ObservableList<Lesson> getFilteredLessonList() {
throw new AssertionError("This method should not be called.");
}

@Override
public void updateFilteredLessonList(Predicate<Lesson> predicate) {
throw new AssertionError("This method should not be called.");
}

@Override
public Optional<Lesson> getLesson(Code code, Type type) {
throw new AssertionError("This method should not be called.");
}

@Override
public void sortLesson() {
throw new AssertionError("This method should not be called.");
}

public Index getTaskIndex(Task task) {
throw new AssertionError("This method should not be called.");
}

}

/**
* A Model stub that contains a single contact.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package trackitnus.logic.commands.contact;

import static trackitnus.logic.commands.CommandTestUtil.assertCommandSuccess;
import static trackitnus.testutil.TypicalTrackIter.getTypicalTrackIter;
import static trackitnus.testutil.typical.TypicalTrackIter.getTypicalTrackIter;

import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class ContactCommandTestUtil {
public static final String TAG_DESC_FRIEND = " " + PREFIX_TAG + VALID_TAG_FRIEND;
public static final String TAG_DESC_HUSBAND = " " + PREFIX_TAG + VALID_TAG_HUSBAND;

public static final String INVALID_NAME_DESC = " " + PREFIX_NAME + "James&"; // '&' not allowed in names
public static final String INVALID_NAME_DESC = " " + PREFIX_NAME + "James/"; // '/' not allowed in names
public static final String INVALID_PHONE_DESC = " " + PREFIX_PHONE + "911a"; // 'a' not allowed in phones
public static final String INVALID_EMAIL_DESC = " " + PREFIX_EMAIL + "bob!yahoo"; // missing '@' symbol
public static final String INVALID_ADDRESS_DESC = " " + PREFIX_ADDRESS; // empty string not allowed for addresses
Expand Down