package anabalica.github.io.meowletters;

import junit.framework.*;

import java.util.ArrayList;

import anabalica.github.io.meowletters.letters.Letter;
import anabalica.github.io.meowletters.letters.LetterChain;

/**
 * Test LetterChain class
 *
 * @author Ana Balica
 */
public class LetterChainTest extends TestCase {
    protected LetterChain letterChain = new LetterChain();
    protected ArrayList<Letter> chain = new ArrayList<Letter>();

    public void testIsValid() {
        // Test empty chain
        assertTrue(letterChain.isValid());

        // Test chain with a single element
        chain.add(new Letter("K"));
        letterChain.setChain(chain);
        assertTrue(letterChain.isValid());

        // Test a very long chain
        chain.clear();
        String longChain = "QWFPGJLUYARSTDHNEZXCVBKMWQFPGJLRSTDHNE";
        for (int i = 0; i < longChain.length(); i++) {
            chain.add(new Letter(Character.toString(longChain.charAt(i))));
        }
        assertFalse(letterChain.isValid());

        // Test two consecutive elements
        chain.clear();
        chain.add(new Letter("G"));
        chain.add(new Letter("H"));
        assertTrue(letterChain.isValid());

        // Test three non consecutive elements
        chain.add(new Letter("B"));
        assertFalse(letterChain.isValid());

        // Test circular chain elements
        chain.clear();
        chain.add(new Letter("Z"));
        chain.add(new Letter("A"));
        assertFalse(letterChain.isValid());
    }

    public void testAdd() {
        letterChain.add(new Letter("A"));
        assertFalse(letterChain.isEmpty());
        assertEquals(letterChain.size(), 1);
        assertTrue(letterChain.getChain().get(0).equals(new Letter("A")));

        letterChain.add(new Letter("B"));
        assertEquals(letterChain.size(), 2);
        assertTrue(letterChain.getChain().get(1).equals(new Letter("B")));
    }
}

@@ -1534,24 +1534,72 @@
 testAdd() %7B%0A
+        // Test adding one element to the chain%0A
         lett
@@ -1723,36 +1723,38 @@
 ;%0A        assert
-True
+Equals
 (letterChain.get
@@ -1757,30 +1757,13 @@
 .get
-Chain().get(0).equals(
+(0), 
 new 
@@ -1774,20 +1774,58 @@
 er(%22A%22))
-)
 ;%0A%0A
+        // Test adding another element%0A
         
@@ -1909,36 +1909,38 @@
 ;%0A        assert
-True
+Equals
 (letterChain.get
@@ -1943,30 +1943,13 @@
 .get
-Chain().get(1).equals(
+(1), 
 new 
@@ -1960,17 +1960,16 @@
 er(%22B%22))
-)
 ;%0A    %7D%0A

fix testAdd of LetterChainTest