From 3ae346ba8c1393bbcdf8895aefb15107f98c4e60 Mon Sep 17 00:00:00 2001 From: Ashley Travaini <atravain@myune.edu.au> Date: Sat, 10 Jul 2021 17:10:34 +1000 Subject: [PATCH] Added unit tests to perform checks on known bugs, These tests currently fail --- .../dotsandboxes/DotsAndBoxesGridTest.java | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java index 1946bed..e3fed03 100644 --- a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java +++ b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java @@ -27,5 +27,40 @@ public class DotsAndBoxesGridTest { assertTrue(true); } - // FIXME: You need to write tests for the two known bugs in the code. + // A test to check that the boxComplete function performs correctly + @Test + public void testBoxComplete() { + + // Creates a grid with a box starting at (0,0) + DotsAndBoxesGrid grid = new DotsAndBoxesGrid(15, 8, 2); + grid.drawHorizontal(0, 0, 1); + grid.drawHorizontal(0, 1, 1); + grid.drawVertical(0, 0, 1); + grid.drawVertical(1, 0, 1); + + logger.info("This test checks that the boxComplete function works correctly"); + + assertAll( + "A complete box must return true, an incomplete must return false.", + () -> assertTrue(grid.boxComplete(0,0)), + // Returns false as the x,y co-ordinates passed are not the left and top co-ordinates of the box + () -> assertFalse(grid.boxComplete(1,1)) + ); + } + + // A test to check that the program throws an exception when a player attempts to draw a line in a position that + // has already been played + @Test + public void testDrawLine() { + + // Creates a grid and draws a horizontal and vertical line at (0,0) + DotsAndBoxesGrid grid = new DotsAndBoxesGrid(15, 8, 2); + grid.drawHorizontal(0, 0, 1); + grid.drawVertical(0, 0, 1); + + logger.info("This test checks that an exception is thrown when a player tries to draw a line that is already drawn"); + + assertThrows(IllegalStateException.class, () -> grid.drawHorizontal(0, 0, 1), "The horizontal line was drawn more than once"); + assertThrows(IllegalStateException.class, () -> grid.drawVertical(0, 0, 1), "The vertical line was drawn more than once"); + } } -- GitLab