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