<commit_before>package guitests;

import guitests.guihandles.TaskCardHandle;
import org.junit.Test;

import tars.commons.core.Messages;
import tars.commons.exceptions.IllegalValueException;
import tars.model.task.Name;
import tars.model.task.Priority;
import tars.testutil.TestTask;
import tars.testutil.TestUtil;

import static org.junit.Assert.assertTrue;

public class AddCommandTest extends TarsGuiTest {

    @Test
    public void add() {
        // add one task
        TestTask[] currentList = td.getTypicalTasks();
        TestTask taskToAdd = td.taskH;
        assertAddSuccess(taskToAdd, currentList);
        currentList = TestUtil.addTasksToList(currentList, taskToAdd);

        // add another task
        taskToAdd = td.taskI;
        assertAddSuccess(taskToAdd, currentList);
        currentList = TestUtil.addTasksToList(currentList, taskToAdd);

        // add duplicate task
        commandBox.runCommand(td.taskH.getAddCommand());
        assertResultMessage(Messages.MESSAGE_DUPLICATE_TASK);
        assertTrue(taskListPanel.isListMatching(currentList));

        // add to empty list
        commandBox.runCommand("clear");
        assertAddSuccess(td.taskA);

        // invalid command
        
        commandBox.runCommand("adds Johnny");
        assertResultMessage(Messages.MESSAGE_UNKNOWN_COMMAND);
        
        assertAddSuccess(td.taskA);
    }

    private void assertAddSuccess(TestTask taskToAdd, TestTask... currentList) {
        commandBox.runCommand(taskToAdd.getAddCommand());

        // confirm the new card contains the right data
        TaskCardHandle addedCard = taskListPanel.navigateToTask(taskToAdd.getName().taskName);
        assertMatching(taskToAdd, addedCard);

        // confirm the list now contains all previous tasks plus the new task
        TestTask[] expectedList = TestUtil.addTasksToList(currentList, taskToAdd);
        assertTrue(taskListPanel.isListMatching(expectedList));
    }

    //@@author A0140022H
    @Test
    public void addRecurring() {
        TestTask[] recurringList = new TestTask[0];
        recurringList = TestUtil.addTasksToList(recurringList, td.taskC, td.taskD);
        try {
            recurringList[1].setName(new Name("Task C"));
            recurringList[1].setPriority(new Priority("l"));
        } catch (IllegalValueException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        commandBox.runCommand("add Task C -dt 03/09/2016 1400 to 04/09/2016 1400 -p l -r 2 every day");
        assertTrue(taskListPanel.isListMatching(recurringList));
    }
}<commit_msg>Fix bug to prevent duplicate task added for recurring<commit_after>package guitests;

import guitests.guihandles.TaskCardHandle;
import org.junit.Test;

import tars.commons.core.Messages;
import tars.commons.exceptions.IllegalValueException;
import tars.model.task.Name;
import tars.model.task.Priority;
import tars.testutil.TestTask;
import tars.testutil.TestUtil;

import static org.junit.Assert.assertTrue;

public class AddCommandTest extends TarsGuiTest {

    @Test
    public void add() {
        // add one task
        TestTask[] currentList = td.getTypicalTasks();
        TestTask taskToAdd = td.taskH;
        assertAddSuccess(taskToAdd, currentList);
        currentList = TestUtil.addTasksToList(currentList, taskToAdd);

        // add another task
        taskToAdd = td.taskI;
        assertAddSuccess(taskToAdd, currentList);
        currentList = TestUtil.addTasksToList(currentList, taskToAdd);

        // add duplicate task
        commandBox.runCommand(td.taskH.getAddCommand());
        assertResultMessage(Messages.MESSAGE_DUPLICATE_TASK);
        assertTrue(taskListPanel.isListMatching(currentList));

        // add to empty list
        commandBox.runCommand("clear");
        assertAddSuccess(td.taskA);

        // invalid command
        
        commandBox.runCommand("adds Johnny");
        assertResultMessage(Messages.MESSAGE_UNKNOWN_COMMAND);
        
        assertAddSuccess(td.taskA);
    }

    private void assertAddSuccess(TestTask taskToAdd, TestTask... currentList) {
        commandBox.runCommand(taskToAdd.getAddCommand());

        // confirm the new card contains the right data
        TaskCardHandle addedCard = taskListPanel.navigateToTask(taskToAdd.getName().taskName);
        assertMatching(taskToAdd, addedCard);

        // confirm the list now contains all previous tasks plus the new task
        TestTask[] expectedList = TestUtil.addTasksToList(currentList, taskToAdd);
        assertTrue(taskListPanel.isListMatching(expectedList));
    }

    //@@author A0140022H
    @Test
    public void addRecurring() {
        TestTask[] recurringList = new TestTask[0];
        recurringList = TestUtil.addTasksToList(recurringList, td.taskC, td.taskD);
        try {
            recurringList[1].setName(new Name("Task C"));
            recurringList[1].setPriority(new Priority("l"));
        } catch (IllegalValueException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        commandBox.runCommand("clear");
        commandBox.runCommand("add Task C -dt 03/09/2016 1400 to 04/09/2016 1400 -p l -r 2 every day");
        assertTrue(taskListPanel.isListMatching(recurringList));
    }
}
{'fraction_non_alphanumeric': 0.09547169811320755, 'fraction_numerical': 0.013207547169811321, 'mean_word_length': 3.012869038607116, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4031245', 'n_tokens_mistral': 1554, 'n_tokens_neox': 1495, 'n_words': 315}