CS计算机代考程序代写 Java junit package comp1110.ass1;

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 LocationTask1Test {

private void testFromString(String input, Location expected) {
Location output = new Location(input);
assertEquals(expected.getX(), output.getX(), “Expected x coordinate of ” + expected.getX() +
” from string ‘” + input +
“‘, but got ” + output.getX() + “.”);
assertEquals(expected.getY(), output.getY(), “Expected y coordinate of ” + expected.getY() +
” from string ‘” + input +
“‘, but got ” + output.getY() + “.”);
}

private void testFromPosition(int position, Location expected) {
Location output = new Location(position);
assertEquals(expected.getX(), output.getX(), “Expected x coordinate of ” + expected.getX() +
” from position ‘” + position +
“‘, but got ” + output.getX() + “.”);
assertEquals(expected.getY(), output.getY(), “Expected y coordinate of ” + expected.getY() +
” from position ‘” + position +
“‘, but got ” + output.getY() + “.”);
}

@Test
public void testLocFromString() {
for (int x = 0; x < 10; x++) { for (int y = 0; y < 10; y++) { testFromString(x+""+y, new Location(x, y)); } } } @Test public void testLocFromPos() { for (int x = 0; x < 4; x++) { for (int y = 0; y < 4; y++) { testFromPosition(4*y+x, new Location(x, y)); } } } }