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")));
    }
}

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() {
        // Test adding one element to the chain
        letterChain.add(new Letter("A"));
        assertFalse(letterChain.isEmpty());
        assertEquals(letterChain.size(), 1);
        assertEquals(letterChain.get(0), new Letter("A"));

        // Test adding another element
        letterChain.add(new Letter("B"));
        assertEquals(letterChain.size(), 2);
        assertEquals(letterChain.get(1), new Letter("B"));
    }
}

fix testAdd of LetterChainTest