Add oving 7
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package oving7.train;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class CargoCarTest {
|
||||
|
||||
private CargoCar cargoCar;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
cargoCar = new CargoCar(3000, 2000);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Check total weight")
|
||||
public void testWeight() {
|
||||
assertEquals(5000, cargoCar.getTotalWeight(), "Test total weight after initialization");
|
||||
|
||||
cargoCar.setCargoWeight(4000);
|
||||
assertEquals(7000, cargoCar.getTotalWeight(),
|
||||
"Test total weight after changing cargo weight");
|
||||
assertEquals(4000, cargoCar.getCargoWeight(),
|
||||
"Test cargo weight after changing the weight");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package oving7.train;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class PassengerCarTest {
|
||||
|
||||
private PassengerCar passengerCar;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
passengerCar = new PassengerCar(3000, 200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Check total weight")
|
||||
public void testWeight() {
|
||||
assertEquals(3000 + (200 * 80), passengerCar.getTotalWeight(),
|
||||
"Test total weight after initialization");
|
||||
|
||||
passengerCar.setPassengerCount(100);
|
||||
assertEquals(3000 + (100 * 80), passengerCar.getTotalWeight(),
|
||||
"Test total weight after changing the number of passengers");
|
||||
assertEquals(100, passengerCar.getPassengerCount(),
|
||||
"Test passenger count after changing the number");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package oving7.train;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class TrainCarTest {
|
||||
|
||||
private TrainCar trainCar;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
trainCar = new TrainCar(3000);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Dead weight equals total weight")
|
||||
public void testDeadWeight() {
|
||||
assertEquals(3000, trainCar.getTotalWeight(), "Test initialization of dead weight");
|
||||
|
||||
trainCar.setDeadWeight(5000);
|
||||
assertEquals(5000, trainCar.getTotalWeight(),
|
||||
"Test that total weight equals set dead weight");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package oving7.train;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class TrainTest {
|
||||
|
||||
private CargoCar cc1;
|
||||
private CargoCar cc2;
|
||||
private PassengerCar pc1;
|
||||
private PassengerCar pc2;
|
||||
private Train train;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
train = new Train();
|
||||
pc1 = new PassengerCar(2000, 200);
|
||||
pc2 = new PassengerCar(1500, 100);
|
||||
cc1 = new CargoCar(3000, 5000);
|
||||
cc2 = new CargoCar(2500, 7000);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Add cars to train")
|
||||
public void testAddCarToTrain() {
|
||||
train.addTrainCar(pc1);
|
||||
train.addTrainCar(pc2);
|
||||
train.addTrainCar(cc1);
|
||||
assertTrue(train.contains(pc1),
|
||||
"Test if the train contains passenger car 1 after it has been added");
|
||||
assertTrue(train.contains(pc2),
|
||||
"Test if the train contains passenger car 2 after it has been added");
|
||||
assertTrue(train.contains(cc1),
|
||||
"Test if the train contains cargo car 1 after it has been added");
|
||||
assertFalse(train.contains(cc2),
|
||||
"Test if the train contains cargo car 2 without it being added");
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
train.addTrainCar(null);
|
||||
}, "Test if an IllegalArgumentException is thrown when adding a null car");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Check total weight of the train")
|
||||
public void testTotalTrainWeight() {
|
||||
train.addTrainCar(pc1);
|
||||
train.addTrainCar(cc1);
|
||||
assertEquals(8000 + (2000 + (200 * 80)), train.getTotalWeight(),
|
||||
"Test the train's total weight after adding a passenger car and a cargo car");
|
||||
|
||||
train.addTrainCar(pc2);
|
||||
assertEquals(8000 + (2000 + (200 * 80)) + (1500 + (100 * 80)), train.getTotalWeight(),
|
||||
"Test the train's total weight after adding another passenger car");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Check passenger count on the train")
|
||||
public void testPassengerCount() {
|
||||
train.addTrainCar(pc1);
|
||||
train.addTrainCar(pc2);
|
||||
assertEquals(300, train.getPassengerCount(),
|
||||
"Test passenger count after adding passenger cars");
|
||||
|
||||
train.addTrainCar(cc1);
|
||||
assertEquals(300, train.getPassengerCount(),
|
||||
"Test passenger count after adding a cargo car");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Check cargo weight on the train")
|
||||
public void testCargoWeight() {
|
||||
train.addTrainCar(cc1);
|
||||
train.addTrainCar(cc2);
|
||||
assertEquals(12_000, train.getCargoWeight(), "Test cargo weight after adding cargo cars");
|
||||
|
||||
train.addTrainCar(pc1);
|
||||
assertEquals(12_000, train.getCargoWeight(),
|
||||
"Test cargo weight after adding a passenger car");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user