-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMoonRoverTest.java
More file actions
70 lines (61 loc) · 1.63 KB
/
MoonRoverTest.java
File metadata and controls
70 lines (61 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import static org.junit.Assert.*;
import java.util.Scanner;
import org.junit.Test;
public class MoonRoverTest {
//Test Input One
@Test
public void testMoonRover1() {
int topX, topY;
String initialiseMoon = "5 5";
topX = initialiseMoon.charAt(0)-'0';
topY = initialiseMoon.charAt(2)-'0';
Plateau moon = new Plateau(topX,topY);
int x,y;
char o;
String initialise = "1 2 N";
x = initialise.charAt(0)-'0';
y = initialise.charAt(2)-'0';
o = initialise.charAt(4);
MoonRover rover1 = new MoonRover(x, y, o);
String explore = "LMLMLMLMM";
for(int i=0; i<explore.length(); i++){
if(explore.charAt(i)=='L')
rover1.spinLeft();
else if(explore.charAt(i)=='R')
rover1.spinRight();
else if(explore.charAt(i)=='M')
rover1.move();
else
System.out.println("Error in explore command\n");
}
assertEquals("1 3 N", rover1.whereAreYou());
}
//Test Input Two
@Test
public void testMoonRover2() {
int topX, topY;
String initialiseMoon = "5 5";
topX = initialiseMoon.charAt(0)-'0';
topY = initialiseMoon.charAt(2)-'0';
Plateau moon = new Plateau(topX,topY);
int x,y;
char o;
String initialise = "3 3 E";
x = initialise.charAt(0)-'0';
y = initialise.charAt(2)-'0';
o = initialise.charAt(4);
MoonRover rover2 = new MoonRover(x, y, o);
String explore = "MMRMMRMRRM";
for(int i=0; i<explore.length(); i++){
if(explore.charAt(i)=='L')
rover2.spinLeft();
else if(explore.charAt(i)=='R')
rover2.spinRight();
else if(explore.charAt(i)=='M')
rover2.move();
else
System.out.println("Error in explore command\n");
}
assertEquals("5 1 E", rover2.whereAreYou());
}
}