uebung05 aufgabenstellung
This commit is contained in:
parent
e7f7a20ea6
commit
cd913d2703
43
uebung05/src/logistics/Demo.java
Normal file
43
uebung05/src/logistics/Demo.java
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
package logistics;
|
||||||
|
|
||||||
|
import logistics.material.BulletBelts;
|
||||||
|
import logistics.material.Grease;
|
||||||
|
import logistics.material.LiterDiesel;
|
||||||
|
import logistics.material.MetGallonsKerosene;
|
||||||
|
import logistics.material.Oil;
|
||||||
|
import logistics.material.RocketPods;
|
||||||
|
import logistics.material.ShellBatches;
|
||||||
|
|
||||||
|
public class Demo {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
final Manager manager = new Manager();
|
||||||
|
manager.addVehicle(new Tank("Leo1"));
|
||||||
|
manager.addVehicle(new Tank("Leo2"));
|
||||||
|
manager.addVehicle(new Helicopter("Tiger1"));
|
||||||
|
manager.addVehicle(new Helicopter("Tiger2"));
|
||||||
|
System.out.println();
|
||||||
|
manager.showOverallNeed();
|
||||||
|
System.out.println();
|
||||||
|
manager.fillUpVehicles();
|
||||||
|
manager.showOverallNeed();
|
||||||
|
System.out.println();
|
||||||
|
manager.logTick(1);
|
||||||
|
System.out.println();
|
||||||
|
manager.showNeed(LiterDiesel.INSTANCE);
|
||||||
|
System.out.println();
|
||||||
|
manager.showNeed(MetGallonsKerosene.INSTANCE);
|
||||||
|
System.out.println();
|
||||||
|
manager.showNeed(BulletBelts.INSTANCE);
|
||||||
|
System.out.println();
|
||||||
|
manager.showNeed(RocketPods.INSTANCE);
|
||||||
|
System.out.println();
|
||||||
|
manager.showNeed(ShellBatches.INSTANCE);
|
||||||
|
System.out.println();
|
||||||
|
manager.showNeed(Oil.INSTANCE);
|
||||||
|
System.out.println();
|
||||||
|
manager.showNeed(Grease.INSTANCE);
|
||||||
|
System.out.println();
|
||||||
|
manager.showOverallNeed();
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
}
|
67
uebung05/test/logistics/ManagerTest.java
Normal file
67
uebung05/test/logistics/ManagerTest.java
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
package logistics;
|
||||||
|
|
||||||
|
import logistics.material.BulletBelts;
|
||||||
|
import logistics.material.Grease;
|
||||||
|
import logistics.material.LiterDiesel;
|
||||||
|
import logistics.material.MetGallonsKerosene;
|
||||||
|
import logistics.material.Oil;
|
||||||
|
import logistics.material.RocketPods;
|
||||||
|
import logistics.material.ShellBatches;
|
||||||
|
import logistics.quantities.NeedCollector;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
public class ManagerTest {
|
||||||
|
private static final float EPS = 1e-5f;
|
||||||
|
private Manager manager;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
manager = new Manager();
|
||||||
|
manager.addVehicle(new Tank("Leo1"));
|
||||||
|
manager.addVehicle(new Tank("Leo2"));
|
||||||
|
manager.addVehicle(new Helicopter("Tiger1"));
|
||||||
|
manager.addVehicle(new Helicopter("Tiger2"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInitialNeed() {
|
||||||
|
final NeedCollector collector = manager.collectNeeds();
|
||||||
|
assertEquals(4, collector.getNeed(RocketPods.INSTANCE));
|
||||||
|
assertEquals(12, collector.getNeed(Oil.INSTANCE));
|
||||||
|
assertEquals(24, collector.getNeed(BulletBelts.INSTANCE));
|
||||||
|
assertEquals(20, collector.getNeed(ShellBatches.INSTANCE));
|
||||||
|
assertEquals(12, collector.getNeed(Grease.INSTANCE));
|
||||||
|
assertEquals(1000f, collector.getNeed(MetGallonsKerosene.INSTANCE), EPS);
|
||||||
|
assertEquals(2400f, collector.getNeed(LiterDiesel.INSTANCE), EPS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNeedAfterFillUp() {
|
||||||
|
manager.fillUpVehicles();
|
||||||
|
final NeedCollector collector = manager.collectNeeds();
|
||||||
|
assertEquals(0, collector.getNeed(RocketPods.INSTANCE));
|
||||||
|
assertEquals(0, collector.getNeed(Oil.INSTANCE));
|
||||||
|
assertEquals(0, collector.getNeed(BulletBelts.INSTANCE));
|
||||||
|
assertEquals(0, collector.getNeed(ShellBatches.INSTANCE));
|
||||||
|
assertEquals(0, collector.getNeed(Grease.INSTANCE));
|
||||||
|
assertEquals(0f, collector.getNeed(MetGallonsKerosene.INSTANCE), EPS);
|
||||||
|
assertEquals(0f, collector.getNeed(LiterDiesel.INSTANCE), EPS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNeedAfterLogTick() {
|
||||||
|
manager.fillUpVehicles();
|
||||||
|
manager.logTick(1);
|
||||||
|
final NeedCollector collector = manager.collectNeeds();
|
||||||
|
assertEquals(2, collector.getNeed(RocketPods.INSTANCE));
|
||||||
|
assertEquals(4, collector.getNeed(Oil.INSTANCE));
|
||||||
|
assertEquals(6, collector.getNeed(BulletBelts.INSTANCE));
|
||||||
|
assertEquals(4, collector.getNeed(ShellBatches.INSTANCE));
|
||||||
|
assertEquals(4, collector.getNeed(Grease.INSTANCE));
|
||||||
|
assertEquals(400f, collector.getNeed(MetGallonsKerosene.INSTANCE), EPS);
|
||||||
|
assertEquals(360f, collector.getNeed(LiterDiesel.INSTANCE), EPS);
|
||||||
|
}
|
||||||
|
}
|
80
uebung05/test/logistics/storage/IntStorageTest.java
Normal file
80
uebung05/test/logistics/storage/IntStorageTest.java
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
package logistics.storage;
|
||||||
|
|
||||||
|
import logistics.material.Oil;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
public class IntStorageTest {
|
||||||
|
private static final int MAX = 3;
|
||||||
|
|
||||||
|
private IntStorage intStorage;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
intStorage = new IntStorage(0, Oil.INSTANCE, MAX);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEmptyStorage() {
|
||||||
|
assertEquals(0, intStorage.getStored());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetStorage() {
|
||||||
|
intStorage.fill(1);
|
||||||
|
assertEquals(1, intStorage.getStored());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetMax() {
|
||||||
|
assertEquals(MAX, intStorage.getMax());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFillUp() {
|
||||||
|
intStorage.fillUp();
|
||||||
|
assertEquals(MAX, intStorage.getStored());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpperBound() {
|
||||||
|
intStorage.fill(MAX + 1);
|
||||||
|
assertEquals(MAX, intStorage.getStored());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConsume() {
|
||||||
|
intStorage.fillUp();
|
||||||
|
assertEquals(MAX, intStorage.getStored());
|
||||||
|
assertEquals(MAX, intStorage.consume(MAX));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLowerBound() {
|
||||||
|
intStorage.consume(1);
|
||||||
|
assertEquals(0, intStorage.getStored());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void testIllegalFill() {
|
||||||
|
intStorage.fill(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void testIllegalConsume() {
|
||||||
|
intStorage.consume(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void testIllegalLowerBoundConstructor() {
|
||||||
|
new IntStorage(-1, Oil.INSTANCE, MAX);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpperBoundConstructor() {
|
||||||
|
final IntStorage storage = new IntStorage(MAX + 1, Oil.INSTANCE, MAX);
|
||||||
|
assertEquals(MAX, storage.getStored());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user