View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.example.demo.sudoku;
21  
22  import org.junit.jupiter.api.Assertions;
23  import org.junit.jupiter.api.Test;
24  
25  public class SudokuUnitTest {
26  
27    private static final Sudoku TRIVIAL = new Sudoku(new byte[]{
28        0, 1, 2, 3, 4, 5, 6, 7, 8,
29        3, 4, 5, 6, 7, 8, 0, 1, 2,
30        6, 7, 8, 0, 1, 2, 3, 4, 5,
31  
32        1, 2, 3, 4, 5, 6, 7, 8, 0,
33        4, 5, 6, 7, 8, 0, 1, 2, 3,
34        7, 8, 0, 1, 2, 3, 4, 5, 6,
35  
36        2, 3, 4, 5, 6, 7, 8, 0, 1,
37        5, 6, 7, 8, 0, 1, 2, 3, 4,
38        8, 0, 1, 2, 3, 4, 5, 6, 7,
39    });
40  
41    private static final Sudoku WRONG = new Sudoku(new byte[]{
42        0, -1, -1, -1, -1, -1, -1, -1, 0,
43        -1, -1, -1, -1, -1, -1, -1, -1, -1,
44        -1, -1, -1, -1, -1, -1, -1, -1, -1,
45  
46        -1, -1, -1, -1, 0, -1, -1, -1, -1,
47        -1, -1, -1, -1, -1, -1, -1, -1, -1,
48        -1, -1, -1, -1, -1, 0, -1, -1, -1,
49  
50        -1, -1, -1, -1, -1, -1, -1, -1, -1,
51        -1, -1, -1, -1, -1, -1, -1, -1, -1,
52        -1, -1, -1, -1, -1, 0, -1, -1, -1,
53    });
54  
55    @Test
56    public void testCheckRowRules() {
57      Assertions.assertTrue(TRIVIAL.checkRowRules());
58      Assertions.assertFalse(WRONG.checkRowRules());
59    }
60  
61    @Test
62    public void testCheckColumnRules() {
63      Assertions.assertTrue(TRIVIAL.checkColumnRules());
64      Assertions.assertFalse(WRONG.checkColumnRules());
65    }
66  
67    @Test
68    public void testCheckSquareRules() {
69      Assertions.assertTrue(TRIVIAL.checkSquareRules());
70      Assertions.assertFalse(WRONG.checkSquareRules());
71    }
72  
73  }