From 10c4518ed0951af816fd46c24d65908ed9ee8d05 Mon Sep 17 00:00:00 2001 From: Max Wenzel Date: Wed, 12 Jan 2022 13:40:34 +0100 Subject: [PATCH] add setState --- .../fleetstorm/matchfield/Coordinate.java | 4 ++++ .../fleetstorm/matchfield/CoordinateTest.java | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/main/java/de/tims/fleetstorm/matchfield/Coordinate.java b/src/main/java/de/tims/fleetstorm/matchfield/Coordinate.java index dcace9e..2f7ec5a 100644 --- a/src/main/java/de/tims/fleetstorm/matchfield/Coordinate.java +++ b/src/main/java/de/tims/fleetstorm/matchfield/Coordinate.java @@ -27,4 +27,8 @@ public class Coordinate { public int getState() { return this.state; } + + public void setState(int state) { + this.state = state; + } } diff --git a/src/test/java/de/tims/fleetstorm/matchfield/CoordinateTest.java b/src/test/java/de/tims/fleetstorm/matchfield/CoordinateTest.java index d37a398..f7bb7f1 100644 --- a/src/test/java/de/tims/fleetstorm/matchfield/CoordinateTest.java +++ b/src/test/java/de/tims/fleetstorm/matchfield/CoordinateTest.java @@ -22,4 +22,23 @@ class CoordinateTest { assertEquals(coordinate.getState(), Coordinate.EMPTY); assertEquals(coordinate.getState(), 0); } + + @Test + void testGetAndSetForAllStates() { + coordinate.setState(Coordinate.SHIP); + assertEquals(coordinate.getState(), Coordinate.SHIP); + assertEquals(coordinate.getState(), 1); + + coordinate.setState(Coordinate.SHOT); + assertEquals(coordinate.getState(), Coordinate.SHOT); + assertEquals(coordinate.getState(), 2); + + coordinate.setState(Coordinate.HIT); + assertEquals(coordinate.getState(), Coordinate.HIT); + assertEquals(coordinate.getState(), 3); + + coordinate.setState(Coordinate.EMPTY); + assertEquals(coordinate.getState(), Coordinate.EMPTY); + assertEquals(coordinate.getState(), 0); + } }