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

Edit list to work w assignments #119

Merged
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
31 changes: 16 additions & 15 deletions src/main/java/seedu/address/logic/commands/ListCommand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_TASKS;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_ASSIGNMENT;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
Expand All @@ -10,8 +10,8 @@

import seedu.address.commons.core.index.Index;
import seedu.address.model.Model;
import seedu.address.model.assignment.Assignment;
import seedu.address.model.assignment.Deadline;
import seedu.address.model.assignment.Task;

/**
* Lists all tasks in ProductiveNUS to the user.
Expand All @@ -21,26 +21,27 @@ public class ListCommand extends Command {
public static final String COMMAND_WORD = "list";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Lists the tasks in the next [INDEX] number of weeks.\n"
+ "If no index is keyed in, all your tasks will be displayed.\n"
+ ": Lists the assignments in the next [INDEX] days, starting from the current date and time.\n"
+ "A day represents 24 hours.\n"
+ "If no index is keyed in, all your assignments will be displayed.\n"
+ "Parameters: [INDEX] (must be a positive integer)\n"
+ "Example: " + COMMAND_WORD + " 1";

public static final String MESSAGE_SUCCESS = "Listed your tasks";
public static final String MESSAGE_SUCCESS = "Listed your assignments";

private final Index numberOfWeeks;
private final Index numberOfDays;

public ListCommand(Index numberOfWeeks) {
this.numberOfWeeks = numberOfWeeks;
public ListCommand(Index numberOfDays) {
this.numberOfDays = numberOfDays;
}

private Predicate<Task> showLimitedTasks() {
return task -> {
private Predicate<Assignment> showLimitedAssignments() {
return assignment -> {
DateTimeFormatter inputFormat = DateTimeFormatter.ofPattern(Deadline.DEADLINE_DATE_TIME_FORMAT)
.withResolverStyle(ResolverStyle.STRICT);
String dateAndTimeToParse = task.getTime().value;
String dateAndTimeToParse = assignment.getDeadline().value;
LocalDateTime currentDateAndTime = LocalDateTime.now();
LocalDateTime lastDateAndTime = currentDateAndTime.plusWeeks(numberOfWeeks.getZeroBased());
LocalDateTime lastDateAndTime = currentDateAndTime.plusDays(numberOfDays.getZeroBased());
LocalDateTime parsedDateAndTime = LocalDateTime.parse(dateAndTimeToParse, inputFormat);

boolean isAfterCurrentDateAndTime = parsedDateAndTime.isAfter(currentDateAndTime);
Expand All @@ -53,10 +54,10 @@ private Predicate<Task> showLimitedTasks() {
@Override
public CommandResult execute(Model model) {
requireNonNull(model);
if (numberOfWeeks.getZeroBased() != 0) {
model.updateFilteredTaskList(showLimitedTasks());
if (numberOfDays.getZeroBased() == 0) {
model.updateFilteredAssignmentList(PREDICATE_SHOW_ALL_ASSIGNMENT);
} else {
model.updateFilteredTaskList(PREDICATE_SHOW_ALL_TASKS);
model.updateFilteredAssignmentList((showLimitedAssignments()));
}
return new CommandResult(ListCommand.MESSAGE_SUCCESS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ public class ListCommandParser implements Parser<ListCommand> {
* @throws ParseException if the user input does not conform the expected format
*/
public ListCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap;

boolean isNotListAll = args.matches(".*\\b\\d+\\b$"); //Has index as argument
boolean isNotListAll = args.matches(".*\\b.+\\b$"); //Has argument
if (!isNotListAll) {
return new ListCommand(Index.fromZeroBased(0));
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public static Index parseIndex(String oneBasedIndex) throws ParseException {
* trimmed.
* @throws ParseException if the specified index is invalid (not non-zero unsigned integer).
*/
public static Index parseListIndex(String oneBasedIndex) throws ParseException {
String trimmedIndex = oneBasedIndex.trim();
public static Index parseListIndex(String zeroBasedIndex) throws ParseException {
String trimmedIndex = zeroBasedIndex.trim();
if (!StringUtil.isNonZeroUnsignedInteger(trimmedIndex)) {
throw new ParseException(MESSAGE_INVALID_INDEX);
}
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,6 @@ public interface Model {
*/
void updateFilteredAssignmentList(Predicate<Assignment> predicate);

/**
* Updates the filter of the filtered task list to filter by the given {@code predicate}.
* @throws NullPointerException if {@code predicate} is null.
*/
void updateFilteredTaskList(Predicate<Task> predicate);

/** Returns an unmodifiable view of the reminded assignments list */
ObservableList<Assignment> getRemindedAssignmentsList();
}
5 changes: 4 additions & 1 deletion src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ public ObservableList<Task> getFilteredTaskList() {
return filteredTasks;
}

@Override
/**
* Updates filtered task list with given predicate.
* @param predicate Returns a true if a task matches the predicate, false otherwise.
*/
public void updateFilteredTaskList(Predicate<Task> predicate) {
requireNonNull(predicate);
filteredTasks.setPredicate(predicate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,6 @@ public void updateFilteredAssignmentList(Predicate<Assignment> predicate) {
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 ObservableList<Assignment> getRemindedAssignmentsList() {
throw new AssertionError("This method should not be called.");
Expand Down
131 changes: 89 additions & 42 deletions src/test/java/seedu/address/logic/commands/ListCommandTest.java
Original file line number Diff line number Diff line change
@@ -1,42 +1,89 @@
//package seedu.address.logic.commands;
//
//import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
//import static seedu.address.logic.commands.CommandTestUtil.showAssignmentAtIndex;
//import static seedu.address.testutil.TypicalAssignments.getTypicalAddressBook;
//import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_ASSIGNMENT;
//
//import org.junit.jupiter.api.BeforeEach;
//import org.junit.jupiter.api.Test;
//
//import seedu.address.commons.core.index.Index;
//import seedu.address.model.Model;
//import seedu.address.model.ModelManager;
//import seedu.address.model.UserPrefs;
//
///**
// * Contains integration tests (interaction with the Model) and unit tests for ListCommand.
// */
//public class ListCommandTest {
//
// private Model model;
// private Model expectedModel;
//
// @BeforeEach
// public void setUp() {
// model = new ModelManager(getTypicalAddressBook(), new UserPrefs());
// expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs());
// }
//
// @Test
// public void execute_listIsNotFiltered_showsSameList() {
// assertCommandSuccess(new ListCommand(
// Index.fromOneBased(1)), model, ListCommand.MESSAGE_SUCCESS, expectedModel);
// }
//
// @Test
// public void execute_listIsFiltered_showsEverything() {
// showAssignmentAtIndex(model, INDEX_FIRST_ASSIGNMENT);
// assertCommandSuccess(
// new ListCommand(Index.fromOneBased(1)), model, ListCommand.MESSAGE_SUCCESS, expectedModel);
// }
//}
package seedu.address.logic.commands;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.logic.commands.CommandTestUtil.showAssignmentAtIndex;
import static seedu.address.testutil.TypicalAssignments.getTypicalAddressBook;
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_ASSIGNMENT;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.ResolverStyle;
import java.util.Collections;
import java.util.function.Predicate;

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

import seedu.address.commons.core.index.Index;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.UserPrefs;
import seedu.address.model.assignment.Assignment;
import seedu.address.model.assignment.Deadline;


/**
* Contains integration tests (interaction with the Model) and unit tests for ListCommand.
*/
public class ListCommandTest {

private Model model;
private Model expectedModel;
private Index index;

private Predicate<Assignment> showLimitedAssignments() {
return assignment -> {
DateTimeFormatter inputFormat = DateTimeFormatter.ofPattern(Deadline.DEADLINE_DATE_TIME_FORMAT)
.withResolverStyle(ResolverStyle.STRICT);
String dateAndTimeToParse = assignment.getDeadline().value;
LocalDateTime currentDateAndTime = LocalDateTime.now();
LocalDateTime lastDateAndTime = currentDateAndTime.plusDays(index.getZeroBased());
LocalDateTime parsedDateAndTime = LocalDateTime.parse(dateAndTimeToParse, inputFormat);

boolean isAfterCurrentDateAndTime = parsedDateAndTime.isAfter(currentDateAndTime);
boolean isBeforeLastDateAndTime = parsedDateAndTime.isBefore(lastDateAndTime);

return isAfterCurrentDateAndTime && isBeforeLastDateAndTime;
};
}

@BeforeEach
public void setUp() {
model = new ModelManager(getTypicalAddressBook(), new UserPrefs());
expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs());
}

@Test
public void execute_listIsNotFiltered_showsSameList() {
assertCommandSuccess(new ListCommand(
Index.fromZeroBased(0)), model, ListCommand.MESSAGE_SUCCESS, expectedModel);
}

@Test
public void execute_listIsFiltered_showsEverything() {
showAssignmentAtIndex(model, INDEX_FIRST_ASSIGNMENT);
assertCommandSuccess(new ListCommand(
Index.fromZeroBased(0)), model, ListCommand.MESSAGE_SUCCESS, expectedModel);
}

@Test
public void execute_oneDayFromCurrentDate_showAssignments() {
index = Index.fromZeroBased(1);
String expectedMessage = ListCommand.MESSAGE_SUCCESS;
ListCommand listForOneDay = new ListCommand(Index.fromZeroBased(1));
expectedModel.updateFilteredAssignmentList(showLimitedAssignments());
assertCommandSuccess(listForOneDay, model, expectedMessage, expectedModel);
assertEquals(Collections.emptyList(), model.getFilteredAssignmentList());
}

@Test
public void execute_fourDaysFromCurrentDate_showAssignments() {
index = Index.fromZeroBased(4);
String expectedMessage = ListCommand.MESSAGE_SUCCESS;
ListCommand listForFourDays = new ListCommand(Index.fromZeroBased(4));
expectedModel.updateFilteredAssignmentList(showLimitedAssignments());
assertCommandSuccess(listForFourDays, model, expectedMessage, expectedModel);
assertEquals(Collections.emptyList(), model.getFilteredAssignmentList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package seedu.address.logic.parser;

import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure;

import org.junit.jupiter.api.Test;

import seedu.address.logic.commands.ListCommand;

public class ListCommandParserTest {
private ListCommandParser parser = new ListCommandParser();

@Test
public void parse_invalidArgs_throwsParseException() {
assertParseFailure(parser, "-1", String.format(
MESSAGE_INVALID_COMMAND_FORMAT, ListCommand.MESSAGE_USAGE));
assertParseFailure(parser, "0", String.format(
MESSAGE_INVALID_COMMAND_FORMAT, ListCommand.MESSAGE_USAGE));
assertParseFailure(parser, "a", String.format(
MESSAGE_INVALID_COMMAND_FORMAT, ListCommand.MESSAGE_USAGE));
}
}