import junit.framework.TestCase;

/**
 * Unit tests for the CS139 ArrayList Document Lab.
 * 
 * @author Nathan Sprague - Alvin Chao - modifications for JUnit3
 * @version 4/2017
 */
public class DocumentTest extends TestCase {

    private Document docEmpty = new Document();  
    
    private Document docFull = new Document();
    
    
    /**
     * testCopy.
     */
     
    public void testCopyConstructorCreatesEqualDocuments() {
        Document temp = new Document();
        temp.appendLine("Hello There");
        Document copy = new Document(temp);
        assertTrue(copy.equals(temp));

        copy = new Document(docEmpty);
        assertTrue(copy.equals(docEmpty));
    }


    /**
     * Test constructor no alias.
     */
     
    public void testCopyConstructorDoesNotAliasArrayList() {
        docFull.appendLine("Hello There");
        Document copy = new Document(docFull);

        copy.deleteLine(0);

        assertFalse(copy.equals(docFull));
    }

    /** 
     * test toString Full.
     */
     
    public void testToStringFull() {
        docFull.appendLine("Hello There");
        docFull.appendLine("This is cool.");
        assertEquals("Hello There\nThis is cool.\n", docFull.toString());
    }

    /**
     * test toString empty.
     */
     
    public void testToStringEmpty() {
        assertEquals("", docEmpty.toString());
    }

    /**
     * test deleteLine.
     */
     
    public void testDeleteLine() {
        docFull.appendLine("Hello There");
        docFull.appendLine("This is cool.");
        docFull.deleteLine(0);        
        assertEquals("This is cool.\n", docFull.toString());
    }

    /**
     * test Longest Single.
     */
     
    public void testLongestSingle() {
        docEmpty.appendLine("aaaa");
        assertEquals("aaaa", docEmpty.longestLine());
    }

    /** 
     * test Longest First.
     */
     
    public void testLongestFirst() {
        docEmpty.appendLine("aaaa");
        docEmpty.appendLine("aaa");
        docEmpty.appendLine("aa");
        assertEquals("aaaa", docEmpty.longestLine());
    }

    /**
     * test longest Middle.
     */
     
    public void testLongestMiddle() {
        docEmpty.appendLine("aaa");
        docEmpty.appendLine("aaaa");
        docEmpty.appendLine("aa");
        assertEquals("aaaa", docEmpty.longestLine());
    }

    /**
     * test Longest Last.
     */
     
    public void testLongestLast() {
        docEmpty.appendLine("aaa");
        docEmpty.appendLine("aa");
        docEmpty.appendLine("aaaa");
        assertEquals("aaaa", docEmpty.longestLine());
    }

    /**
     * test Longest Empty Doc.
     */
     
    public void testLongestEmptyDocument() {
        assertEquals("", docEmpty.longestLine());
    }

    /**
     * testEquals not equals.
     */
     
    public void testEqualsNotEqual() {
        docFull.appendLine("Hello There");
        assertFalse(docEmpty.equals(docFull));
        assertFalse(docFull.equals(docEmpty));
    }
    
    /**
     * testEquals Same Document.
     */
     
    public void testEqualsSameDocument() {
        assertTrue(docEmpty.equals(docEmpty));
        assertTrue(docFull.equals(docFull));
    }

    /** 
     * testEquals diff but equal.
     */
     
    public void testEqualsDifferentButEqual() {
        docFull.appendLine("Hello There");
        docFull.appendLine("This is cool.");
        Document docFullCopy = new Document();

        docFullCopy.appendLine("Hello There");
        docFullCopy.appendLine("This is cool.");

        assertTrue(docFull.equals(docFullCopy));
    }

}
