import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.junit.jupiter.api.Test;

public class ArrayListPracticeTest
{
    @Test
    public void testRemoveWordSimple()
    {
        ArrayList<String> words = new ArrayList<String>(Arrays.asList(
                "the", "happy", "cat", "ate", "the", "unhappy", "rat"));

        ArrayListPractice.removeWord(words, "the");
        
        assertEquals(Arrays.asList(
                "happy", "cat", "ate", "unhappy", "rat"),
                words);
    }

    @Test
    public void testRemoveWordAdjacent()
    {
        ArrayList<String> words = new ArrayList<String>(Arrays.asList(
                "a", "blue", "blue", "blue", "bird","ate", "a",
                "blue", "blue", "worm", "too", "much", "blue"));
        
        ArrayListPractice.removeWord(words, "blue");
        
        assertEquals(Arrays.asList(
                "a", "bird", "ate", "a", "worm", "too", "much"),
                words);
    }

    @Test
    public void testDuplicateMatching()
    {
        ArrayList<Integer> list = new ArrayList<Integer>(Arrays.asList(
                5, 7, 5, 7, 7, 9, 5, 7));

        ArrayListPractice.duplicateMatching(list, 7);
        
        assertEquals(Arrays.asList(
                5, 7, 7, 5, 7, 7, 7, 7, 9, 5, 7, 7),
                list);
    }

    @Test
    public void testRemoveAdjacentDuplicates()
    {
        ArrayList<Integer> list = new ArrayList<Integer>(Arrays.asList(
                5, 7, 7, 5, 3, 7, 7, 7, 8, 7, 7, 7, 7));

        ArrayListPractice.removeAdjacentDuplicates(list);
        
        assertEquals(Arrays.asList(
                5, 7, 5, 3, 7, 8, 7),
                list);
    }

    @Test
    public void testRemoveAdjacentDuplicatesSmall()
    {
        ArrayList<Integer> list = new ArrayList<Integer>();
        
        ArrayListPractice.removeAdjacentDuplicates(list);
        
        assertEquals(new ArrayList<Integer>(), list); // empty list


        list = new ArrayList<Integer>();
        list.add(5);

        ArrayListPractice.removeAdjacentDuplicates(list);
        
        assertEquals(Arrays.asList(
                5),
                list);
    }
}
