public class CarTest {
/**
* Test method for {@link weeklytask4.Car#Car(double, double)}.
*/
@Test
public final void testCar() {
Car c = new Car(60,10);
assertEquals("Petrol in constructor",0.0,c.getPetrol(),0.01);
assertEquals("Capacity in constructor",60.0,c.getCapacity(),0.01);
assertEquals("Efficiency in constructor",10.0,c.getEfficiency(),0.01);
}
/**
* Test method for {@link weeklytask4.Car#addPetrol(double)}.
*/
@Test
public final void testAddPetrol() {
Car c = new Car(30,10);
c.addPetrol(20);
assertEquals("After adding 20l of petrol", 20.,c.getPetrol(),0.01);
c.addPetrol(20);
assertEquals("After adding 20l more of petrol", 30.,c.getPetrol(),0.01);
}
/**
* Test method for {@link weeklytask4.Car#drive(double)}.
*/
@Test
public final void testDrive() {
Car c = new Car(30,10);
c.setPetrol(20);
c.drive(100);
assertEquals("After 100 km", 10.,c.getPetrol(),0.01);
c.drive(10000);
assertEquals("After 10000 km", 0.,c.getPetrol(),0.01);
}
/**
* Test method for {@link weeklytask4.Car#setEfficiency(double)}.
*/
@Test
public final void testSetEfficiency()
{
Car c = new Car(30,10);
c.setEfficiency(5);
assertEquals("Changing fuel efficiency",5.,c.getEfficiency(),0.01);
}
/**
* Test method for {@link weeklytask4.Car#setPetrol(double)}.
*/
@Test
public final void testSetPetrol()
{
Car c = new Car(30,10);
c.setPetrol(5);
assertEquals("Changing fuel petrol",5.,c.getPetrol(),0.01);
c.setPetrol(29);
assertEquals("Changing fuel petrol",29.,c.getPetrol(),0.01);
c.setPetrol(35);
assertEquals("Changing fuel petrol",30.,c.getPetrol(),0.01);
}
/**
* Test method for {@link weeklytask4.Car#setCapacity(double)}.
*/
@Test
public final void testSetCapacity()
{
Car c = new Car(30,10);
c.setPetrol(25);
c.setCapacity(35);
assertEquals("Changing fuel capacity",25.,c.getPetrol(),0.01);
assertEquals("Changing fuel capacity",35.,c.getCapacity(),0.01);
c.setCapacity(20);
assertEquals("Changing fuel capacity",20.,c.getPetrol(),0.01);
assertEquals("Changing fuel capacity",20.,c.getCapacity(),0.01);
}
}