diff --git a/.classpath b/.classpath new file mode 100644 index 0000000000000000000000000000000000000000..17fe15da9460cd8e45372354269950bfc3d3b03c --- /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 0000000000000000000000000000000000000000..23d5387b4e30db72fe9013f487ffa6393e09866a --- /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 a64642b1797414bb041f02d82b739718fddbaa6f..9935fdd77cf534e47c14aa12e8df6e5c4bdee3a0 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 a9e7c5b6639e8a2a8728809d9b17c8d155baf9b6..d4297bfd65decd4182fc1fcad043bd7120786f70 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 1946beda974d180686c65c0259a7b881e9a4eb5a..6d5005ab192e25c1e968ebffe91bf3a74f280efe 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. + }