forked from oopd-gu-chalmers/lab1
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCarstest.java
114 lines (102 loc) · 3.23 KB
/
Carstest.java
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.*;
public class Carstest {
@Test
public void testMove() {
Volvo240 v = new Volvo240();
v.startEngine();
assertEquals(0.1, v.getCurrentSpeed());
}
@Test
public void testRight() {
Saab95 s = new Saab95();
s.startEngine();
s.turnRight();
assertEquals("East", s.getDirection());
}
@Test
public void testRTBcorrect() {
ScaniaTruck s = new ScaniaTruck();
s.raiseTruckBed(60);
assertEquals(60, s.CargoTruck.getAngle());
}
@Test
public void testRTBerror() {
ScaniaTruck s = new ScaniaTruck();
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> s.raiseTruckBed(90));
assertEquals("Invalid integer. Must be within the limits 0-70", exception.getMessage()); }
@Test
public void testRTBmove() {
ScaniaTruck s = new ScaniaTruck();
s.startEngine();
IllegalStateException exception = assertThrows(IllegalStateException.class,
() -> s.raiseTruckBed(60));
assertEquals("Truck must be stationary to raise or lower the truckbed", exception.getMessage());
}
@Test
public void testRTBAlreadyRaised() {
ScaniaTruck s = new ScaniaTruck();
s.raiseTruckBed((60));
s.raiseTruckBed(20);
assertEquals(70, s.CargoTruck.getAngle());
}
@Test
public void testLoadCarmoving() {
CarTransport b = new CarTransport(6);
Saab95 s = new Saab95();
b.startEngine();
IllegalStateException exception = assertThrows(IllegalStateException.class,
() -> b.loadCar(s));
assertEquals("Truck must be both stationary and with the truckbed lowered to load cars.", exception.getMessage());
}
@Test
public void testLoadBiltransport() {
CarTransport b = new CarTransport(6);
CarTransport s = new CarTransport(4);
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> b.loadCar(s));
assertEquals("Cannot load vehicle transports", exception.getMessage());
}
@Test
public void testLoadCar() {
CarTransport b = new CarTransport(6);
Volvo240 v = new Volvo240();
Saab95 s = new Saab95();
b.loadCar(s);
b.loadCar(v);
assertEquals(v, b.cargo.get(1));
}
@Test
public void testMoveCargo() {
CarTransport b = new CarTransport(6);Volvo240 v = new Volvo240();
b.loadCar(v);
b.startEngine();
b.turnRight();
b.move();
b.move();
b.move();
b.move();
b.move();
b.move();
b.move();
assertEquals(0.7, v.getX());
}
@Test
public void testUnLoad() {
CarTransport b = new CarTransport(6);
Volvo240 v = new Volvo240();
Saab95 s = new Saab95();
b.loadCar(v);
b.loadCar(s);
b.raiseTruckBed();
b.startEngine();
b.move();
b.move();
b.stopEngine();
b.lowerTruckBed();
b.unLoadCar();
assertEquals(5.2, s.getY());
assertEquals(v, b.cargo.get(0));
}
}