From 902811a857a951897480d16344d7c36d659e6c4a Mon Sep 17 00:00:00 2001
From: Niraj Rana Bhat <nranabha@myune.edu.au>
Date: Wed, 2 Aug 2023 13:43:12 +0000
Subject: [PATCH] build.gradle updated to support gradle 8 and unit tests added
 for tesing incomplete boxes, complete boxes and detecting redrawn lines

---
 build.gradle                                  |  2 +-
 .../dotsandboxes/DotsAndBoxesGridTest.java    | 50 +++++++++++++++----
 2 files changed, 42 insertions(+), 10 deletions(-)

diff --git a/build.gradle b/build.gradle
index a64642b..e067df3 100644
--- a/build.gradle
+++ b/build.gradle
@@ -39,7 +39,7 @@ task fatJar(type: Jar) {
     manifest {
         attributes 'Main-Class': 'dotsandboxes.Main'
     }
-    baseName = 'executable-jar'
+    archiveBaseName = 'executable-jar'
     duplicatesStrategy = DuplicatesStrategy.EXCLUDE
     from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
     with jar
diff --git a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
index 1946bed..f93614f 100644
--- a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
+++ b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
@@ -4,6 +4,8 @@ import org.junit.jupiter.api.*;
 import static org.junit.jupiter.api.Assertions.*;
 import static org.junit.jupiter.api.Assumptions.*;
 
+import java.beans.Transient;
+
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
@@ -15,17 +17,47 @@ public class DotsAndBoxesGridTest {
     private static final Logger logger = LogManager.getLogger(DotsAndBoxesGridTest.class);
 
     /*
-     * Tests are functions that have an @Test annotation before them.
-     * The typical format of a test is that it contains some code that does something, and then one
-     * or more assertions to check that a condition holds.
-     *
-     * This is a dummy test just to show that the test suite itself runs
+     * Code to test that boxComplete returns true for boxes that are complete
+     */
+    @Test
+    public void boxCompleteDetectsCompletedBoxes(){
+        DotsAndBoxesGrid tGrid = new DotsAndBoxesGrid(5, 5, 2);
+        tGrid.drawHorizontal(0, 0, 0);
+        tGrid.drawHorizontal(0, 1, 0);
+        tGrid.drawVertical(0, 0, 0);
+        tGrid.drawVertical(1, 0, 0);
+        assertTrue(tGrid.boxComplete(0, 0));
+    }
+    
+    /*
+     * Code to test that boxComplete returns false for boxes that are not complete
      */
     @Test
-    public void testTestSuiteRuns() {
-        logger.info("Dummy test to show the test suite runs");
-        assertTrue(true);
+    public void boxCompleteDetectsIncompleteBoxes(){
+        DotsAndBoxesGrid tBoxesGrid = new DotsAndBoxesGrid(5,5 , 2);
+        assertFalse(tBoxesGrid.boxComplete(0, 0));
+        tBoxesGrid.drawHorizontal(0, 0, 0);
+        assertFalse(tBoxesGrid.boxComplete(0, 0));
+        tBoxesGrid.drawHorizontal(0, 1, 0);
+        assertFalse(tBoxesGrid.boxComplete(0, 0));
+        tBoxesGrid.drawVertical(0, 0, 0);
+        assertFalse(tBoxesGrid.boxComplete(0, 0));
+        
     }
+    /*
+     * Code to test if a line is drawn on top of an existing line is detected
+     */
+    @Test
+    public void drawMethodsDetectRedrawnLines(){
+        DotsAndBoxesGrid tGrid = new DotsAndBoxesGrid(5, 5, 2);
+        tGrid.drawHorizontal(0, 0, 0);
+        assertThrows(IllegalStateException.class, () -> {
+            tGrid.drawHorizontal(0, 0, 0);
+        });
 
-    // FIXME: You need to write tests for the two known bugs in the code.
+        tGrid.drawVertical(0, 0, 0);
+        assertThrows(IllegalStateException.class, () -> {
+            tGrid.drawVertical(0, 0, 0);
+        });
+    }
 }
-- 
GitLab