From 6e5e212c3e6c299cb2a09a8f65f4b7db2724b519 Mon Sep 17 00:00:00 2001 From: Lorenz Hohmann Date: Thu, 16 Dec 2021 15:37:33 +0100 Subject: [PATCH] matchfield: added setState() function --- .../matchfield/MatchfieldCreation.java | 6 +++++- .../matchfield/MatchfieldCreationTest.java | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/tims/fleetstorm/matchfield/MatchfieldCreation.java b/src/main/java/de/tims/fleetstorm/matchfield/MatchfieldCreation.java index 6ad69b3..2f604a6 100644 --- a/src/main/java/de/tims/fleetstorm/matchfield/MatchfieldCreation.java +++ b/src/main/java/de/tims/fleetstorm/matchfield/MatchfieldCreation.java @@ -26,7 +26,11 @@ public class MatchfieldCreation { } public int getState(int x, int y) { - return 1; + return this.matchfield[x][y]; + } + + public void setState(int x, int y, int state) { + this.matchfield[x][y] = state; } } diff --git a/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java b/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java index 37c1ede..ee790cb 100644 --- a/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java +++ b/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java @@ -33,7 +33,7 @@ class MatchfieldCreationTest { return Stream.of(Arguments.of("field size 10x10", 10, 100), Arguments.of("field size 15x15", 15, 225)); } - @ParameterizedTest(name = "matchfield change field is correct") + @ParameterizedTest(name = "matchfield get field is correct") @MethodSource("testMatchfieldGetFieldState") void testMatchfieldGetCorrectState(String testName, int x, int y, int expectedResult) { MatchfieldCreation matchfield = new MatchfieldCreation(10); @@ -46,4 +46,20 @@ class MatchfieldCreationTest { static Stream testMatchfieldGetFieldState() { return Stream.of(Arguments.of("field x:0 y:0 has initial state", 0, 0, 1)); } + + @ParameterizedTest(name = "matchfield change field is correct") + @MethodSource("testMatchfieldSetStateIsCorrect") + void testMatchfieldGetCorrectState(String testName, int x, int y, int state, int expectedResult) { + MatchfieldCreation matchfield = new MatchfieldCreation(10); + matchfield.createMatchfield(); + + matchfield.setState(x, y, state); + + int calcResult = matchfield.getState(x, y); + assertThat(calcResult).describedAs(testName).isEqualTo(expectedResult); + } + + static Stream testMatchfieldSetStateIsCorrect() { + return Stream.of(Arguments.of("field x:0 y:0 has state 2 after setState()", 0, 0, 2, 2)); + } }