From: Hirzel P. <ph...@us...> - 2008-05-15 20:27:45
|
Update of /cvsroot/tcotool/TCO-Tool/test/org/tcotool/tools/test In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv9446/test/org/tcotool/tools/test Modified Files: CalculatorTestCase.java Log Message: Feature: calculating Cost#baseOffset (n*12 months) Index: CalculatorTestCase.java =================================================================== RCS file: /cvsroot/tcotool/TCO-Tool/test/org/tcotool/tools/test/CalculatorTestCase.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CalculatorTestCase.java 13 Jun 2007 20:19:50 -0000 1.3 --- CalculatorTestCase.java 15 May 2008 20:27:35 -0000 1.4 *************** *** 16,19 **** --- 16,20 ---- */ + import org.tcotool.model.FactCost; import org.tcotool.model.PersonalCost; import org.tcotool.model.TcoObject; *************** *** 21,24 **** --- 22,28 ---- import org.tcotool.tools.ModelUtility; + import ch.softenvironment.math.FinancialUtils; + import ch.softenvironment.math.MathUtils; + import junit.framework.TestCase; *************** *** 56,60 **** assertTrue("Multitude driver", ModelUtility.getMultitudeFactor(m.driver) == 5.0); ! assertTrue("Multitude driver", m.utility.getMultitudeFactor((TcoObject)m.driver, true) == m.driverFactor); try { --- 60,64 ---- assertTrue("Multitude driver", ModelUtility.getMultitudeFactor(m.driver) == 5.0); ! assertTrue("Multitude driver", m.utility.getMultitudeFactor((TcoObject)m.driver, true) == m.getDriverFactor()); try { *************** *** 68,72 **** assertTrue("Multitude driver", m.utility.getMultitudeFactor(pcost, true) == 0.0); pcost.setMultitude(new Double(6.0)); ! assertTrue("Multitude driver", m.utility.getMultitudeFactor(pcost, true) == m.driverFactor * 6.0); } catch(Throwable e) { fail(e.getLocalizedMessage()); --- 72,76 ---- assertTrue("Multitude driver", m.utility.getMultitudeFactor(pcost, true) == 0.0); pcost.setMultitude(new Double(6.0)); ! assertTrue("Multitude driver", m.utility.getMultitudeFactor(pcost, true) == m.getDriverFactor() * 6.0); } catch(Throwable e) { fail(e.getLocalizedMessage()); *************** *** 77,84 **** * @see Calculator#getPersonalHours() */ ! public void testPersonalHoursInternal() { try { double hours = 65.0; ! double total = m.driverFactor * 6.0 * hours; PersonalCost pcost = m.addPersonalCost(); // pcost.setAmount(new Double(195)); --- 81,88 ---- * @see Calculator#getPersonalHours() */ ! public void testTcoPersonalHoursInternal() { try { double hours = 65.0; ! double total = m.getDriverFactor() * 6.0 * hours; PersonalCost pcost = m.addPersonalCost(); // pcost.setAmount(new Double(195)); *************** *** 87,97 **** Calculator c = new Calculator(m.utility); ! double val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, /*Calculator.HOURS_INTERNAL*/ "INTERNAL"), Calculator.INDEX_TOTAL); assertTrue("PC Internal", val == total); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, /*Calculator.HOURS_EXTERNAL*/ "EXTERNAL"), Calculator.INDEX_TOTAL); assertTrue("PC External", val == 0.0); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, /*Calculator.HOURS_INTERNAL_LUMP*/ "INTERNAL_LUMP"), Calculator.INDEX_TOTAL); assertTrue("PC Internal Lump", val == 0.0); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, /*Calculator.HOURS_EXTERNAL_LUMP*/ "EXTERNAL_LUMP"), Calculator.INDEX_TOTAL); assertTrue("PC External Lump", val == 0.0); } catch(Throwable e) { --- 91,101 ---- Calculator c = new Calculator(m.utility); ! double val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, Calculator.PERSONAL_HOURS_INTERNAL /* "INTERNAL"*/), Calculator.INDEX_TOTAL); assertTrue("PC Internal", val == total); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, Calculator.PERSONAL_HOURS_EXTERNAL /*"EXTERNAL"*/), Calculator.INDEX_TOTAL); assertTrue("PC External", val == 0.0); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, Calculator.PERSONAL_COST_INTERNAL_LUMP /*"INTERNAL_LUMP"*/), Calculator.INDEX_TOTAL); assertTrue("PC Internal Lump", val == 0.0); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, Calculator.PERSONAL_COST_EXTERNAL_LUMP /*"EXTERNAL_LUMP"*/), Calculator.INDEX_TOTAL); assertTrue("PC External Lump", val == 0.0); } catch(Throwable e) { *************** *** 103,110 **** * @see Calculator#getPersonalHours() */ ! public void testPersonalHoursExternal() { try { double hours = 65.0; ! double total = m.driverFactor * 6.0 * hours; PersonalCost pcost = m.addPersonalCost(); pcost.setAmount(new Double(195)); --- 107,114 ---- * @see Calculator#getPersonalHours() */ ! public void testTcoPersonalHoursExternal() { try { double hours = 65.0; ! double total = m.getDriverFactor() * 6.0 * hours; PersonalCost pcost = m.addPersonalCost(); pcost.setAmount(new Double(195)); *************** *** 113,123 **** Calculator c = new Calculator(m.utility); ! double val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, /*Calculator.HOURS_INTERNAL*/ "INTERNAL"), Calculator.INDEX_TOTAL); assertTrue("PC Internal", val == 0.0); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, /*Calculator.HOURS_EXTERNAL*/ "EXTERNAL"), Calculator.INDEX_TOTAL); assertTrue("PC External", val == total); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, /*Calculator.HOURS_INTERNAL_LUMP*/ "INTERNAL_LUMP"), Calculator.INDEX_TOTAL); assertTrue("PC Internal Lump", val == 0.0); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, /*Calculator.HOURS_EXTERNAL_LUMP*/ "EXTERNAL_LUMP"), Calculator.INDEX_TOTAL); assertTrue("PC External Lump", val == 0.0); } catch(Throwable e) { --- 117,127 ---- Calculator c = new Calculator(m.utility); ! double val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, Calculator.PERSONAL_HOURS_INTERNAL), Calculator.INDEX_TOTAL); assertTrue("PC Internal", val == 0.0); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, Calculator.PERSONAL_HOURS_EXTERNAL), Calculator.INDEX_TOTAL); assertTrue("PC External", val == total); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, Calculator.PERSONAL_COST_INTERNAL_LUMP), Calculator.INDEX_TOTAL); assertTrue("PC Internal Lump", val == 0.0); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, Calculator.PERSONAL_COST_EXTERNAL_LUMP), Calculator.INDEX_TOTAL); assertTrue("PC External Lump", val == 0.0); } catch(Throwable e) { *************** *** 129,136 **** * @see Calculator#getPersonalHours() */ ! public void testPersonalCostLumpInternal() { try { double amount = 195.0; ! double total = m.driverFactor * 6.0 * amount; PersonalCost pcost = m.addPersonalCost(); pcost.setAmount(new Double(amount)); --- 133,140 ---- * @see Calculator#getPersonalHours() */ ! public void testTcoPersonalCostLumpInternal() { try { double amount = 195.0; ! double total = m.getDriverFactor() * 6.0 * amount; PersonalCost pcost = m.addPersonalCost(); pcost.setAmount(new Double(amount)); *************** *** 138,148 **** Calculator c = new Calculator(m.utility); ! double val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, /*Calculator.HOURS_INTERNAL*/ "INTERNAL"), Calculator.INDEX_TOTAL); assertTrue("PC Internal", val == 0.0); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, /*Calculator.HOURS_EXTERNAL*/ "EXTERNAL"), Calculator.INDEX_TOTAL); assertTrue("PC External", val == 0.0); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, /*Calculator.COST_INTERNAL_LUMP*/ "INTERNAL_LUMP"), Calculator.INDEX_TOTAL); assertTrue("PC Internal Lump", val == total); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, /*Calculator.COST_EXTERNAL_LUMP*/ "EXTERNAL_LUMP"), Calculator.INDEX_TOTAL); assertTrue("PC External Lump", val == 0.0); } catch(Throwable e) { --- 142,152 ---- Calculator c = new Calculator(m.utility); ! double val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, Calculator.PERSONAL_HOURS_INTERNAL), Calculator.INDEX_TOTAL); assertTrue("PC Internal", val == 0.0); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, Calculator.PERSONAL_HOURS_EXTERNAL), Calculator.INDEX_TOTAL); assertTrue("PC External", val == 0.0); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, Calculator.PERSONAL_COST_INTERNAL_LUMP), Calculator.INDEX_TOTAL); assertTrue("PC Internal Lump", val == total); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, Calculator.PERSONAL_COST_EXTERNAL_LUMP), Calculator.INDEX_TOTAL); assertTrue("PC External Lump", val == 0.0); } catch(Throwable e) { *************** *** 154,161 **** * @see Calculator#getPersonalHours() */ ! public void testPersonalCostLumpExternal() { try { double amount = 195.0; ! double total = m.driverFactor * 6.0 * amount; PersonalCost pcost = m.addPersonalCost(); pcost.setAmount(new Double(amount)); --- 158,165 ---- * @see Calculator#getPersonalHours() */ ! public void testTcoPersonalCostLumpExternal() { try { double amount = 195.0; ! double total = m.getDriverFactor() * 6.0 * amount; PersonalCost pcost = m.addPersonalCost(); pcost.setAmount(new Double(amount)); *************** *** 163,173 **** Calculator c = new Calculator(m.utility); ! double val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, /*Calculator.HOURS_INTERNAL*/ "INTERNAL"), Calculator.INDEX_TOTAL); assertTrue("PC Internal", val == 0.0); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, /*Calculator.HOURS_EXTERNAL*/ "EXTERNAL"), Calculator.INDEX_TOTAL); assertTrue("PC External", val == 0.0); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, /*Calculator.HOURS_INTERNAL_LUMP*/ "INTERNAL_LUMP"), Calculator.INDEX_TOTAL); assertTrue("PC Internal Lump", val == 0.0); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, /*Calculator.HOURS_EXTERNAL_LUMP*/ "EXTERNAL_LUMP"), Calculator.INDEX_TOTAL); assertTrue("PC External Lump", val == total); } catch(Throwable e) { --- 167,177 ---- Calculator c = new Calculator(m.utility); ! double val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, Calculator.PERSONAL_HOURS_INTERNAL), Calculator.INDEX_TOTAL); assertTrue("PC Internal", val == 0.0); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, Calculator.PERSONAL_HOURS_EXTERNAL), Calculator.INDEX_TOTAL); assertTrue("PC External", val == 0.0); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, Calculator.PERSONAL_COST_INTERNAL_LUMP), Calculator.INDEX_TOTAL); assertTrue("PC Internal Lump", val == 0.0); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, Calculator.PERSONAL_COST_EXTERNAL_LUMP), Calculator.INDEX_TOTAL); assertTrue("PC External Lump", val == total); } catch(Throwable e) { *************** *** 175,194 **** } } ! public void testPersonalRoleFTE() { try { ! // double total = m.driverFactor * 6.0 * amount; PersonalCost pcost = m.addPersonalCost(); pcost.setRole(m.role); ! m.utility.updateRole(pcost); ! double hours = m.driverFactor * 6.0 * m.role.getYearlyHours().doubleValue(); Calculator c = new Calculator(m.utility); ! double val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, /*Calculator.HOURS_INTERNAL*/ "INTERNAL"), Calculator.INDEX_TOTAL); assertTrue("PC Internal", val == hours); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, /*Calculator.HOURS_EXTERNAL*/ "EXTERNAL"), Calculator.INDEX_TOTAL); assertTrue("PC External", val == 0.0); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, /*Calculator.COST_INTERNAL_LUMP*/ "INTERNAL_LUMP"), Calculator.INDEX_TOTAL); assertTrue("PC Internal Lump", val == 0.0); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, /*Calculator.COST_EXTERNAL_LUMP*/ "EXTERNAL_LUMP"), Calculator.INDEX_TOTAL); assertTrue("PC External Lump", val == 0.0); } catch(Throwable e) { --- 179,198 ---- } } ! public void testTcoPersonalRoleFTE() { try { ! // double total = m.getDriverFactor() * 6.0 * amount; PersonalCost pcost = m.addPersonalCost(); pcost.setRole(m.role); ! ModelUtility.updateRole(pcost); ! double hours = m.getDriverFactor() * 6.0 * m.role.getYearlyHours().doubleValue(); Calculator c = new Calculator(m.utility); ! double val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, Calculator.PERSONAL_HOURS_INTERNAL), Calculator.INDEX_TOTAL); assertTrue("PC Internal", val == hours); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, Calculator.PERSONAL_HOURS_EXTERNAL), Calculator.INDEX_TOTAL); assertTrue("PC External", val == 0.0); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, Calculator.PERSONAL_COST_INTERNAL_LUMP), Calculator.INDEX_TOTAL); assertTrue("PC Internal Lump", val == 0.0); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, Calculator.PERSONAL_COST_EXTERNAL_LUMP), Calculator.INDEX_TOTAL); assertTrue("PC External Lump", val == 0.0); } catch(Throwable e) { *************** *** 196,216 **** } } ! public void testPersonalRoleHours() { try { ! // double total = m.driverFactor * 6.0 * amount; PersonalCost pcost = m.addPersonalCost(); pcost.setRole(m.role); pcost.setHours(new Double(13.0)); m.utility.updateRole(pcost); ! double hours = m.driverFactor * 6.0 * 13.0; Calculator c = new Calculator(m.utility); ! double val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, /*Calculator.HOURS_INTERNAL*/ "INTERNAL"), Calculator.INDEX_TOTAL); assertTrue("PC Internal", val == hours); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, /*Calculator.HOURS_EXTERNAL*/ "EXTERNAL"), Calculator.INDEX_TOTAL); assertTrue("PC External", val == 0.0); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, /*Calculator.COST_INTERNAL_LUMP*/ "INTERNAL_LUMP"), Calculator.INDEX_TOTAL); assertTrue("PC Internal Lump", val == 0.0); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, /*Calculator.COST_EXTERNAL_LUMP*/ "EXTERNAL_LUMP"), Calculator.INDEX_TOTAL); assertTrue("PC External Lump", val == 0.0); } catch(Throwable e) { --- 200,220 ---- } } ! public void testTcoPersonalRoleHours() { try { ! // double total = m.getDriverFactor() * 6.0 * amount; PersonalCost pcost = m.addPersonalCost(); pcost.setRole(m.role); pcost.setHours(new Double(13.0)); m.utility.updateRole(pcost); ! double hours = m.getDriverFactor() * 6.0 * 13.0; Calculator c = new Calculator(m.utility); ! double val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, Calculator.PERSONAL_HOURS_INTERNAL), Calculator.INDEX_TOTAL); assertTrue("PC Internal", val == hours); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, Calculator.PERSONAL_HOURS_EXTERNAL), Calculator.INDEX_TOTAL); assertTrue("PC External", val == 0.0); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, Calculator.PERSONAL_COST_INTERNAL_LUMP), Calculator.INDEX_TOTAL); assertTrue("PC Internal Lump", val == 0.0); ! val = Calculator.getValue(c.getCosts(m.model, Calculator.PERSONAL_TCO, Calculator.PERSONAL_COST_EXTERNAL_LUMP), Calculator.INDEX_TOTAL); assertTrue("PC External Lump", val == 0.0); } catch(Throwable e) { *************** *** 218,220 **** --- 222,496 ---- } } + /** + * Test the DIRECT/INDIRECT costs defined by CostCause. + */ + public void testTcoCostDirect() { + try { + Calculator c = new Calculator(m.utility /*, durationMonths*/); + double pDirect = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.PERSONAL_DIRECT), Calculator.INDEX_TOTAL); + double pIndirect = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.PERSONAL_INDIRECT), Calculator.INDEX_TOTAL); + double pUndefined = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.PERSONAL_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL); + double fDirect = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.FACT_DIRECT), Calculator.INDEX_TOTAL); + double fIndirect = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.FACT_INDIRECT), Calculator.INDEX_TOTAL); + double fUndefined = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.FACT_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL); + assertTrue("Personal DIRECT", MathUtils.compare(0.0, pDirect) == 0); + assertTrue("Personal INDIRECT", MathUtils.compare(0.0, pIndirect) == 0); + assertTrue("Personal UNDEFINED", MathUtils.compare(0.0, pUndefined) == 0); + assertTrue("Fact DIRECT", MathUtils.compare(0.0, fDirect) == 0); + assertTrue("Fact INDIRECT", MathUtils.compare(0.0, fIndirect) == 0); + assertTrue("Fact UNDEFINED", MathUtils.compare(0.0, fUndefined) == 0); + + PersonalCost pCost = m.addPersonalCost(); + //pCost.setRole(m.role); + //pCost.setHours(new Double(13.0)); + pCost.setAmount(new Double(100.45)); + c = new Calculator(m.utility); + pDirect = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.PERSONAL_DIRECT), Calculator.INDEX_TOTAL); + pIndirect = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.PERSONAL_INDIRECT), Calculator.INDEX_TOTAL); + pUndefined = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.PERSONAL_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL); + fDirect = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.FACT_DIRECT), Calculator.INDEX_TOTAL); + fIndirect = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.FACT_INDIRECT), Calculator.INDEX_TOTAL); + fUndefined = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.FACT_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL); + assertTrue("Personal DIRECT", MathUtils.compare(0.0, pDirect) == 0); + assertTrue("Personal INDIRECT", MathUtils.compare(0.0, pIndirect) == 0); + assertTrue("Personal UNDEFINED", MathUtils.compare(m.getDriverFactor() * 6.0 * 100.45, pUndefined) == 0); + assertTrue("Fact DIRECT", MathUtils.compare(0.0, fDirect) == 0); + assertTrue("Fact INDIRECT", MathUtils.compare(0.0, fIndirect) == 0); + assertTrue("Fact UNDEFINED", MathUtils.compare(0.0, fUndefined) == 0); + + FactCost fCost = m.addFactCost(); + fCost.setAmount(new Double(93.17)); + c = new Calculator(m.utility); + pDirect = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.PERSONAL_DIRECT), Calculator.INDEX_TOTAL); + pIndirect = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.PERSONAL_INDIRECT), Calculator.INDEX_TOTAL); + pUndefined = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.PERSONAL_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL); + fDirect = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.FACT_DIRECT), Calculator.INDEX_TOTAL); + fIndirect = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.FACT_INDIRECT), Calculator.INDEX_TOTAL); + fUndefined = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.FACT_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL); + assertTrue("Personal DIRECT", MathUtils.compare(0.0, pDirect) == 0); + assertTrue("Personal INDIRECT", MathUtils.compare(0.0, pIndirect) == 0); + assertTrue("Personal UNDEFINED", MathUtils.compare(m.getDriverFactor() * 6.0 * 100.45, pUndefined) == 0); + assertTrue("Fact DIRECT", MathUtils.compare(0.0, fDirect) == 0); + assertTrue("Fact INDIRECT", MathUtils.compare(0.0, fIndirect) == 0); + assertTrue("Fact UNDEFINED", MathUtils.compare(m.getDriverFactor() * 7.0 * 93.17, fUndefined) == 0); + //TODO for real CostCause instances + } catch(Throwable e) { + fail(e.getLocalizedMessage()); + } + } + public void testTcoCostEstimated() { + try { + Calculator c = new Calculator(m.utility /*, durationMonths*/); + double pEstimated = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.PERSONAL_ESTIMATED), Calculator.INDEX_TOTAL); + double pKnown = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.PERSONAL_KNOWN), Calculator.INDEX_TOTAL); + double fEstimated = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.FACT_ESTIMATED), Calculator.INDEX_TOTAL); + double fKnown = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.FACT_KNOWN), Calculator.INDEX_TOTAL); + double totalEstimated = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.ESTIMATED), Calculator.INDEX_TOTAL); + double totalKnown = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.KNOWN), Calculator.INDEX_TOTAL); + assertTrue("Personal ESTIMATED", MathUtils.compare(0.0, pEstimated) == 0); + assertTrue("Personal KNOWN", MathUtils.compare(0.0, pKnown) == 0); + assertTrue("Fact ESTIMATED", MathUtils.compare(0.0, fEstimated) == 0); + assertTrue("Fact KNOWN", MathUtils.compare(0.0, fKnown) == 0); + assertTrue("Total ESTIMATED", MathUtils.compare(0.0, totalEstimated) == 0); + assertTrue("TOTAL KNOWN", MathUtils.compare(0.0, totalKnown) == 0); + + PersonalCost pCost = m.addPersonalCost(); + pCost.setAmount(new Double(100.0)); + pCost.setEstimated(Boolean.TRUE); + pCost = m.addPersonalCost(); + pCost.setAmount(new Double(50.0)); + pCost.setEstimated(Boolean.FALSE); + FactCost fCost = m.addFactCost(); + fCost.setAmount(new Double(70.0)); + fCost.setEstimated(Boolean.TRUE); + fCost = m.addFactCost(); + fCost.setAmount(new Double(30.0)); + fCost.setEstimated(Boolean.FALSE); + c = new Calculator(m.utility); + pEstimated = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.PERSONAL_ESTIMATED), Calculator.INDEX_TOTAL); + pKnown = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.PERSONAL_KNOWN), Calculator.INDEX_TOTAL); + fEstimated = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.FACT_ESTIMATED), Calculator.INDEX_TOTAL); + fKnown = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.FACT_KNOWN), Calculator.INDEX_TOTAL); + totalEstimated = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.ESTIMATED), Calculator.INDEX_TOTAL); + totalKnown = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.KNOWN), Calculator.INDEX_TOTAL); + double pTmp = m.getDriverFactor() * 6.0 * 100.0; + assertTrue("Personal ESTIMATED", MathUtils.compare(pTmp, pEstimated) == 0); + double fTmp = m.getDriverFactor() * 7.0 * 70.0; + assertTrue("Fact ESTIMATED", MathUtils.compare(fTmp, fEstimated) == 0); + assertTrue("Total ESTIMATED", MathUtils.compare(pTmp + fTmp, totalEstimated) == 0); + pTmp = m.getDriverFactor() * 6.0 * 50.0; + assertTrue("Personal KNOWN", MathUtils.compare(pTmp, pKnown) == 0); + fTmp = m.getDriverFactor() * 7.0 * 30.0; + assertTrue("Fact KNOWN", MathUtils.compare(fTmp, fKnown) == 0); + assertTrue("TOTAL KNOWN", MathUtils.compare(pTmp + fTmp, totalKnown) == 0); + //TODO for real CostCause instances + } catch(Throwable e) { + fail(e.getLocalizedMessage()); + } + } + public void testTcoFactCostBaseOffset() { + try { + long durationMonths = 48; + double perYear = durationMonths / 12; + m.utility.getSystemParameter().setDefaultUsageDuration(new Long(durationMonths)); + + FactCost fCost = m.addFactCost(); + fCost.setUsageDuration(new Long(durationMonths)); + fCost.setAmount(new Double(2000.0)); + fCost.setBaseOffset(new Long(0)); + fCost.setRepeatable(Boolean.FALSE); + + double total0 = m.getDriverFactor() * (7.0*2000.0); + + // 1st TCO-Year + Calculator c = new Calculator(m.utility, (TcoObject)m.utility.getRoot(), durationMonths+24 /*must be longer*/); + double f = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.FACT_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL + 0); + assertTrue("Total cost; offset=0", MathUtils.compare(total0, f) == 0); + f = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.FACT_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL + 1); + assertTrue("1. year; offset=0", MathUtils.compare(total0 /perYear, f) == 0); + f = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.FACT_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL + 2); + assertTrue("2. year; offset=0", MathUtils.compare(total0 /perYear, f) == 0); + f = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.FACT_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL + 3); + assertTrue("3. year; offset=0", MathUtils.compare(total0 /perYear, f) == 0); + f = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.FACT_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL + 4); + assertTrue("4. year; offset=0", MathUtils.compare(total0 /perYear, f) == 0); + f = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.FACT_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL + 5); + assertTrue("5. year; offset=0, non-repeatable", MathUtils.compare(0.0, f) == 0); + + fCost.setBaseOffset(new Long(12)); + c = new Calculator(m.utility, (TcoObject)m.utility.getRoot(), durationMonths+24 /*must be longer*/); + f = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.FACT_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL + 0); + assertTrue("Total cost; offset=12", MathUtils.compare(total0, f) == 0); + f = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.FACT_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL + 1); + assertTrue("1. year; offset=12", MathUtils.compare(0.0, f) == 0); + f = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.FACT_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL + 2); + assertTrue("2. year; offset=12", MathUtils.compare(total0 /perYear, f) == 0); + f = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.FACT_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL + 3); + assertTrue("3. year; offset=12", MathUtils.compare(total0 /perYear, f) == 0); + f = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.FACT_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL + 4); + assertTrue("4. year; offset=12", MathUtils.compare(total0 /perYear, f) == 0); + f = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.FACT_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL + 5); + assertTrue("5. year; offset=12;", MathUtils.compare(total0 /perYear, f) == 0); + f = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.FACT_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL + 6); + assertTrue("6. year; offset=12; non-repeatable", MathUtils.compare(0.0, f) == 0); + + fCost.setRepeatable(Boolean.TRUE); + c = new Calculator(m.utility, (TcoObject)m.utility.getRoot(), durationMonths+24 /*must be longer*/); + f = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.FACT_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL + 0); + assertTrue("Total cost; offset=12", MathUtils.compare(total0, f) == 0); + f = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.FACT_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL + 1); + assertTrue("1. year; offset=12", MathUtils.compare(0.0, f) == 0); + f = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.FACT_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL + 2); + assertTrue("2. year; offset=12", MathUtils.compare(total0 /perYear, f) == 0); + f = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.FACT_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL + 3); + assertTrue("3. year; offset=12", MathUtils.compare(total0 /perYear, f) == 0); + f = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.FACT_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL + 4); + assertTrue("4. year; offset=12", MathUtils.compare(total0 /perYear, f) == 0); + f = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.FACT_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL + 5); + assertTrue("5. year; offset=12;", MathUtils.compare(total0 /perYear, f) == 0); + f = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.FACT_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL + 6); + assertTrue("6. year; offset=12; repeatable=>never ending", MathUtils.compare(total0 /perYear, f) == 0); + + fCost.setBaseOffset(new Long(3)); // check offset in the middle of the year + c = new Calculator(m.utility, (TcoObject)m.utility.getRoot(), durationMonths+24 /*must be longer*/); + f = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.FACT_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL + 0); + //TODO test years + } catch(Throwable e) { + fail(e.getLocalizedMessage()); + } + } + public void testTcoPersonalCostBaseOffset() { + try { + int durationMonths = 12; // PersonalCost always meant for 1 year! + + PersonalCost fCost = m.addPersonalCost(); + fCost.setMultitude(new Double(7.0)); + fCost.setAmount(new Double(2000.0)); + fCost.setBaseOffset(new Long(0)); + fCost.setRepeatable(Boolean.FALSE); + + double total0 = m.getDriverFactor() * (7.0*2000.0); + + // 1st TCO-Year + Calculator c = new Calculator(m.utility, (TcoObject)m.utility.getRoot(), durationMonths+24 /*must be longer*/); + double f = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.PERSONAL_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL + 0); + assertTrue("Total cost; offset=0", MathUtils.compare(total0, f) == 0); + f = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.PERSONAL_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL + 1); + assertTrue("1. year; offset=0", MathUtils.compare(total0, f) == 0); + f = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.PERSONAL_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL + 2); + assertTrue("2. year; offset=0", MathUtils.compare(0.0, f) == 0); + + fCost.setBaseOffset(new Long(12)); + c = new Calculator(m.utility, (TcoObject)m.utility.getRoot(), durationMonths+24 /*must be longer*/); + f = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.PERSONAL_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL + 0); + assertTrue("Total cost; offset=12", MathUtils.compare(total0, f) == 0); + f = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.PERSONAL_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL + 1); + assertTrue("1. year; offset=12", MathUtils.compare(0.0, f) == 0); + f = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.PERSONAL_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL + 2); + assertTrue("2. year; offset=12", MathUtils.compare(total0, f) == 0); + f = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.PERSONAL_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL + 3); + assertTrue("3. year; offset=12; non-repeatable", MathUtils.compare(0.0, f) == 0); + + fCost.setRepeatable(Boolean.TRUE); + c = new Calculator(m.utility, (TcoObject)m.utility.getRoot(), durationMonths+36 /*must be longer*/); + f = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.PERSONAL_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL + 0); + assertTrue("Total cost; offset=12", MathUtils.compare(total0, f) == 0); + f = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.PERSONAL_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL + 1); + assertTrue("1. year; offset=12", MathUtils.compare(0.0, f) == 0); + f = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.PERSONAL_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL + 2); + assertTrue("2. year; offset=12", MathUtils.compare(total0, f) == 0); + f = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.PERSONAL_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL + 3); + assertTrue("3. year; offset=12, repeatable!!!", MathUtils.compare(total0, f) == 0); + f = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.PERSONAL_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL + 4); + assertTrue("4. year; offset=12, repeatable!!!", MathUtils.compare(total0, f) == 0); + + fCost.setBaseOffset(new Long(3)); // check offset in the middle of the year + c = new Calculator(m.utility, (TcoObject)m.utility.getRoot(), durationMonths+24 /*must be longer*/); + f = Calculator.getValue(c.getTcoCodeTotal((TcoObject)m.utility.getRoot(), Calculator.PERSONAL_DIRECT_UNDEFINED), Calculator.INDEX_TOTAL + 0); + //TODO + } catch(Throwable e) { + fail(e.getLocalizedMessage()); + } + + + } + /** + * Check with sample: + * http://www.harri-deutsch.de/verlag/titel/pfeifer/k01_1736.pdf + */ + public void testCalcDepreciationLinear() { + double value = 10000; // Buchwert des Wirtschaftsgutes zu Beginn + int usageDuration = 5; // years + + assertTrue("Linear Begin", FinancialUtils.calcDepreciationLinear(value, usageDuration, 0) == value); + assertTrue("Linear 1.Year", FinancialUtils.calcDepreciationLinear(value, usageDuration, 1) == 8000.0); + assertTrue("Linear 2.Year", FinancialUtils.calcDepreciationLinear(value, usageDuration, 2) == 6000.0); + assertTrue("Linear 3.Year", FinancialUtils.calcDepreciationLinear(value, usageDuration, 3) == 4000.0); + assertTrue("Linear 4.Year", FinancialUtils.calcDepreciationLinear(value, usageDuration, 4) == 2000.0); + assertTrue("Linear 5.Year", FinancialUtils.calcDepreciationLinear(value, usageDuration, 5) == 0.0); + assertTrue("Linear after depreciation", FinancialUtils.calcDepreciationLinear(value, usageDuration, 6) == 0.0); + } + /** + * Check with sample: + * http://www.harri-deutsch.de/verlag/titel/pfeifer/k01_1736.pdf + */ + public void testCalcDepreciationGeometricDegressive() { + double value = 10000; // Buchwert des Wirtschaftsgutes zu Beginn + int usageDuration = 5; // years + + double p = 20; // %-Satz der jährlich vom Buchwert abgeschrieben werden soll + assertTrue("Degressive Begin", FinancialUtils.calcDepreciationGeometricDegressive(value, p, 0) == value); + assertTrue("Degressive 1.Year", (long)FinancialUtils.calcDepreciationGeometricDegressive(value, p, 1) == 8000); + assertTrue("Degressive 2.Year", (long)FinancialUtils.calcDepreciationGeometricDegressive(value, p, 2) == 6400); + assertTrue("Degressive 3.Year", (long)FinancialUtils.calcDepreciationGeometricDegressive(value, p, 3) == 5120); + assertTrue("Degressive 4.Year", (long)FinancialUtils.calcDepreciationGeometricDegressive(value, p, 4) == 4096); + assertTrue("Degressive 5.Year", (long)FinancialUtils.calcDepreciationGeometricDegressive(value, p, 5) == 3276); + + value = 120000; + p = 5; + usageDuration = 4; + assertTrue("Degressive Begin", FinancialUtils.calcDepreciationGeometricDegressive(value, p, 0) == value); + assertTrue("Degressive 1.Year", (long)FinancialUtils.calcDepreciationGeometricDegressive(value, p, 1) == 114000); + assertTrue("Degressive 2.Year", (long)FinancialUtils.calcDepreciationGeometricDegressive(value, p, 2) == 108300); + } } |