SimulationResult { protected DataEntry recalculateDataEntry(DataEntry old, int oldCount, double newValue) { if (old == null) { return new DataEntry(newValue, newValue, newValue); } double min = old.getMin() != null && old.getMin() < newValue ? old.getMin() : newValue; double max = old.getMax() != null && old.getMax() > newValue ? old.getMax() : newValue; double avg = MathUtil.getCumulativeMovingAverage(old.getAvg(), oldCount, newValue); return new DataEntry(min, max, avg); } SimulationResult(SupplyChain supplyChain); List<TestCaseResult> getResults(); SupplyChain getSupplyChain(); DataEntry getTotalCosts(); DataEntry getTotalCO2(); DataEntry getTotalLeadTimes(); DataEntry getTotalDelays(); DataEntry getTotalExtraCosts(); Map<String, DataEntry> getCo2ByCategory(); Map<String, DataEntry> getCo2ByNode(); Map<String, Event> getExecutedEvents(); Map<String, DataEntry> getCostsByCategory(); Map<String, DataEntry> getLeadTimesByCategory(); Map<String, DataEntry> getDelaysByCategory(); Map<String, DataEntry> getExtraCostsByCategory(); Map<String, DataEntry> getCostsByNode(); Map<String, DataEntry> getLeadTimesByNode(); Map<String, DataEntry> getDelaysByNode(); Map<String, DataEntry> getExtraCostsByNode(); Map<String, Double> getEventExecutionRate(); int getTestCaseCount(); void addTestCaseResult(TestCaseResult tcr);  }
@Test public void testRecalculateDataEntry() { SimulationResult instance = new SimulationResult(null); int oldCount = 0; double newValue = 6.0; DataEntry expResult = new DataEntry(6.0, 6.0, 6.0); DataEntry result = instance.recalculateDataEntry(null, oldCount, newValue); assertEquals(expResult.getMin(), result.getMin(), 0.00000001); assertEquals(expResult.getMax(), result.getMax(), 0.00000001); assertEquals(expResult.getAvg(), result.getAvg(), 0.00000001); DataEntry old = result; oldCount++; newValue = 10.0; expResult = new DataEntry(6.0, 10.0, 8.0); result = instance.recalculateDataEntry(old, oldCount, newValue); assertEquals(expResult.getMin(), result.getMin(), 0.00000001); assertEquals(expResult.getMax(), result.getMax(), 0.00000001); assertEquals(expResult.getAvg(), result.getAvg(), 0.00000001); old = result; oldCount++; newValue = 11.0; expResult = new DataEntry(6.0, 11.0, 9.0); result = instance.recalculateDataEntry(old, oldCount, newValue); assertEquals(expResult.getMin(), result.getMin(), 0.00000001); assertEquals(expResult.getMax(), result.getMax(), 0.00000001); assertEquals(expResult.getAvg(), result.getAvg(), 0.00000001); old = result; oldCount++; newValue = 21.0; expResult = new DataEntry(6.0, 21.0, 12.0); result = instance.recalculateDataEntry(old, oldCount, newValue); assertEquals(expResult.getMin(), result.getMin(), 0.00000001); assertEquals(expResult.getMax(), result.getMax(), 0.00000001); assertEquals(expResult.getAvg(), result.getAvg(), 0.00000001); old = result; oldCount++; newValue = 2.0; expResult = new DataEntry(2.0, 21.0, 10.0); result = instance.recalculateDataEntry(old, oldCount, newValue); assertEquals(expResult.getMin(), result.getMin(), 0.00000001); assertEquals(expResult.getMax(), result.getMax(), 0.00000001); assertEquals(expResult.getAvg(), result.getAvg(), 0.00000001); }