From 2dcf32c17ff86b1bee38294a82fbbeeef73675f0 Mon Sep 17 00:00:00 2001
From: hkaur28 <hkaur28@myune.edu.au>
Date: Sun, 30 Jul 2023 14:24:40 +0500
Subject: [PATCH] Added JUnit Tests

---
 .classpath                                    | 22 +++++++++
 .project                                      | 17 +++++++
 build.gradle                                  |  2 +-
 .../java/dotsandboxes/DotsAndBoxesGrid.java   |  2 +-
 .../dotsandboxes/DotsAndBoxesGridTest.java    | 47 +++++++++++--------
 5 files changed, 69 insertions(+), 21 deletions(-)
 create mode 100644 .classpath
 create mode 100644 .project

diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..17fe15d
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src/main/java"/>
+	<classpathentry kind="src" path="src/test/java"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
+		<attributes>
+			<attribute name="module" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="lib" path="gradle/wrapper/gradle-wrapper.jar"/>
+	<classpathentry kind="lib" path="/home/bot/Downloads/apache-log4j-2.20.0-bin/log4j-core-2.20.0.jar"/>
+	<classpathentry kind="lib" path="/home/bot/Downloads/apache-log4j-2.20.0-bin/log4j-api-2.20.0.jar"/>
+	<classpathentry kind="lib" path="/home/bot/Desktop/jar_files/junit-jupiter-api-5.7.0.jar"/>
+	<classpathentry kind="lib" path="/home/bot/Desktop/jar_files/junit-jupiter-engine-5.7.0.jar"/>
+	<classpathentry kind="lib" path="/home/bot/Desktop/jar_files/junit-jupiter-params-5.7.0.jar"/>
+	<classpathentry kind="lib" path="/home/bot/Desktop/jar_files/opentest4j-1.2.0.jar"/>
+	<classpathentry kind="lib" path="/home/bot/Desktop/jar_files/junit-platform-engine-1.7.0.jar"/>
+	<classpathentry kind="lib" path="/home/bot/Desktop/jar_files/junit-jupiter-5.7.0.jar"/>
+	<classpathentry kind="lib" path="/home/bot/Desktop/jar_files/apiguardian-api-1.1.0.jar"/>
+	<classpathentry kind="lib" path="/home/bot/Desktop/jar_files/junit-platform-commons-1.7.0.jar"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/.project b/.project
new file mode 100644
index 0000000..23d5387
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>dotsandboxes</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>
diff --git a/build.gradle b/build.gradle
index a64642b..9935fdd 100644
--- a/build.gradle
+++ b/build.gradle
@@ -43,4 +43,4 @@ task fatJar(type: Jar) {
     duplicatesStrategy = DuplicatesStrategy.EXCLUDE
     from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
     with jar
-}
\ No newline at end of file
+}
diff --git a/src/main/java/dotsandboxes/DotsAndBoxesGrid.java b/src/main/java/dotsandboxes/DotsAndBoxesGrid.java
index a9e7c5b..d4297bf 100644
--- a/src/main/java/dotsandboxes/DotsAndBoxesGrid.java
+++ b/src/main/java/dotsandboxes/DotsAndBoxesGrid.java
@@ -112,7 +112,7 @@ 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 false;
     }
 
     /** Tries to claim a box for a player. If the box is complete, sets the ownership and returns true. */
diff --git a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
index 1946bed..6d5005a 100644
--- a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
+++ b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
@@ -4,28 +4,37 @@ import org.junit.jupiter.api.*;
 import static org.junit.jupiter.api.Assertions.*;
 import static org.junit.jupiter.api.Assumptions.*;
 
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
+
 
 public class DotsAndBoxesGridTest {
-    /*
-     * Because Test classes are classes, they can have fields, and can have static fields.
-     * This field is a logger. Loggers are like a more advanced println, for writing messages out to the console or a log file.
-     */
-    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
-     */
+
+    // FIXME: You need to write tests for the two known bugs in the code.
+    private DotsAndBoxesGrid grid;
+
+    @BeforeEach
+    public void setUp() {
+        // Create a new DotsAndBoxesGrid instance before each test
+        grid = new DotsAndBoxesGrid(4, 3, 2);
+    }
+
+    @Test
+    public void testBoxComplete() {
+        // Test if the boxComplete method works correctly
+
+        assertTrue(grid.boxComplete(3,3));
+    }
+
     @Test
-    public void testTestSuiteRuns() {
-        logger.info("Dummy test to show the test suite runs");
-        assertTrue(true);
+   public void whenExceptionThrown_thenAssertionSucceeds() {
+        Exception exception = assertThrows(Exception.class, () -> {
+            grid.drawHorizontal(3,3,1);
+        });
+
+        String expectedMessage = "Already Drawn";
+        String actualMessage = exception.getMessage();
+
+        assertTrue(actualMessage.contains(expectedMessage));
     }
 
-    // FIXME: You need to write tests for the two known bugs in the code.
+
 }
-- 
GitLab