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 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

@@ -357,16 +357,17 @@
 cription
+ 
 %22;%0A    S
@@ -481,16 +481,903 @@
 love%22;%0A%0A
+    @Test%0A    public void sortDescriptions() %7B%0A        try %7B%0A            Description a = new Description(description + %22a%22);%0A            Description b = new Description(description + %22b%22);%0A            Description c = new Description(description + %22c%22);%0A            int ab = a.compareTo(b);%0A            assertEquals(ab,-1);%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%3CDescription%3E actual = new ArrayList%3CDescription%3E(Arrays.asList(b,c,a));%0A            Collections.sort(actual);%0A%0A            ArrayList%3CDescription%3E expected = new ArrayList%3CDescription%3E(Arrays.asList(a,b,c));%0A%0A            assertEquals(actual, expected);%0A        %7D catch (Exception e) %7B%0A            e.printStackTrace();%0A            fail();%0A        %7D%0A    %7D%0A%0A
     @Tes
@@ -1490,17 +1490,16 @@
 tion + %22
- 
 a%22), new
@@ -1673,17 +1673,16 @@
 tion + %22
- 
 b%22), new
@@ -1856,17 +1856,16 @@
 tion + %22
- 
 c%22), new

test description sort