Skip to content

Commit ab9d660

Browse files
committed
Improve coverage
1 parent 4259495 commit ab9d660

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package de.sfuhrm.sudoku;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.assertEquals;
6+
7+
class CellIndexTest {
8+
9+
@Test
10+
void testToString() {
11+
CellIndex cellIndex = new CellIndex();
12+
cellIndex.row = 5;
13+
cellIndex.column = 10;
14+
15+
assertEquals("CellIndex{row=5, column=10}", cellIndex.toString());
16+
}
17+
}

sudoku/src/test/java/de/sfuhrm/sudoku/GameSchemaImplTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@
1919
*/
2020
package de.sfuhrm.sudoku;
2121

22+
import org.junit.jupiter.api.Test;
2223
import org.junit.jupiter.params.ParameterizedTest;
2324
import org.junit.jupiter.params.provider.Arguments;
2425
import org.junit.jupiter.params.provider.MethodSource;
2526

27+
import java.util.List;
2628
import java.util.stream.Stream;
2729

30+
import static org.junit.jupiter.api.Assertions.assertEquals;
2831
import static org.junit.jupiter.api.Assertions.assertFalse;
32+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
2933
import static org.junit.jupiter.api.Assertions.assertTrue;
3034

3135
/**
@@ -139,4 +143,28 @@ public void testValidValueWithTooSmall(GameSchema schema) {
139143
public void testValidValueWithTooBig(GameSchema schema) {
140144
assertFalse(schema.validValue((byte)(schema.getMaximumValue() + 1)));
141145
}
146+
147+
@ParameterizedTest
148+
@MethodSource("allGameSchemas")
149+
public void testEqualsAndHashCode(GameSchema schema) {
150+
GameSchemaImpl copy = new GameSchemaImpl(
151+
schema.getUnsetValue(),
152+
schema.getMinimumValue(),
153+
schema.getMaximumValue(),
154+
schema.getWidth(),
155+
schema.getBlockWidth());
156+
157+
assertEquals(schema, copy);
158+
assertEquals(schema.hashCode(), copy.hashCode());
159+
assertNotEquals(schema, null);
160+
assertNotEquals(schema, new Object());
161+
}
162+
163+
@Test
164+
public void testEqualsWithDifferentSchemas() {
165+
List<GameSchema> schemas = GameSchemas.getSupportedGameSchemas();
166+
if (schemas.size() >= 2) {
167+
assertNotEquals(schemas.get(0), schemas.get(1));
168+
}
169+
}
142170
}

0 commit comments

Comments
 (0)