package pp.battleship.model;

import org.junit.Test;
import pp.util.RandomPositionIterator;

import java.util.HashSet;
import java.util.Set;

import static org.junit.Assert.fail;

public class RandomPositionIteratorTest {
    @Test
    public void testEqualsOccurs() {
        final var it = new RandomPositionIterator<>(IntPoint::new, 2, 2);
        final Set<IntPoint> positions = new HashSet<>();
        positions.add(new IntPoint(0, 0));
        positions.add(new IntPoint(1, 1));

        int n = 0;
        while (it.hasNext() && ++n <= 3) {
            if (!positions.add(it.next()))
                return;
        }
        fail("not found");
    }

    @Test
    public void testNoEquals() {
        final var it = new RandomPositionIterator<>(IntPoint::new, 2, 2);
        final Set<IntPoint> positions = new HashSet<>();

        while (it.hasNext()) {
            if (!positions.add(it.next()))
                fail("not found");
        }
    }
}
