Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • 1-bugfixing-assignment-error
  • main
  • testsfail
3 results

Target

Select target project
  • uekeh/assessment-2
1 result
Select Git revision
  • 1-bugfixing-assignment-error
  • main
  • testsfail
3 results
Show changes
Commits on Source (2)
......@@ -106,13 +106,13 @@ public class DotsAndBoxesGrid {
* @return true if all four sides have been drawn.
*/
public boolean boxComplete(int x, int y) {
if (x >= width - 1 || x < 0 || y >= height - 1 || y < 0) {
return false;
}
if (x >= width + 1 || x < 0 || y >= height + 1 || y < 0) {
return true;
} else {
// 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. */
......@@ -132,10 +132,10 @@ public class DotsAndBoxesGrid {
* @return true if it completes a box
*/
public boolean drawHorizontal(int x, int y, int player) {
if (x >= width - 1 || x < 0) {
if (x >= width + 1 || x > 0) {
throw new IndexOutOfBoundsException(String.format("x was %d, which is out of range. Range is 0 to %d", x, width - 1));
}
if (y >= height || y < 0) {
if (y >= height || y > 0) {
throw new IndexOutOfBoundsException(String.format("y was %d, which is out of range. Range is 0 to %d", y, height));
}
......
......@@ -27,5 +27,34 @@ public class DotsAndBoxesGridTest {
assertTrue(true);
}
@Test
public void testBoxComplete() {
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(15,8,2);
grid.drawVertical(1,4,0);
grid.drawHorizontal(1,3,0);
grid.drawHorizontal(2,3,0);
boolean completesBox = grid.drawVertical(2,4,0);
assertEquals(true, completesBox);
}
@Test
public void testBoxComplete() {
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(15,8,2);
grid.drawVertical(1,4,0);
grid.drawHorizontal(1,3,0);
boolean completesBox = grid.drawVertical(2,4, 0);
assertEquals(true, completesBox);
}
@Test
public void testDrawHorizontal() {
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(15,8,2);
grid.drawHorizontal(1,3,0);
assertThrows(IndexOutOfBoundsException.class, () -> {
grid.drawHorizontal(1,3,0); //"y was %d, which is out of range. Range is 0 to %d", y, height
});
}
// FIXME: You need to write tests for the two known bugs in the code.
}