|
19 | 19 | */ |
20 | 20 | package de.sfuhrm.sudoku; |
21 | 21 |
|
| 22 | +import org.junit.jupiter.api.Test; |
22 | 23 | import org.junit.jupiter.params.ParameterizedTest; |
23 | 24 | import org.junit.jupiter.params.provider.Arguments; |
24 | 25 | import org.junit.jupiter.params.provider.MethodSource; |
25 | 26 |
|
| 27 | +import java.util.List; |
26 | 28 | import java.util.stream.Stream; |
27 | 29 |
|
| 30 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
28 | 31 | import static org.junit.jupiter.api.Assertions.assertFalse; |
| 32 | +import static org.junit.jupiter.api.Assertions.assertNotEquals; |
29 | 33 | import static org.junit.jupiter.api.Assertions.assertTrue; |
30 | 34 |
|
31 | 35 | /** |
@@ -139,4 +143,28 @@ public void testValidValueWithTooSmall(GameSchema schema) { |
139 | 143 | public void testValidValueWithTooBig(GameSchema schema) { |
140 | 144 | assertFalse(schema.validValue((byte)(schema.getMaximumValue() + 1))); |
141 | 145 | } |
| 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 | + } |
142 | 170 | } |
0 commit comments