Skip to content
Snippets Groups Projects
Commit 2dcf32c1 authored by hkaur28's avatar hkaur28
Browse files

Added JUnit Tests

parent f08d27a5
No related branches found
No related tags found
No related merge requests found
<?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>
.project 0 → 100644
<?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>
...@@ -112,7 +112,7 @@ public class DotsAndBoxesGrid { ...@@ -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. // 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). // 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. */ /** Tries to claim a box for a player. If the box is complete, sets the ownership and returns true. */
......
...@@ -4,28 +4,37 @@ import org.junit.jupiter.api.*; ...@@ -4,28 +4,37 @@ import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assumptions.*; import static org.junit.jupiter.api.Assumptions.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class DotsAndBoxesGridTest { public class DotsAndBoxesGridTest {
/*
* Because Test classes are classes, they can have fields, and can have static fields. // FIXME: You need to write tests for the two known bugs in the code.
* This field is a logger. Loggers are like a more advanced println, for writing messages out to the console or a log file. private DotsAndBoxesGrid grid;
*/
private static final Logger logger = LogManager.getLogger(DotsAndBoxesGridTest.class); @BeforeEach
public void setUp() {
/* // Create a new DotsAndBoxesGrid instance before each test
* Tests are functions that have an @Test annotation before them. grid = new DotsAndBoxesGrid(4, 3, 2);
* 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.
* @Test
* This is a dummy test just to show that the test suite itself runs public void testBoxComplete() {
*/ // Test if the boxComplete method works correctly
assertTrue(grid.boxComplete(3,3));
}
@Test @Test
public void testTestSuiteRuns() { public void whenExceptionThrown_thenAssertionSucceeds() {
logger.info("Dummy test to show the test suite runs"); Exception exception = assertThrows(Exception.class, () -> {
assertTrue(true); 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.
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment