package test.uebung.uebung09.iterator;

import org.junit.Test;

import java.util.Iterator;
import java.util.NoSuchElementException;
import uebung09.iterator.Array2dIterator;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

public class Array2dIteratorTest {
    @Test
    public void testArray2dIterator() {
        final String[][] array = {{}, {"foo", "bar"}, {"baz"}, {}};
        final Iterator<String> it = new Array2dIterator<>(array);
        assertTrue(it.hasNext());
        assertEquals("foo", it.next());
        assertTrue(it.hasNext());
        assertEquals("bar", it.next());
        assertTrue(it.hasNext());
        assertEquals("baz", it.next());
        assertFalse(it.hasNext());
        assertThrows(NoSuchElementException.class, it::next);
    }

    @Test
    public void testArray2dIteratorOnlyEmpty() {
        final String[][] array = {{}, {}, {}};
        final Iterator<String> it = new Array2dIterator<>(array);
        assertFalse(it.hasNext());
        assertThrows(NoSuchElementException.class, it::next);
    }

    @Test
    public void testArray2dIteratorEmpty() {
        final String[][] array = {};
        final Iterator<String> it = new Array2dIterator<>(array);
        assertFalse(it.hasNext());
        assertThrows(NoSuchElementException.class, it::next);
    }
}
