package test.uebung.uebung09.collection;

import java.util.Iterator;

import uebung09.collection.Set;
import uebung09.collection.SetFactory;
import java.util.NoSuchElementException;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class SetTest {

    static String a = "test";
    static String b = "test2";
    static String c = "test3";


    public static void main(String[] args) {
    }

    @Test
    public void EmptySetTest(){

        Set<String> test = SetFactory.create();

        Iterator<String> i = test.iterator();

        assertFalse(i.hasNext());
        assertThrows(NoSuchElementException.class, i::next);
        assertFalse(test.contains(a));
        assertEquals(0,test.size());
        assertTrue(test.isEmpty());
    }

    @Test
    public void SingeltonSetTest(){

        Set<String> test = SetFactory.create(a);

        Iterator<String> i = test.iterator();

        assertTrue(i.hasNext());
        assertTrue(a == i.next());
        assertFalse(i.hasNext());
        assertThrows(NoSuchElementException.class, i::next);
        assertTrue(test.contains(a));
        assertEquals(1,test.size());
        assertFalse(test.isEmpty());
    }

    @Test
    public void BigSetTest() {

        Set<String> test = SetFactory.create(a,b,c);

        Iterator<String> i = test.iterator();

        assertTrue(i.hasNext());
        assertTrue(a == i.next());
        assertTrue(i.hasNext());
        assertTrue(a == i.next());
        assertTrue(i.hasNext());
        assertTrue(a == i.next());
        assertFalse(i.hasNext());
        assertThrows(NoSuchElementException.class, i::next);
        assertTrue(test.contains(a));
        assertEquals(1,test.size());
        assertFalse(test.isEmpty());
    }
}
