Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marcellaantania committed Oct 18, 2023
1 parent 052ed29 commit 90c7eda
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ public boolean equals(Object other) {
}

// instanceof handles nulls
if (!(other instanceof HasLeaveThisMonthPredicate)) {
return false;
}

return true;
return other instanceof HasLeaveAnyMonthPredicate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ public void equalsTest() {
ViewLeaveCommand command1 = new ViewLeaveCommand(predicate1);
ViewLeaveCommand command2 = new ViewLeaveCommand(predicate2);
ViewLeaveCommand command3 = new ViewLeaveCommand(new HasLeaveThisMonthPredicate("12"));
assertEquals(command1, command1);
assertEquals(command1, command2);
assertFalse(command1.equals(command3));
assertFalse(command1.equals(null));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.LeaveCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.ViewLeaveCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.NameContainsKeywordsPredicate;
import seedu.address.model.person.Person;
Expand Down Expand Up @@ -97,6 +98,11 @@ public void parseCommand_leave() throws Exception {
assertTrue(parser.parseCommand(LeaveCommand.COMMAND_WORD + " 1 m/2") instanceof LeaveCommand);
}

@Test
public void parseCommand_viewLeave() throws Exception {
assertTrue(parser.parseCommand(ViewLeaveCommand.COMMAND_WORD + " m/2") instanceof ViewLeaveCommand);
}

@Test
public void parseCommand_unrecognisedInput_throwsParseException() {
assertThrows(ParseException.class, String.format(MESSAGE_INVALID_COMMAND_FORMAT, HelpCommand.MESSAGE_USAGE), ()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package seedu.address.logic.parser;

import static seedu.address.logic.commands.CommandTestUtil.VALID_DEPARTMENT;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure;
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;

import java.util.function.Predicate;

import org.junit.jupiter.api.Test;

import seedu.address.logic.Messages;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.UserPrefs;
import seedu.address.model.person.Department;
import seedu.address.model.person.HasLeaveAnyMonthPredicate;
import seedu.address.model.person.HasLeaveThisMonthPredicate;
Expand All @@ -16,20 +22,37 @@

class ViewLeaveCommandParserTest {

private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs());

private ViewLeaveCommandParser parser = new ViewLeaveCommandParser();

@Test
void parse_success() {
void parse_success() throws ParseException {
Predicate<Person> testPredicateAnyMonth = new HasLeaveAnyMonthPredicate();
Predicate<Person> testPredicateMonth = new HasLeaveThisMonthPredicate("3");
Predicate<Person> testPredicateMonths = testPredicateMonth.and(new HasLeaveThisMonthPredicate("1"));
Predicate<Person> testPredicateMonthAndDept = testPredicateMonth.and(
new MatchingDepartmentPredicate(new Department(VALID_DEPARTMENT)));

//assertParseSuccess(parser, "", new ViewLeaveCommand(testPredicateAnyMonth));
//assertParseSuccess(parser, " m/3", new ViewLeaveCommand(testPredicateMonth));
//assertParseSuccess(parser, " m/1,3", new ViewLeaveCommand(testPredicateMonths));
//assertParseSuccess(parser, " m/1 d/Engineering", new ViewLeaveCommand(testPredicateMonthAndDept));
Model expectedModel1 = new ModelManager(getTypicalAddressBook(), new UserPrefs());
expectedModel1.updateFilteredPersonList(testPredicateAnyMonth);
assertCommandSuccess(parser.parse(""), model, String.format(Messages.MESSAGE_VIEW_LEAVE_SUCCESS,
expectedModel1.getFilteredPersonList().size()), expectedModel1);

Model expectedModel2 = new ModelManager(getTypicalAddressBook(), new UserPrefs());
expectedModel2.updateFilteredPersonList(testPredicateMonth);
assertCommandSuccess(parser.parse(" m/3"), model, String.format(Messages.MESSAGE_VIEW_LEAVE_SUCCESS,
expectedModel2.getFilteredPersonList().size()), expectedModel2);

Model expectedModel3 = new ModelManager(getTypicalAddressBook(), new UserPrefs());
expectedModel3.updateFilteredPersonList(testPredicateMonths);
assertCommandSuccess(parser.parse(" m/1,3"), model, String.format(Messages.MESSAGE_VIEW_LEAVE_SUCCESS,
expectedModel3.getFilteredPersonList().size()), expectedModel3);

Model expectedModel4 = new ModelManager(getTypicalAddressBook(), new UserPrefs());
expectedModel4.updateFilteredPersonList(testPredicateMonthAndDept);
assertCommandSuccess(parser.parse(" m/1 d/Engineering"), model, String.format(Messages.MESSAGE_VIEW_LEAVE_SUCCESS,
expectedModel4.getFilteredPersonList().size()), expectedModel4);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package seedu.address.model.person;

import org.junit.jupiter.api.Test;
import seedu.address.testutil.PersonBuilder;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

class HasLeaveAnyMonthPredicateTest {

@Test
void test_hasLeaveAnyMonth_returnsTrue() {
HasLeaveAnyMonthPredicate predicate1 = new HasLeaveAnyMonthPredicate();
assertTrue(predicate1.test(new PersonBuilder().withLeave("111001000011").build()));
}

@Test
void test_hasLeaveAnyMonth_returnsFalse() {
HasLeaveAnyMonthPredicate predicate1 = new HasLeaveAnyMonthPredicate();
assertFalse(predicate1.test(new PersonBuilder().withLeave("000000000000").build()));
}

@Test
void testEquals() {
HasLeaveAnyMonthPredicate predicate1 = new HasLeaveAnyMonthPredicate();
HasLeaveAnyMonthPredicate predicate2 = new HasLeaveAnyMonthPredicate();

assertEquals(predicate1, predicate1);
assertEquals(predicate1, predicate2);
assertNotEquals(predicate1, null);
assertNotEquals(predicate1, 1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package seedu.address.model.person;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;
import seedu.address.testutil.PersonBuilder;

class HasLeaveThisMonthPredicateTest {

@Test
void test_hasLeaveThisMonth_returnsTrue() {
HasLeaveThisMonthPredicate predicate1 = new HasLeaveThisMonthPredicate("1");
assertTrue(predicate1.test(new PersonBuilder().withLeave("111001000011").build()));
}

@Test
void test_hasLeaveThisMonth_returnsFalse() {
HasLeaveThisMonthPredicate predicate1 = new HasLeaveThisMonthPredicate("4");
assertFalse(predicate1.test(new PersonBuilder().withLeave("111001000011").build()));
}

@Test
void testEquals() {
HasLeaveThisMonthPredicate predicate1 = new HasLeaveThisMonthPredicate("1");
HasLeaveThisMonthPredicate predicate2 = new HasLeaveThisMonthPredicate("1");
HasLeaveThisMonthPredicate predicate3 = new HasLeaveThisMonthPredicate("12");
assertEquals(predicate1, predicate1);
assertEquals(predicate1, predicate2);
assertNotEquals(predicate1, predicate3);
assertNotEquals(predicate1, null);
assertNotEquals(predicate1, 1);
}
}

0 comments on commit 90c7eda

Please sign in to comment.