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

Add SubjectTest and PersonHaveSubjectPredicateTest #89

Merged
merged 15 commits into from
Oct 25, 2024
13 changes: 13 additions & 0 deletions src/main/java/seedu/address/commons/util/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,17 @@ public static boolean isNonZeroUnsignedInteger(String s) {
return false;
}
}

/**
* Capitalizes the first letter of the input string.
* @param input The string to be formatted.
* @return The string with the first letter capitalized and the rest in lowercase.
*/
public static String capitalizeFirstLetter(String input) {
if (input == null || input.isEmpty()) {
return input;
}
return input.substring(0, 1).toUpperCase() + input.substring(1).toLowerCase();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_HOURS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_SUBJECT;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.CommandHistory;
Expand All @@ -27,13 +28,15 @@ public class AddTuteeCommand extends Command {
+ PREFIX_PHONE + "PHONE "
+ PREFIX_EMAIL + "EMAIL "
+ PREFIX_ADDRESS + "ADDRESS "
+ PREFIX_HOURS + "HOURS \n"
+ PREFIX_HOURS + "HOURS "
+ PREFIX_SUBJECT + "SUBJECT \n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
+ PREFIX_PHONE + "98765432 "
+ PREFIX_EMAIL + "[email protected] "
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 "
+ PREFIX_HOURS + "6 ";
+ PREFIX_HOURS + "6 "
+ PREFIX_SUBJECT + "Math ";


public static final String MESSAGE_SUCCESS = "New tutee added: \n %1$s";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_HOURS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_SUBJECT;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.CommandHistory;
Expand All @@ -27,13 +28,17 @@ public class AddTutorCommand extends Command {
+ PREFIX_PHONE + "PHONE "
+ PREFIX_EMAIL + "EMAIL "
+ PREFIX_ADDRESS + "ADDRESS "
+ PREFIX_HOURS + "HOURS \n"

+ PREFIX_HOURS + "HOURS "
+ PREFIX_SUBJECT + "SUbJECT \n"

+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
+ PREFIX_PHONE + "98765432 "
+ PREFIX_EMAIL + "[email protected] "
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 "
+ PREFIX_HOURS + "6 ";
+ PREFIX_HOURS + "6 "
+ PREFIX_SUBJECT + "Math";


public static final String MESSAGE_SUCCESS = "New tutor added: \n %1$s";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public Optional<Hours> getHours() {
return Optional.ofNullable(hours);
}

//subjects that are the same will only be stored once with HashSet
public void setSubjects(Set<Subject> subjects) {
this.subjects = (subjects != null) ? new HashSet<>(subjects) : null;
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.address.logic.parser;

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.StringUtil.capitalizeFirstLetter;

import java.io.File;
import java.util.Collection;
Expand Down Expand Up @@ -169,9 +170,11 @@ public static Subject parseSubject(String subject) throws ParseException {
if (!Subject.isValidSubject(subject)) {
throw new ParseException(Subject.MESSAGE_CONSTRAINTS);
}
return new Subject(subject.toLowerCase());
return new Subject(capitalizeFirstLetter(trimmedSubject.toLowerCase()));
}



/**
* Parses a collection of subject names into a {@code Set<Subject>}.
* Each subject name in the collection will be parsed individually.
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/model/VersionedAddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public boolean equals(Object other) {

VersionedAddressBook otherVersionedAddressBook = (VersionedAddressBook) other;

boolean check = addressBookStateList.equals(otherVersionedAddressBook.addressBookStateList);
boolean check2 = super.equals(otherVersionedAddressBook);
// state check
return super.equals(otherVersionedAddressBook)
&& addressBookStateList.equals(otherVersionedAddressBook.addressBookStateList)
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ public boolean equals(Object other) {
&& email.equals(otherPerson.email)
&& address.equals(otherPerson.address)
&& hours.equals(otherPerson.hours)
&& tags.equals(otherPerson.tags);
&& tags.equals(otherPerson.tags)
&& subjects.equals(otherPerson.subjects);
}

@Override
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/seedu/address/model/person/Subject.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package seedu.address.model.person;

import static java.util.Objects.requireNonNull;

/**
* Represents a Person's subject teaching or learning in the address book.
*/
public class Subject {
public static final String MESSAGE_CONSTRAINTS =
"Subjects should be string format and of those valid ones(english, math, science).";

public static final String[] AVAILABLE_SUBJECTS = {"english", "math", "science"};
public static final String[] AVAILABLE_SUBJECTS = {"English", "Math", "Science"};
public final String subject;


Expand All @@ -16,6 +18,7 @@ public class Subject {
* @param subject
*/
public Subject(String subject) {
requireNonNull(subject);
if (!isValidSubject(subject)) {
throw new IllegalArgumentException(MESSAGE_CONSTRAINTS);
}
Expand Down Expand Up @@ -48,7 +51,7 @@ public int hashCode() {

@Override
public String toString() {
return subject;
return subject + " ";
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/seedu/address/model/person/Tutee.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ public boolean equals(Object other) {
&& this.getEmail().equals(otherTutee.getEmail())
&& this.getAddress().equals(otherTutee.getAddress())
&& this.getHours().equals(otherTutee.getHours())
&& this.getTags().equals(otherTutee.getTags());
&& this.getTags().equals(otherTutee.getTags())
&& this.getSubjects().equals(otherTutee.getSubjects());
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/seedu/address/model/person/Tutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ public boolean equals(Object other) {
&& this.getEmail().equals(otherTutor.getEmail())
&& this.getAddress().equals(otherTutor.getAddress())
&& this.getHours().equals(otherTutor.getHours())
&& this.getTags().equals(otherTutor.getTags());
&& this.getTags().equals(otherTutor.getTags())
&& this.getSubjects().equals(otherTutor.getSubjects());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public boolean equals(Object other) {
}

UniquePersonList otherUniquePersonList = (UniquePersonList) other;
boolean check = internalList.equals(otherUniquePersonList.internalList);
return internalList.equals(otherUniquePersonList.internalList);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public class CommandTestUtil {
public static final String VALID_HOURS_DEACON = "25";
public static final String VALID_TAG_COLLEAGUE = "colleague";
public static final String VALID_TAG_MENTOR = "mentor";
public static final String VALID_SUBJECT_MATH = "math";
public static final String VALID_SUBJECT_SCIENCE = "science";
public static final String VALID_SUBJECT_MATH = "Math";
public static final String VALID_SUBJECT_SCIENCE = "Science";


public static final String NAME_DESC_AMY = " " + PREFIX_NAME + VALID_NAME_AMY;
Expand Down
79 changes: 73 additions & 6 deletions src/test/java/seedu/address/logic/commands/EditCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_PERSON;
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;

import org.junit.jupiter.api.Disabled;
import java.util.HashSet;
import java.util.Set;

import org.junit.jupiter.api.Test;

import seedu.address.commons.core.index.Index;
Expand All @@ -28,6 +30,9 @@
import seedu.address.model.ModelManager;
import seedu.address.model.UserPrefs;
import seedu.address.model.person.Person;
import seedu.address.model.person.Subject;
import seedu.address.model.person.Tutee;
import seedu.address.model.person.Tutor;
import seedu.address.testutil.EditPersonDescriptorBuilder;
import seedu.address.testutil.PersonBuilder;

Expand All @@ -54,19 +59,19 @@ public void execute_allFieldsSpecifiedUnfilteredList_success() {
assertCommandSuccess(editCommand, model, commandHistory, expectedMessage, expectedModel);
}

@Disabled

@Test
public void execute_someFieldsSpecifiedUnfilteredList_success() {
Index indexLastPerson = Index.fromOneBased(model.getFilteredPersonList().size());
Person lastPerson = model.getFilteredPersonList().get(indexLastPerson.getZeroBased());
Index indexFirstPerson = INDEX_FIRST_PERSON;
Person lastPerson = model.getFilteredPersonList().get(indexFirstPerson.getZeroBased());

PersonBuilder personInList = new PersonBuilder(lastPerson);
Person editedPerson = personInList.withName(VALID_NAME_BOB).withPhone(VALID_PHONE_BOB)
.withTags(VALID_TAG_HUSBAND).build();
.withTags(VALID_TAG_HUSBAND).build(); //is tutor

EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB)
.withPhone(VALID_PHONE_BOB).withTags(VALID_TAG_HUSBAND).build();
EditCommand editCommand = new EditCommand(indexLastPerson, descriptor);
EditCommand editCommand = new EditCommand(indexFirstPerson, descriptor);

String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson));

Expand Down Expand Up @@ -258,4 +263,66 @@ public void toStringMethod() {
assertEquals(expected, editCommand.toString());
}


@Test
public void execute_editSubjectsTutor_success() {
// Arrange
Index indexFirstPerson = INDEX_FIRST_PERSON;
Person personToEdit = model.getFilteredPersonList().get(indexFirstPerson.getZeroBased());

// Assuming personToEdit is a Tutor
Set<Subject> newSubjects = Set.of(new Subject("Math"), new Subject("Science"));
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder()
.withSubjects("Math", "Science").build();

EditCommand editCommand = new EditCommand(indexFirstPerson, descriptor);

// Creating expected person with updated subjects
Person editedPerson = new Tutor(personToEdit.getName(), personToEdit.getPhone(),
personToEdit.getEmail(), personToEdit.getAddress(), personToEdit.getHours(),
personToEdit.getTags(), newSubjects);

String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson));

// Act
Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs());
expectedModel.setPerson(personToEdit, editedPerson);
expectedModel.commitAddressBook();

assertCommandSuccess(editCommand, model, commandHistory, expectedMessage, expectedModel);
}

@Test
public void execute_addSubjectsTutee_success() {
// Arrange
Index indexLastPerson = Index.fromOneBased(model.getFilteredPersonList().size());
Person personToEdit = model.getFilteredPersonList().get(indexLastPerson.getZeroBased());

// Assuming personToEdit is a Tutee
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder()
.withSubjects("English").build();

EditCommand editCommand = new EditCommand(indexLastPerson, descriptor);

// Create expected person with updated subjects
Set<Subject> updatedSubjects = new HashSet<>(personToEdit.getSubjects());
updatedSubjects.add(new Subject("English"));
Person editedPerson = new Tutee(personToEdit.getName(), personToEdit.getPhone(),
personToEdit.getEmail(), personToEdit.getAddress(), personToEdit.getHours(),
personToEdit.getTags(), updatedSubjects);

String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson));

// Act
Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs());
expectedModel.setPerson(personToEdit, editedPerson);
expectedModel.commitAddressBook();

assertCommandSuccess(editCommand, model, commandHistory, expectedMessage, expectedModel);
}





}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.List;
import java.util.stream.Collectors;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import seedu.address.logic.commands.AddTuteeCommand;
Expand Down Expand Up @@ -68,12 +69,17 @@ public void parseCommand_delete() throws Exception {
assertEquals(new DeleteCommand(INDEX_FIRST_PERSON), command);
}

@Disabled
@Test
public void parseCommand_edit() throws Exception {
Person person = new PersonBuilder().build();
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder(person).build();

EditCommand message = new EditCommand(INDEX_FIRST_PERSON, descriptor);

EditCommand command = (EditCommand) parser.parseCommand(EditCommand.COMMAND_WORD + " "
+ INDEX_FIRST_PERSON.getOneBased() + " " + PersonUtil.getEditPersonDescriptorDetails(descriptor));

assertEquals(new EditCommand(INDEX_FIRST_PERSON, descriptor), command);
}

Expand Down
Loading