package pl.nn44.battleship.model;

import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.junit.Assert;
import org.junit.Test;

import java.util.List;

public class CoordTests {

    private final String has4 = "has 4 neighbours";

    private Matcher<Coord> isNeighbourOf(List<Coord> coords) {
        return new TypeSafeMatcher<Coord>() {
            @Override
            protected boolean matchesSafely(Coord item) {
                return coords.contains(item);
            }

            @Override
            public void describeTo(Description description) {
                description.appendValue("actual coord in list");
                description.appendValue(coords);
            }
        };
    }

    @Test
    public void checkNeighbours00() {
        List<Coord> neighbours = new Coord(0, 0).neighbours();

        Assert.assertSame(has4, 4, neighbours.size());
        Assert.assertThat(new Coord(-1, 0), isNeighbourOf(neighbours));
        Assert.assertThat(new Coord(1, 0), isNeighbourOf(neighbours));
        Assert.assertThat(new Coord(0, -1), isNeighbourOf(neighbours));
        Assert.assertThat(new Coord(0, 1), isNeighbourOf(neighbours));
    }

    @Test
    public void checkNeighbours64() {
        List<Coord> neighbours = new Coord(6, 4).neighbours();

        Assert.assertSame(has4, 4, neighbours.size());
        Assert.assertThat(new Coord(5, 4), isNeighbourOf(neighbours));
        Assert.assertThat(new Coord(7, 4), isNeighbourOf(neighbours));
        Assert.assertThat(new Coord(6, 3), isNeighbourOf(neighbours));
        Assert.assertThat(new Coord(6, 5), isNeighbourOf(neighbours));
    }
}

@@ -309,16 +309,18 @@
 oord%3E is
+In
 Neighbou
@@ -320,18 +320,20 @@
 eighbour
-Of
+List
 (List%3CCo
@@ -969,32 +969,34 @@
 Coord(-1, 0), is
+In
 NeighbourOf(neig
@@ -980,34 +980,36 @@
 ), isInNeighbour
-Of
+List
 (neighbours));%0A 
@@ -1048,24 +1048,26 @@
 rd(1, 0), is
+In
 NeighbourOf(
@@ -1055,34 +1055,36 @@
 ), isInNeighbour
-Of
+List
 (neighbours));%0A 
@@ -1124,24 +1124,26 @@
 d(0, -1), is
+In
 NeighbourOf(
@@ -1131,34 +1131,36 @@
 ), isInNeighbour
-Of
+List
 (neighbours));%0A 
@@ -1199,24 +1199,26 @@
 rd(0, 1), is
+In
 NeighbourOf(
@@ -1206,34 +1206,36 @@
 ), isInNeighbour
-Of
+List
 (neighbours));%0A 
@@ -1444,32 +1444,34 @@
  Coord(5, 4), is
+In
 NeighbourOf(neig
@@ -1455,34 +1455,36 @@
 ), isInNeighbour
-Of
+List
 (neighbours));%0A 
@@ -1523,24 +1523,26 @@
 rd(7, 4), is
+In
 NeighbourOf(
@@ -1530,34 +1530,36 @@
 ), isInNeighbour
-Of
+List
 (neighbours));%0A 
@@ -1598,24 +1598,26 @@
 rd(6, 3), is
+In
 NeighbourOf(
@@ -1605,34 +1605,36 @@
 ), isInNeighbour
-Of
+List
 (neighbours));%0A 
@@ -1677,16 +1677,18 @@
 , 5), is
+In
 Neighbou
@@ -1692,10 +1692,12 @@
 bour
-Of
+List
 (nei

test for current coord model