From 378c7bf3e69d648514f3d97da3d23a434710282b Mon Sep 17 00:00:00 2001
From: Juan Ludevid <jludevid@myune.edu.au>
Date: Fri, 29 Jul 2022 20:15:12 +1000
Subject: [PATCH] bugs have been fixed

---
 src/main/java/dotsandboxes/DotsAndBoxesGrid.java     | 11 ++++++++---
 src/test/java/dotsandboxes/DotsAndBoxesGridTest.java | 11 +++++------
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/src/main/java/dotsandboxes/DotsAndBoxesGrid.java b/src/main/java/dotsandboxes/DotsAndBoxesGrid.java
index a9e7c5b..f4f9b99 100644
--- a/src/main/java/dotsandboxes/DotsAndBoxesGrid.java
+++ b/src/main/java/dotsandboxes/DotsAndBoxesGrid.java
@@ -112,7 +112,8 @@ public class DotsAndBoxesGrid {
 
         // A box is complete if the north and south horizontals and the east and west verticals have all been drawn.
         // FIXME: You'll need to fix this code (after writing a test first).
-        return true;
+        return (this.horizontals[x][y] && this.horizontals[x][y+1] && this.verticals[x][y] && this.verticals[x+1][y]);
+       
     }
 
     /** Tries to claim a box for a player. If the box is complete, sets the ownership and returns true. */
@@ -140,7 +141,9 @@ public class DotsAndBoxesGrid {
         }
 
         // FIXME: You need to throw an exception if the line was already drawn.
-
+        if (this.horizontals[x][y]) {
+            throw new IllegalStateException(String.format("horizontal line at [%d][%d] has been drawn already", x, y));
+        }
         this.horizontals[x][y] = true;
 
         // Try to claim the north or south boxes
@@ -171,7 +174,9 @@ public class DotsAndBoxesGrid {
         }
 
         // You need to throw an exception if the line was already drawn.
-
+        if (this.verticals[x][y]) {
+            throw new IllegalStateException(String.format("Vertical line at [%d][%d] has been drawn already", x, y));
+        }
         this.verticals[x][y] = true;
         // Try to claim the north or south boxes
         boolean claimE = claimBox(x, y, player);
diff --git a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
index fecf5e8..a3f8859 100644
--- a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
+++ b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
@@ -45,19 +45,18 @@ public class DotsAndBoxesGridTest {
        case2.drawHorizontal(0, 0, 0);
        case2.drawVertical(0, 0, 1);
        case2.drawHorizontal(0, 1, 0);
-       case2.drawVertical(0, 0, 1);
        assertFalse(case2.boxComplete(0, 0));
    }
    @Test
    public void drawMethodsDetectRedrawnLines() {
      // code to test that drawHorizontal throws an exception if the line was already drawn goes here
      DotsAndBoxesGrid case3 = new DotsAndBoxesGrid(5, 5, 2);
-     case3.drawHorizontal(0, 0, 1);
      case3.drawVertical(0, 0, 1);
-     assertAll(
-       ()->assertThrows(IllegalStateException.class, ()-> case3.drawHorizontal(0, 0, 1), "No horizonal line has been drawn"),
-       ()->assertThrows(IllegalStateException.class, ()-> case3.drawVertical(0, 0, 1), "No vertical line has been drawn")
-       );
+      case3.drawHorizontal(0, 0, 1);
+      assertAll(
+        ()->assertThrows(IllegalStateException.class, ()-> case3.drawVertical(0, 0, 1), "No vertical line has been drawn"),
+        ()->assertThrows(IllegalStateException.class, ()-> case3.drawHorizontal(0, 0, 1), "No horizonal line has been drawn")
+        );
      
      
    }
-- 
GitLab