package seedu.task.model.task;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

import org.junit.Test;

import seedu.task.model.tag.UniqueTagList;
//@@author A0163559U
public class TaskComparableTest {

    String description = "task description ";
    String priority = "2";
    String timing = "03/03/2017";
    String tag1 = "friendship";
    String tag2 = "love";

    @Test
    public void sortDescriptions() {
        try {
            Description a = new Description(description + "a");
            Description b = new Description(description + "b");
            Description c = new Description(description + "c");
            int ab = a.compareTo(b);
            assertEquals(ab,-1);
            int ac = a.compareTo(c);
            assertEquals(ac,-2);

            int ba = b.compareTo(a);
            assertEquals(ba, 1);

            assertEquals(0, a.compareTo(a));

            ArrayList<Description> actual = new ArrayList<Description>(Arrays.asList(b,c,a));
            Collections.sort(actual);

            ArrayList<Description> expected = new ArrayList<Description>(Arrays.asList(a,b,c));

            assertEquals(actual, expected);
        } catch (Exception e) {
            e.printStackTrace();
            fail();
        }
    }

    @Test
    public void sortByComplete() {

        try {
            Task t1 = new Task(new Description(description + "a"), new Priority(priority),
                    new Timing(timing), new Timing(timing), new UniqueTagList(tag1, tag2));
            Task t2 = new Task(new Description(description + "b"), new Priority(priority),
                    new Timing(timing), new Timing(timing), new UniqueTagList(tag1, tag2));
            Task t3 = new Task(new Description(description + "c"), new Priority(priority),
                    new Timing(timing), new Timing(timing), new UniqueTagList(tag1, tag2));

            //add two near identical tasks
            ArrayList<Task> al = new ArrayList<Task>(Arrays.asList(t1, t2));

            //complete one of them and expect completed task to move to end of list
            t1.setComplete();
            sort_and_assertEquals(al, new ArrayList<Task>(Arrays.asList(t2, t1)));

            //add an uncompleted task to the end of the list
            al.add(t3);
            sort_and_assertEquals(al, new ArrayList<Task>(Arrays.asList(t2, t3, t1)));

            //complete a task in the middle and expect it to move to the end
            t3.setComplete();
            sort_and_assertEquals(al, new ArrayList<Task>(Arrays.asList(t2, t1, t3)));

            //complete a task and expect it to move to the middle
            t2.setComplete();
            sort_and_assertEquals(al, new ArrayList<Task>(Arrays.asList(t1, t2, t3)));

        } catch (Exception e) {
            e.printStackTrace();
            fail();
        }
    }

    private void sort_and_assertEquals(ArrayList<Task> actual, ArrayList<Task> expected) {
        Collections.sort(actual);
        assertEquals(actual, expected);
    }

    @SuppressWarnings("unused")
    private void printDescriptions(ArrayList<Task> al) {
        System.out.println("Starting print...");
        for (Task t : al) {
            System.out.println(t.getDescription());
        }
        System.out.println("Ending print.");

    }
}
//@@author

@@ -730,24 +730,25 @@
 ion + %22c%22);%0A
+%0A
             
@@ -805,16 +805,17 @@
 ab,-1);%0A
+%0A
         
@@ -1264,24 +1264,25 @@
  expected);%0A
+%0A
         %7D ca
@@ -1401,16 +1401,837 @@
 oid sort
+Priorities() %7B%0A        try %7B%0A            Priority a = new Priority(%221%22);%0A            Priority b = new Priority(%222%22);%0A            Priority c = new Priority(%223%22);%0A%0A            int ab = a.compareTo(b);%0A            assertEquals(ab,-1);%0A%0A            int ac = a.compareTo(c);%0A            assertEquals(ac,-2);%0A%0A            int ba = b.compareTo(a);%0A            assertEquals(ba, 1);%0A%0A            assertEquals(0, a.compareTo(a));%0A%0A            ArrayList%3CPriority%3E actual = new ArrayList%3CPriority%3E(Arrays.asList(b,c,a));%0A            Collections.sort(actual);%0A%0A            ArrayList%3CPriority%3E expected = new ArrayList%3CPriority%3E(Arrays.asList(a,b,c));%0A%0A            assertEquals(actual, expected);%0A%0A        %7D catch (Exception e) %7B%0A            e.printStackTrace();%0A            fail();%0A        %7D%0A    %7D%0A%0A    @Test%0A    public void sortTasks
 ByComple
@@ -2232,16 +2232,20 @@
 Complete
+ness
 () %7B%0A%0A  

test priority sort