Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
4.7 kB
5
Indexable
Never
package de.uni_bremen.pi2;

// INVALID, VALID und SOLVED können direkt verwendet werden.
import static de.uni_bremen.pi2.InsectHotel.Result.*;
import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

public class InsectHotelTest
{
    /**
     * Ein komplexer Test aus dem ursprünglichen Puzzle.
     * Ist standardmäßig deaktiviert.
     */
    @Test
    public void testComplex()
    {
        final String[] puzzle = {
                "X       ",
                " OO     ",
                "   X   O",
                "O       ",
                "  XO  X ",
                "X X     ",
                "     X  ",
                "     X  "
        };
        final String[] solution = {
                "XXOOXOOX",
                "XOOXOOXX",
                "OOXXOXXO",
                "OXOOXXOX",
                "XOXOXOXO",
                "XOXXOOXO",
                "OXOXOXOX",
                "OXXOXXOO"
        };
        assertArrayEquals(solution, InsectHotel.solve(puzzle));
    }

    // Die eigentlichen Tests...
    @Test
    public void testFillHardPuzzle() {
        final String[] puzzle = {
                "X       ",
                " OO     ",
                "   X   O",
                "O       ",
                "  XO  X ",
                "X X     ",
                "     X  ",
                "     X  "
        };
        final String entries = "XOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXO";
        final String[] expected = {
                "XXOXOXOX",
                "OOOXOXOX",
                "OXOXXOXO",
                "OOXOXOXO",
                "XOXOXOXX",
                "XOXXOXOX",
                "OXO  X  ",
                "     X  "
        };
        assertArrayEquals(expected, InsectHotel.fill(puzzle, entries));
    }

    @Test
    public void testCheckHardPuzzle() {
        final String[] validPuzzle = {
                "XXOOXOOX",
                "XOOXOOXX",
                "OOXXOXXO",
                "OXOOXXOX",
                "XOXOXOXO",
                "XOXXOOXO",
                "OXOXOXOX",
                "OXXOXXOO"
        };
        assertEquals(SOLVED, InsectHotel.check(validPuzzle));
    }
    @Test
    public void testCheckValid() {
        final String[] hotel = {
                "XO ",
                "OX ",
                "   "
        };
        assertEquals(VALID, InsectHotel.check(hotel));
    }
    @Test
    public void testCheckInvalid() {
        final String[] hotel = {
                "XXO",
                "OXO",
                "   "
        };
        assertEquals(INVALID, InsectHotel.check(hotel));
    }
    @Test
    public void testCheckSolved() {
        final String[] hotel = {
                "XOX",
                "OXO",
                "XOX"
        };
        assertNull(SOLVED, InsectHotel.check(hotel));
    }


    @Test
    public void testSolveEasyPuzzle() {
        final String[] puzzle = {
                "X O",
                " O ",
                "X  "
        };
        final String[] solution = {
                "XOO",
                "OXO",
                "XOX"
        };
        assertArrayEquals(solution, InsectHotel.solve(puzzle));
    }
    @Test
    public void testSolveFalseWithoutSolution() {
        final String[] puzzle = {
                "XOX",
                "OXO",
                "XOX"
        };
        assertNull(InsectHotel.solve(puzzle));
    }
    @Test
    public void testSolveHalfFilled() {
        final String[] puzzle = {
                "XO ",
                " OX",
                "   "
        };
        final String[] solution = {
                "XOX",
                "OOX",
                "XXO"
        };
        assertArrayEquals(solution, InsectHotel.solve(puzzle));
    }


    @Test
    public void testSolveHardPuzzle() {
        final String[] puzzle = {
                "X       ",
                " OO     ",
                "   X   O",
                "O       ",
                "  XO  X ",
                "X X     ",
                "     X  ",
                "     X  "
        };
        final String[] expected = {
                "XXOOXOOX",
                "XOOXOOXX",
                "OOXXOXXO",
                "OXOOXXOX",
                "XOXOXOXO",
                "XOXXOOXO",
                "OXOXOXOX",
                "OXXOXXOO"
        };
        assertArrayEquals(expected, InsectHotel.solve(puzzle));
    }
}

Leave a Comment