From b4af36cb01cbf75fc00e9354afe3a6739bd8d08d Mon Sep 17 00:00:00 2001 From: elleguehen Date: Fri, 10 Feb 2023 16:02:33 +0100 Subject: [PATCH] Tests now compile --- .idea/misc.xml | 2 +- test/BoardTests.java | 5 +---- test/InputCheckerTests.java | 42 +++++++++++++++++-------------------- test/WinCheckerTests.java | 12 ++++------- 4 files changed, 25 insertions(+), 36 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 0319d5d..220cd6a 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/test/BoardTests.java b/test/BoardTests.java index d7c6e76..d6fdcf8 100644 --- a/test/BoardTests.java +++ b/test/BoardTests.java @@ -36,12 +36,9 @@ public class BoardTests { @ParameterizedTest @MethodSource("getSetBoxTestData") - public void getSetBoxTests(Object[] args){ + public void getSetBoxTests(int col, int row, boolean shouldThrow){ Board b = new Board(); Player p = Player.X; - int col = (int) args[0]; - int row = (int) args[1]; - boolean shouldThrow = (boolean) args[2]; if (shouldThrow){ Assertions.assertThrows(IndexOutOfBoundsException.class, ()-> b.setBox(col, row, p)); diff --git a/test/InputCheckerTests.java b/test/InputCheckerTests.java index df90e9e..abaa9df 100644 --- a/test/InputCheckerTests.java +++ b/test/InputCheckerTests.java @@ -3,25 +3,26 @@ import model.InputChecker; import model.Player; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import java.util.Random; import java.util.stream.Stream; public class InputCheckerTests { - public static Stream validIndexTestData() { + public static Stream validIndexTestData() { int val = RandomSingleton.get.nextInt(); boolean isValid = val >= 1 && val <= 9; return Stream.of( - new Object[]{1, true}, - new Object[]{9, true}, - new Object[]{-3, false}, - new Object[]{15, false}, - new Object[]{val, isValid} + Arguments.of(1, true), + Arguments.of(1, true), + Arguments.of(-3, false), + Arguments.of(15, false), + Arguments.of(val, isValid) ); } - public static Stream boxOccupiedTestData() { + public static Stream boxOccupiedTestData() { Board b = randomBoard(); int index = RandomSingleton.get.nextInt(9) + 1; boolean isValid = true; @@ -32,12 +33,12 @@ public class InputCheckerTests { isValid = false; return Stream.of( - new Object[]{new Board(), 1, true}, - new Object[]{fullBoard(), 1, false}, - new Object[]{topLeftBoard(), 1, false}, - new Object[]{topLeftBoard(), 3, true}, - new Object[]{b, index, isValid} - ); + Arguments.of(new Board(), 1, true), + Arguments.of(fullBoard(), 1, false), + Arguments.of(topLeftBoard(), 1, false), + Arguments.of(topLeftBoard(), 3, true), + Arguments.of(b, index, isValid + )); } private static Board fullBoard(){ @@ -71,20 +72,15 @@ public class InputCheckerTests { @ParameterizedTest @MethodSource("validIndexTestData") - public void validIndexTest(Object[] args){ - Board b = new Board(); - int val = (int) args[0]; - boolean expected = (boolean) args[1]; - boolean actual = new InputChecker().isInputValid(b, val); - Assertions.assertEquals(expected, actual); + public void validIndexTest(int val,boolean expected){ + Board b = new Board(); + boolean actual = new InputChecker().isInputValid(b, val); + Assertions.assertEquals(expected, actual); } @ParameterizedTest @MethodSource("boxOccupiedTestData") - public void boxOccupiedTest(Object[] args){ - Board b = (Board) args[0]; - int input = (int) args[1]; - boolean expected = (boolean) args[2]; + public void boxOccupiedTest(Board b, int input, boolean expected){ boolean actual = new InputChecker().isInputValid(b, input); Assertions.assertEquals(expected, actual); } diff --git a/test/WinCheckerTests.java b/test/WinCheckerTests.java index e7242b2..2a9bb0c 100644 --- a/test/WinCheckerTests.java +++ b/test/WinCheckerTests.java @@ -16,11 +16,11 @@ public class WinCheckerTests { public static Stream isGameOverTestData() { Board randomBoard = new Board(); - Player currentBox; + Player currentBox, p; for (int i = 1; i <= 3; ++i) for (int j = 1; j <= 3; ++j) { int rand = rng.nextInt(3); - Player p = switch (rand){ + p = switch (rand) { case 1 -> Player.X; case 2 -> Player.O; default -> null; @@ -169,18 +169,14 @@ public class WinCheckerTests { @ParameterizedTest @MethodSource("isGameOverTestData") - public void isGameOverTest(Object[] args){ - Board b = (Board) args[0]; - boolean expected = (boolean) args[1]; + public void isGameOverTest(Board b, boolean expected){ boolean actual = new WinChecker().isGameOver(b); Assertions.assertEquals(expected, actual); } @ParameterizedTest @MethodSource("getWinnerTestNormalData") - public void getWinnerTestNormal(Object[] args){ - Board b = (Board) args[0]; - Player expected = (Player) args[1]; + public void getWinnerTestNormal(Board b, Player expected){ Player actual = new WinChecker().getWinner(b); Assertions.assertEquals(expected, actual); }