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

import org.junit.jupiter.api.Test;

public class FourTest
{
    @Test
    public void testPartA()
    {
        SumOrSameGame game = new SumOrSameGame(75, 100);

        assertEquals(75, game.puzzle.length);
        assertEquals(100, game.puzzle[0].length);

        int[] counts = new int[9]; // index is value - 1

        for(int[] row : game.puzzle)
            for(int n : row)
                counts[n-1]++;

        for(int c : counts)
            assertTrue(c > 0);
    }

    @Test
    public void testPartBAgainstExample1()
    {
        SumOrSameGame game = new SumOrSameGame();

        game.puzzle = new int[][] {
            {0, 7, 9, 0},
            {7, 4, 1, 6},
            {8, 4, 1, 8}
        };

        assertTrue(game.clearPair(0, 1));

        assertArrayEquals(
                new int[][] {
                    {0, 0, 9, 0},
                    {0, 4, 1, 6},
                    {8, 4, 1, 8}
                },
                game.puzzle);
    }

    @Test
    public void testPartBAgainstExample2()
    {
        SumOrSameGame game = new SumOrSameGame();

        game.puzzle = new int[][] {
            {1, 2, 3, 4},
            {5, 6, 7, 8},
            {5, 4, 1, 2}
        };

        assertFalse(game.clearPair(2, 2));

        assertArrayEquals(
                new int[][] {
                    {1, 2, 3, 4},
                    {5, 6, 7, 8},
                    {5, 4, 1, 2}
                },
                game.puzzle);
    }

    @Test
    public void testPartBAgainstExample3()
    {
        SumOrSameGame game = new SumOrSameGame();

        game.puzzle = new int[][] {
            {8, 1, 0, 5},
            {0, 4, 3, 6},
            {3, 4, 5, 8}
        };

        assertTrue(game.clearPair(1, 1));

        if(game.puzzle[1][3] == 0)
        {
            assertArrayEquals(
                    new int[][] {
                        {8, 1, 0, 5},
                        {0, 0, 3, 0},
                        {3, 4, 5, 8}
                    },
                    game.puzzle);
        }
        else
        {
            assertArrayEquals(
                    new int[][] {
                        {8, 1, 0, 5},
                        {0, 0, 3, 6},
                        {3, 0, 5, 8}
                    },
                    game.puzzle);
        }
    }

    @Test
    public void testPartBAgainstExample4()
    {
        SumOrSameGame game = new SumOrSameGame();

        game.puzzle = new int[][] {
            {1, 7, 9},
            {2, 6, 5},
            {4, 4, 4}
        };

        assertTrue(game.clearPair(0, 2));

        assertArrayEquals(
                new int[][] {
                    {0, 7, 0},
                    {2, 6, 5},
                    {4, 4, 4}
                },
                game.puzzle);
    }
}
