package comp1110.ass1;
import org.junit.jupiter.api.*;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.junit.jupiter.api.Assertions.assertEquals;
@Timeout(value = 1000, unit = MILLISECONDS)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class IsPlacementWellFormedTest {
private void test(String input, boolean expected) {
boolean output = WalkTheDog.isPlacementWellFormed(input);
assertEquals(expected, output, “Expected isPlacementWellFormed called on ‘” + input +
“‘ to be ” + expected +
“, but got ” + output + “.”);
}
@Test
public void testTwoCharPlacements() {
// Check valid placements
for (int x = 0; x < 4; x++) {
for (int y = 0; y < 4; y++) {
test(x+""+y, true);
}
}
// Check strings of wrong length
for (int x = 0; x < 4; x++) {
test(x+"", false);
}
test("", false);
// Check strings of wrong characters
for (int x = 0; x < 48; x++) {
char c = (char) x;
test(c+""+c, false);
test("0"+c, false);
test(c+"0", false);
}
for (int x = 52; x <= 255; x++) {
char c = (char) x;
test(c+""+c, false);
test(c+""+0, false);
}
}
@Test
public void testFourCharPlacements() {
// Check valid placements
for (int x = 0; x < 4; x++) {
for (int y = 0; y < 4; y++) {
for (int x2 = 0; x2 < 4; x2++) {
for (int y2 = 0; y2 < 4; y2++) {
test(x + "" + y + x2 + y2, true);
}
}
}
}
// Check strings of wrong length
for (int x = 0; x < 4; x++) {
String input = "x".repeat(3);
test(input, false);
input += x;
for (int i = 0; i < 10; i++) {
input += x;
test(input, false);
}
}
// Check strings of wrong characters
for (int x = 0; x < 48; x++) {
char c = (char) x;
test(c + "000", false);
test("0" + c + "00", false);
test("00" + c + "0", false);
test("000" + c, false);
}
}
}