add test helper

master
clemens 2022-07-05 15:15:58 +02:00
parent 261ab9c4f4
commit 6bb38066d6
1 changed files with 93 additions and 83 deletions

View File

@ -1,11 +1,10 @@
package satisfactory.items; package satisfactory.items;
import org.jgrapht.Graph;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import satisfactory.Database; import satisfactory.Database;
import satisfactory.Utils;
import java.util.HashMap; import java.util.Arrays;
import java.util.Collection;
import java.util.Map; import java.util.Map;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
@ -14,36 +13,28 @@ class ItemTest {
@Test @Test
void productionScrews() { void productionScrews() {
/*Map<Item, Double> production = Database.Screw.production(100); Collection<Ref> ref = Arrays.asList(
assertEquals(100, production.get(Database.Screw), "Screws (output)"); new Ref(Database.Screw, 100.0),
assertEquals(25, production.get(Database.IronRod), "IronRod"); new Ref(Database.IronRod, 25.0),
assertEquals(25, production.get(Database.IronIngot), "IronIngot"); new Ref(Database.IronIngot, 25.0),
assertEquals(25, production.get(Database.IronOre), "IronOre");*/ new Ref(Database.IronOre, 25.0)
fail(); );
} SumResult sum = SumResult.sum(new Production(Database.Screw, 100.0));
compareProductions(sum, ref);
@Test
void productionScrews2() {
/*Map<Item, Double> production = Database.Screw.getRecipe().sum(Database.Screw, 100);
assertEquals(100, production.get(Database.Screw), "Screws (output)");
assertEquals(25, production.get(Database.IronRod), "IronRod");
assertEquals(25, production.get(Database.IronIngot), "IronIngot");
assertEquals(25, production.get(Database.IronOre), "IronOre");
*/
fail("TODO: migrate");
} }
@Test @Test
void productionReinforcedIronPlates() { void productionReinforcedIronPlates() {
/*Map<Item, Double> production = Database.ReinforcedIronPlate.production(100); Collection<Ref> ref = Arrays.asList(
assertEquals(100, production.get(Database.ReinforcedIronPlate), "output"); new Ref(Database.ReinforcedIronPlate, 100.0, "output"),
assertEquals(1200, production.get(Database.Screw), "Screws"); new Ref(Database.Screw, 1200.0),
assertEquals(300, production.get(Database.IronRod), "IronRod"); new Ref(Database.IronRod, 300.0),
assertEquals(1200, production.get(Database.IronIngot), "IronIngot"); new Ref(Database.IronIngot, 1200.0),
assertEquals(1200, production.get(Database.IronOre), "IronOre"); new Ref(Database.IronOre, 1200.0),
assertEquals(600, production.get(Database.IronPlate), "IronPlate");*/ new Ref(Database.IronPlate, 600.0)
fail(); );
SumResult sum = SumResult.sum(new Production(Database.ReinforcedIronPlate, 100.0));
compareProductions(sum, ref);
} }
@Test @Test
@ -55,65 +46,84 @@ class ItemTest {
@Test @Test
void testPhase3_ME_ACU() { void testPhase3_ME_ACU() {
// references // references
Map<Item, Double> ref = new HashMap<>(); Collection<Ref> ref = Arrays.asList(
ref.put(Database.CircuitBoard, 15.0); new Ref(Database.CircuitBoard, 15.0),
ref.put(Database.Computer, 1.0); new Ref(Database.Computer, 1.0),
ref.put(Database.Limestone,75.0); new Ref(Database.Limestone, 75.0),
ref.put(Database.Concrete,25.0); new Ref(Database.Concrete, 25.0),
ref.put(Database.SteelBeam,20.0); new Ref(Database.SteelBeam, 20.0),
ref.put(Database.EncasedIndustrialBeam, 5.0); new Ref(Database.EncasedIndustrialBeam, 5.0),
ref.put(Database.ModularFrame,5.0); new Ref(Database.ModularFrame, 5.0),
ref.put(Database.HeavyModularFrame,1.0); new Ref(Database.HeavyModularFrame, 1.0),
ref.put(Database.Plastic, 78.0); new Ref(Database.Plastic, 78.0),
ref.put(Database.CopperSheet, 30.0); new Ref(Database.CopperSheet, 30.0),
ref.put(Database.Coal,226.25); new Ref(Database.Coal, 226.25),
ref.put(Database.Cable,159.0); new Ref(Database.Cable, 159.0),
ref.put(Database.CopperOre,329.0); new Ref(Database.CopperOre, 329.0),
ref.put(Database.AutomatedWiring, 7.5); new Ref(Database.AutomatedWiring, 7.5),
ref.put(Database.AdaptiveControlUnit, 1.0); new Ref(Database.AdaptiveControlUnit, 1.0),
ref.put(Database.CrudeOil, 229.5); new Ref(Database.CrudeOil, 229.5),
ref.put(Database.ReinforcedIronPlate, 17.5); new Ref(Database.ReinforcedIronPlate, 17.5),
ref.put(Database.CopperIngot, 329.0); new Ref(Database.CopperIngot, 329.0),
ref.put(Database.SteelIngot, 226.25); new Ref(Database.SteelIngot, 226.25),
ref.put(Database.IronPlate, 105.0); new Ref(Database.IronPlate, 105.0),
ref.put(Database.SmartPlating, 10.0); new Ref(Database.SmartPlating, 10.0),
//ref.put(Database.HeavyOilResidue, 114.0); // TODO: implement calculation //new Ref(Database.HeavyOilResidue, 114.0), // TODO: implement calculation
ref.put(Database.Rubber, 75.0); new Ref(Database.Rubber, 75.0),
ref.put(Database.Wire, 538.0); new Ref(Database.Wire, 538.0),
ref.put(Database.SteelPipe, 97.5); new Ref(Database.SteelPipe, 97.5),
ref.put(Database.Stator, 27.5); new Ref(Database.Stator, 27.5),
ref.put(Database.Screw, 1112.0); new Ref(Database.Screw, 1112.0),
ref.put(Database.IronOre, 841.75); new Ref(Database.IronOre, 841.75),
ref.put(Database.IronIngot, 615.5); new Ref(Database.IronIngot, 615.5),
ref.put(Database.IronRod, 458.0); new Ref(Database.IronRod, 458.0),
ref.put(Database.Rotor, 30.0); new Ref(Database.Rotor, 30.0),
ref.put(Database.Motor, 10.0); new Ref(Database.Motor, 10.0),
ref.put(Database.ModularEngine, 5.0); new Ref(Database.ModularEngine, 5.0)
);
// calculate // calculate
Map<Item, Double> calculations = SumResult.sum(new Production(Database.ModularEngine, 5), new Production(Database.AdaptiveControlUnit, 1)).getMap(); SumResult sum = SumResult.sum(new Production(Database.ModularEngine, 5), new Production(Database.AdaptiveControlUnit, 1));
// assert // assert
ref.forEach((item, amount) -> { compareProductions(sum, ref);
assertTrue(calculations.containsKey(item), "exists? " + item.getName()); fail("Something heavy oil residue");
assertEquals(amount, calculations.get(item), 0.01, item.getName());
});
} }
@Test @Test
void uraniumFuelRodWithSteelIngotParents() { void uraniumFuelRodWithSteelIngotParents() {
Map<Item, Double> ref = new HashMap<>(); Collection<Ref> refs = Arrays.asList(
ref.put(Database.SteelIngot, 81.75); new Ref(Database.SteelIngot, 81.75),
ref.put(Database.IronOre, 81.75); new Ref(Database.IronOre, 81.75),
ref.put(Database.Coal, 81.75); new Ref(Database.Coal, 81.75)
compareProductions(Database.UraniumFuelRod, 1, ref); );
SumResult sums = SumResult.sum(new Production(Database.UraniumFuelRod, 1.0));
compareProductions(sums, refs);
} }
private void compareProductions(Item targetItem, int amount, Map<Item, Double> ref) { private void compareProductions(SumResult sum, Collection<Ref> references) {
Map<Item, Double> sum = SumResult.sum(new Production(targetItem, amount)).getMap(); Map<Item, Double> inputs = sum.getMap();
references.forEach(ref -> {
ref.forEach((item, aDouble) -> { assertTrue(inputs.containsKey(ref.item), ref.note);
assertTrue(sum.containsKey(item)); assertEquals(ref.amount, inputs.get(ref.item), ref.note);
assertEquals(aDouble, sum.get(item));
}); });
} }
} }
class Ref {
Item item;
double amount;
String note;
public Ref(Item item, double amount, String note) {
this.item = item;
this.amount = amount;
this.note = note;
}
public Ref(Item item, double amount) {
this.item = item;
this.amount = amount;
note = item.getName();
}
}