Search in sources :

Example 6 with KeyItem

use of org.estatio.module.budget.dom.keyitem.KeyItem in project estatio by estatio.

the class DistributionService_Test method generateKeyValuesRoundingBy2DecimalsNegativeDelta.

@Test
public void generateKeyValuesRoundingBy2DecimalsNegativeDelta() {
    // given
    DistributionService distributionService = new DistributionService();
    List<Distributable> input = new ArrayList<>();
    // 10000.99
    KeyItem item1 = new KeyItem();
    item1.setSourceValue(BigDecimal.valueOf(10000.99));
    input.add(item1);
    // 200.09
    KeyItem item2 = new KeyItem();
    item2.setSourceValue(BigDecimal.valueOf(200.09));
    input.add(item2);
    // 1.99
    for (int i = 2; i < 14; i = i + 1) {
        KeyItem item = new KeyItem();
        item.setSourceValue(BigDecimal.valueOf(1.99));
        input.add(item);
    }
    // theoretical max rounding error: 14*0.005 = +/-0.07
    // in this example here we get to -0.05
    // when
    List<Distributable> output = distributionService.distribute(input, new BigDecimal(1000), 2);
    BigDecimal sumRoundedValues = BigDecimal.ZERO;
    for (Distributable object : output) {
        sumRoundedValues = sumRoundedValues.add(object.getValue(), MathContext.DECIMAL32);
    }
    // then
    assertThat(output).hasSize(14);
    assertThat(output.get(0).getValue()).isEqualTo(BigDecimal.valueOf(978.10).setScale(2, BigDecimal.ROUND_HALF_UP));
    assertThat(output.get(1).getValue()).isEqualTo(BigDecimal.valueOf(19.57).setScale(2, BigDecimal.ROUND_HALF_UP));
    for (int i = 2; i < 9; i = i + 1) {
        assertThat(output.get(i).getValue()).isEqualTo(BigDecimal.valueOf(0.19).setScale(2, BigDecimal.ROUND_HALF_UP));
    }
    for (int i = 9; i < 14; i = i + 1) {
        assertThat(output.get(i).getValue()).isEqualTo(BigDecimal.valueOf(0.20).setScale(2, BigDecimal.ROUND_HALF_UP));
    }
    assertThat(sumRoundedValues.setScale(2, BigDecimal.ROUND_HALF_UP)).isEqualTo(BigDecimal.valueOf(1000.00).setScale(2, BigDecimal.ROUND_HALF_UP));
}
Also used : ArrayList(java.util.ArrayList) KeyItem(org.estatio.module.budget.dom.keyitem.KeyItem) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 7 with KeyItem

use of org.estatio.module.budget.dom.keyitem.KeyItem in project estatio by estatio.

the class DistributionService_Test method oneNonZeroSourceValue.

@Test
public void oneNonZeroSourceValue() {
    // given
    DistributionService distributionService = new DistributionService();
    List<Distributable> input = new ArrayList<>();
    for (int i = 1; i <= 5; i = i + 1) {
        KeyItem item = new KeyItem();
        item.setSourceValue(BigDecimal.ZERO);
        input.add(item);
    }
    KeyItem item = new KeyItem();
    item.setSourceValue(BigDecimal.ONE);
    input.add(item);
    // when
    List<Distributable> output = distributionService.distribute(input, BigDecimal.ONE, 3);
    BigDecimal sumRoundedValues = BigDecimal.ZERO;
    for (Distributable object : output) {
        sumRoundedValues = sumRoundedValues.add(object.getValue(), MathContext.DECIMAL64);
    }
    // then
    assertThat(output).hasSize(6);
    assertThat(sumRoundedValues.setScale(3, BigDecimal.ROUND_HALF_UP)).isEqualTo(BigDecimal.ONE.setScale(3, BigDecimal.ROUND_HALF_UP));
}
Also used : ArrayList(java.util.ArrayList) KeyItem(org.estatio.module.budget.dom.keyitem.KeyItem) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 8 with KeyItem

use of org.estatio.module.budget.dom.keyitem.KeyItem in project estatio by estatio.

the class DistributionService_Test method justZeroSourceValues.

@Test
public void justZeroSourceValues() {
    // given
    DistributionService distributionService = new DistributionService();
    List<Distributable> input = new ArrayList<>();
    for (int i = 1; i <= 5; i = i + 1) {
        KeyItem item = new KeyItem();
        item.setSourceValue(BigDecimal.ZERO);
        input.add(item);
    }
    // when
    List<Distributable> output = distributionService.distribute(input, BigDecimal.ONE, 3);
    BigDecimal sumRoundedValues = BigDecimal.ZERO;
    for (Distributable object : output) {
        sumRoundedValues = sumRoundedValues.add(object.getValue(), MathContext.DECIMAL64);
    }
    // then
    assertThat(output).hasSize(5);
    assertThat(sumRoundedValues.setScale(3, BigDecimal.ROUND_HALF_UP)).isEqualTo(BigDecimal.ZERO.setScale(3, BigDecimal.ROUND_HALF_UP));
}
Also used : ArrayList(java.util.ArrayList) KeyItem(org.estatio.module.budget.dom.keyitem.KeyItem) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 9 with KeyItem

use of org.estatio.module.budget.dom.keyitem.KeyItem in project estatio by estatio.

the class KeyItem_Test method testChangeAuditedValue.

@Test
public void testChangeAuditedValue() {
    // given
    KeyTable table = new KeyTable();
    table.setPrecision(3);
    KeyItem item = new KeyItem();
    item.setAuditedValue(new BigDecimal(2));
    item.setKeyTable(table);
    assertTrue(item.getAuditedValue().equals(new BigDecimal(2)));
    // when
    item.changeAuditedValue(BigDecimal.valueOf(2.3335));
    // then
    assertEquals(item.getAuditedValue(), BigDecimal.valueOf(2.334).setScale(3, BigDecimal.ROUND_HALF_UP));
}
Also used : KeyTable(org.estatio.module.budget.dom.keytable.KeyTable) KeyItem(org.estatio.module.budget.dom.keyitem.KeyItem) BigDecimal(java.math.BigDecimal) AbstractBeanPropertiesTest(org.incode.module.unittestsupport.dom.bean.AbstractBeanPropertiesTest) Test(org.junit.Test)

Example 10 with KeyItem

use of org.estatio.module.budget.dom.keyitem.KeyItem in project estatio by estatio.

the class KeyItem_Test method testChangeSourceValue.

@Test
public void testChangeSourceValue() {
    // given
    KeyTable table = new KeyTable();
    table.setPrecision(3);
    KeyItem item = new KeyItem();
    item.setSourceValue(new BigDecimal(2));
    item.setKeyTable(table);
    assertTrue(item.getSourceValue().equals(new BigDecimal(2)));
    // when
    item.changeSourceValue(BigDecimal.valueOf(2.335));
    // then
    assertEquals(item.getSourceValue(), BigDecimal.valueOf(2.34).setScale(2, BigDecimal.ROUND_HALF_UP));
}
Also used : KeyTable(org.estatio.module.budget.dom.keytable.KeyTable) KeyItem(org.estatio.module.budget.dom.keyitem.KeyItem) BigDecimal(java.math.BigDecimal) AbstractBeanPropertiesTest(org.incode.module.unittestsupport.dom.bean.AbstractBeanPropertiesTest) Test(org.junit.Test)

Aggregations

KeyItem (org.estatio.module.budget.dom.keyitem.KeyItem)27 BigDecimal (java.math.BigDecimal)23 Test (org.junit.Test)22 ArrayList (java.util.ArrayList)17 KeyTable (org.estatio.module.budget.dom.keytable.KeyTable)7 AbstractBeanPropertiesTest (org.incode.module.unittestsupport.dom.bean.AbstractBeanPropertiesTest)6 TreeSet (java.util.TreeSet)3 Action (org.apache.isis.applib.annotation.Action)3 List (java.util.List)1 ActionLayout (org.apache.isis.applib.annotation.ActionLayout)1 MemberOrder (org.apache.isis.applib.annotation.MemberOrder)1 Unit (org.estatio.module.asset.dom.Unit)1 Distributable (org.estatio.module.budget.dom.Distributable)1 DistributionService (org.estatio.module.budget.dom.DistributionService)1 KeyItemImportExportLineItem (org.estatio.module.budgetassignment.imports.KeyItemImportExportLineItem)1 WorksheetSpec (org.isisaddons.module.excel.dom.WorksheetSpec)1