Skip to content

Latest commit

 

History

History
302 lines (245 loc) · 11.5 KB

A0139438W.md

File metadata and controls

302 lines (245 loc) · 11.5 KB

A0139438W

/java/seedu/geekeep/logic/LogicManagerTest.java
        public Task getTestEvent() throws Exception {
            Title title = new Title("Event");
            DateTime endDateTime = new DateTime("01-05-17 1630");
            DateTime startDateTime = new DateTime("01-04-17 1630");
            Description description = new Description("111, alpha street");
            Tag tag1 = new Tag("tag1");
            Tag tag2 = new Tag("longertag2");
            UniqueTagList tags = new UniqueTagList(tag1, tag2);
            return new Task(title, startDateTime, endDateTime, description, tags, false);
        }

        public Task getTestDeadline() throws Exception {
            Title title = new Title("Deadline");
            DateTime endDateTime = new DateTime("01-05-17 1630");
            Description description = new Description("222, beta street");
            Tag tag1 = new Tag("tag1");
            Tag tag2 = new Tag("longertag2");
            UniqueTagList tags = new UniqueTagList(tag1, tag2);
            return new Task(title, null, endDateTime, description, tags, false);
        }

        public Task getTestEventWithoutTime() throws Exception {
            Title title = new Title("Event Without Time");
            DateTime endDateTime = new DateTime("01-05-17");
            DateTime startDateTime = new DateTime("01-04-17");
            Description description = new Description("111, alpha street");
            Tag tag1 = new Tag("tag1");
            Tag tag2 = new Tag("longertag2");
            UniqueTagList tags = new UniqueTagList(tag1, tag2);
            return new Task(title, startDateTime, endDateTime, description, tags, false);
        }

        public Task getTestFloatingTask() throws Exception {
            Title title = new Title("Floating Task");
            Description description = new Description("333, charlie street");
            Tag tag1 = new Tag("tag1");
            Tag tag2 = new Tag("longertag2");
            UniqueTagList tags = new UniqueTagList(tag1, tag2);
            return new Task(title, null, null, description, tags, false);
        }
/java/seedu/geekeep/logic/LogicManagerTest.java
    @Test
    public void execute_add_invalidTaskData() {
        assertCommandFailure("add []\\[;] s/01-04-17 1630 e/01-05-17 1630 d/valid, location",
                Title.MESSAGE_TITLE_CONSTRAINTS);
        assertCommandFailure("add Valid Title s/not_numbers e/01-05-17 1630 d/valid, location",
                DateTime.MESSAGE_DATETIME_CONSTRAINTS);
        assertCommandFailure("add Valid Title s/01-04-17 1630 e/not_numbers d/valid, location",
                DateTime.MESSAGE_DATETIME_CONSTRAINTS);
        assertCommandFailure("add Valid Title s/01-05-17 1630 e/01-04-17 1630 d/valid, location",
                Task.MESSAGE_ENDDATETIME_LATER_CONSTRAINTS);
        assertCommandFailure("add Valid Title s/01-05-17 1630 d/valid, location",
                Task.MESSAGE_DATETIME_MATCH_CONSTRAINTS);
        assertCommandFailure(
                "add Valid Title s/01-04-17 1630 e/01-05-17 1630 d/valid, location t/invalid_-[.tag",
                Tag.MESSAGE_TAG_CONSTRAINTS);
    }

    @Test
    public void execute_add_successful() throws Exception {
        // setup expectations
        TestDataHelper helper = new TestDataHelper();

        // add a new event
        Task toBeAdded = helper.getTestEvent();
        GeeKeep expectedAB = new GeeKeep();
        expectedAB.addTask(toBeAdded);

        // execute command and verify result
        assertCommandSuccess(helper.generateAddCommand(toBeAdded),
                String.format(AddCommand.MESSAGE_SUCCESS, toBeAdded),
                expectedAB,
                expectedAB.getTaskList());

        // add a new event without time field
        toBeAdded = helper.getTestEventWithoutTime();
        expectedAB.addTask(toBeAdded);

        // execute command and verify result
        assertCommandSuccess(helper.generateAddCommand(toBeAdded),
                String.format(AddCommand.MESSAGE_SUCCESS, toBeAdded),
                expectedAB,
                expectedAB.getTaskList());

        // add a new deadline
        toBeAdded = helper.getTestDeadline();
        expectedAB.addTask(toBeAdded);

        // execute command and verify result
        assertCommandSuccess(helper.generateAddCommand(toBeAdded),
                String.format(AddCommand.MESSAGE_SUCCESS, toBeAdded),
                expectedAB,
                expectedAB.getTaskList());

        // add a new floating task
        toBeAdded = helper.getTestFloatingTask();
        expectedAB.addTask(toBeAdded);

        // execute command and verify result
        assertCommandSuccess(helper.generateAddCommand(toBeAdded),
                String.format(AddCommand.MESSAGE_SUCCESS, toBeAdded),
                expectedAB,
                expectedAB.getTaskList());
    }

    @Test
    public void execute_addDuplicate_notAllowed() throws Exception {
        // setup expectations
        TestDataHelper helper = new TestDataHelper();
        Task toBeAdded = helper.getTestEvent();

        // setup starting state
        model.addTask(toBeAdded); // task already in internal geekeep

        // execute command and verify result
        assertCommandFailure(helper.generateAddCommand(toBeAdded),  AddCommand.MESSAGE_DUPLICATE_TASK);

    }

    @Test
    public void execute_clear() throws Exception {
        TestDataHelper helper = new TestDataHelper();
        model.addTask(helper.generateTask(1));
        model.addTask(helper.generateTask(2));
        model.addTask(helper.generateTask(3));

        assertCommandSuccess("clear", ClearCommand.MESSAGE_SUCCESS, new GeeKeep(), Collections.emptyList());
    }

    @Test
    public void execute_delete_removesCorrectTask() throws Exception {
        TestDataHelper helper = new TestDataHelper();
        List<Task> threeTasks = helper.generateTaskList(3);

        GeeKeep expectedAB = helper.generateGeeKeep(threeTasks);
        expectedAB.removeTask(threeTasks.get(1));
        helper.addToModel(model, threeTasks);

        assertCommandSuccess("delete 2",
                String.format(DeleteCommand.MESSAGE_DELETE_TASK_SUCCESS, threeTasks.get(1)),
                expectedAB,
                expectedAB.getTaskList());
    }

    @Test
    public void execute_deleteIndexNotFound_errorMessageShown() throws Exception {
        assertIndexNotFoundBehaviorForCommand("delete");
    }


    @Test
    public void execute_deleteInvalidArgsFormat_errorMessageShown() throws Exception {
        String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteCommand.MESSAGE_USAGE);
        assertIncorrectIndexFormatBehaviorForCommand("delete", expectedMessage);
    }
/java/seedu/geekeep/logic/LogicManagerTest.java
    @Test
    public void execute_undo_redo_errorMessageShown() throws Exception {
        String expectedMessage = String.format(UndoCommand.MESSAGE_NOTHING_TO_UNDO);
        assertCommandFailure("undo", expectedMessage);

        expectedMessage = String.format(RedoCommand.MESSAGE_NOTHING_TO_REDO);
        assertCommandFailure("redo", expectedMessage);
    }

    @Test
    public void execute_undo_redo_Success() throws Exception {
        TestDataHelper helper = new TestDataHelper();
        List<Task> threeTasks = helper.generateTaskList(3);

        GeeKeep expectedAB = helper.generateGeeKeep(threeTasks);
        expectedAB.removeTask(threeTasks.get(2));
        helper.addToModel(model, threeTasks);

        assertCommandSuccess("delete 3",
                String.format(DeleteCommand.MESSAGE_DELETE_TASK_SUCCESS, threeTasks.get(2)),
                expectedAB,
                expectedAB.getTaskList());

        // Add deleted task back to expected Geekeep
        expectedAB.addTask(threeTasks.get(2));

        assertCommandSuccess("undo",
                String.format(UndoCommand.MESSAGE_SUCCESS, "delete 3"),
                expectedAB,
                expectedAB.getTaskList());

        // Deleted task from expected Geekeep again
        expectedAB.removeTask(threeTasks.get(2));

        assertCommandSuccess("redo",
                String.format(RedoCommand.MESSAGE_SUCCESS, "delete 3"),
                expectedAB,
                expectedAB.getTaskList());
    }

    @Test
    public void execute_done_undone_CorrectTask() throws Exception {
        TestDataHelper helper = new TestDataHelper();
        List<Task> threeTasks = helper.generateTaskList(3);

        GeeKeep expectedAB = helper.generateGeeKeep(threeTasks);
        expectedAB.markTaskDone(1);
        helper.addToModel(model, threeTasks);

        assertCommandSuccess("done 2",
                String.format(DoneCommand.MESSAGE_DONE_TASK_SUCCESS, threeTasks.get(1)),
                expectedAB,
                expectedAB.getTaskList());

        expectedAB.markTaskUndone(1);

        assertCommandSuccess("undone 2",
                String.format(UndoneCommand.MESSAGE_UNDONE_TASK_SUCCESS, threeTasks.get(1)),
                expectedAB,
                expectedAB.getTaskList());
    }

    @Test
    public void execute_done_undone_IndexNotFound_errorMessageShown() throws Exception {
        assertIndexNotFoundBehaviorForCommand("done");
        assertIndexNotFoundBehaviorForCommand("undone");
    }


    @Test
    public void execute_done_undone_InvalidArgsFormat_errorMessageShown() throws Exception {
        String expectedDoneMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, DoneCommand.MESSAGE_USAGE);
        assertIncorrectIndexFormatBehaviorForCommand("done", expectedDoneMessage);
        String expectedUndoneMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, UndoneCommand.MESSAGE_USAGE);
        assertIncorrectIndexFormatBehaviorForCommand("undone", expectedUndoneMessage);
    }
/java/seedu/geekeep/logic/LogicManagerTest.java
    @Test
    public void execute_listdone_listundone_showsTasksCorrectly() throws Exception {
        // prepare expectations for list undone tasks
        TestDataHelper helper = new TestDataHelper();
        GeeKeep expectedAB = helper.generateGeeKeep(2);
        List<? extends ReadOnlyTask> expectedList = expectedAB.getTaskList();

        // prepare geekeep state
        helper.addToModel(model, 2);

        assertCommandSuccess("listundone",
                ListUndoneCommand.MESSAGE_SUCCESS,
                expectedAB,
                expectedList);

        assertCommandFailure("listundone dummy words", ListUndoneCommand.MESSAGE_USAGE);

        // prepare expectations for list done tasks
        expectedList = expectedAB.getTaskList().filtered(t -> t.isDone());

        assertCommandSuccess("listdone",
                ListDoneCommand.MESSAGE_SUCCESS,
                expectedAB,
                expectedList);

        assertCommandFailure("listdone dummy words", ListDoneCommand.MESSAGE_USAGE);

    }
/java/seedu/geekeep/model/task/DateTimeTest.java
package seedu.geekeep.model.task;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

public class DateTimeTest {

    @Test
    public void isValidDateTime() {
        // invalid start date time
        assertFalse(DateTime.isValidDateTime("")); // empty string
        assertFalse(DateTime.isValidDateTime(" ")); // spaces only
        assertFalse(DateTime.isValidDateTime("01-04-171630")); // missing space
        assertFalse(DateTime.isValidDateTime("1-4-17 1630")); // missing padded zeroes
        assertFalse(DateTime.isValidDateTime("1630")); // only time without date

        // valid start date time
        assertTrue(DateTime.isValidDateTime("01-04-17 1630"));
        assertTrue(DateTime.isValidDateTime("01-04-17"));
    }

}