Search in sources :

Example 6 with AggregationResult

use of org.talend.dataprep.transformation.aggregation.api.AggregationResult in project data-prep by Talend.

the class SumTest method shouldComputeSum.

@Test
public void shouldComputeSum() {
    // given when
    AggregationResult result = new AggregationResult(Operator.SUM);
    aggregator.accept(getRow("toto", "514.3"), result);
    aggregator.accept(getRow("toto", "0"), result);
    aggregator.accept(getRow("toto", ""), result);
    aggregator.accept(getRow("toto", "-786.25"), result);
    aggregator.accept(getRow("toto", "235874"), result);
    aggregator.accept(getRow("toto", "-8760"), result);
    // then
    Assert.assertEquals(result.get("toto").getValue(), 226842.05, 0);
}
Also used : AggregationResult(org.talend.dataprep.transformation.aggregation.api.AggregationResult) Test(org.junit.Test)

Example 7 with AggregationResult

use of org.talend.dataprep.transformation.aggregation.api.AggregationResult in project data-prep by Talend.

the class SumTest method shouldNormalizeHaveNoEffect.

@Test
public void shouldNormalizeHaveNoEffect() {
    // given when
    AggregationResult result = new AggregationResult(Operator.SUM);
    aggregator.accept(getRow("toto", "514.3"), result);
    aggregator.accept(getRow("toto", "0"), result);
    aggregator.accept(getRow("toto", ""), result);
    aggregator.accept(getRow("toto", "-786.25"), result);
    aggregator.accept(getRow("toto", "235874"), result);
    aggregator.accept(getRow("toto", "-8760"), result);
    // No effect for operation
    aggregator.normalize(result);
    // then
    Assert.assertEquals(result.get("toto").getValue(), 226842.05, 0);
}
Also used : AggregationResult(org.talend.dataprep.transformation.aggregation.api.AggregationResult) Test(org.junit.Test)

Example 8 with AggregationResult

use of org.talend.dataprep.transformation.aggregation.api.AggregationResult in project data-prep by Talend.

the class MinTest method shouldNormalizeHaveNoEffect.

@Test
public void shouldNormalizeHaveNoEffect() {
    // given when
    AggregationResult result = new AggregationResult(Operator.MIN);
    aggregator.accept(getRow("toto", "5123.4"), result);
    // <-- min here for tata
    aggregator.accept(getRow("tata", "-50.2"), result);
    aggregator.accept(getRow("toto", "786.884"), result);
    aggregator.accept(getRow("tata", "-0.2"), result);
    aggregator.accept(getRow("toto", "41843.453"), result);
    aggregator.accept(getRow("toto", "0"), result);
    aggregator.accept(getRow("tata", "20"), result);
    // <-- min here for toto
    aggregator.accept(getRow("toto", "-1"), result);
    aggregator.accept(getRow("toto", "8.87"), result);
    aggregator.accept(getRow("tata", "875"), result);
    aggregator.accept(getRow("toto", "-0.01"), result);
    // <-- should not be part of the result
    aggregator.accept(getRow("tutu", "dqsfqs"), result);
    // No effect for operation
    aggregator.normalize(result);
    // then
    Assert.assertEquals(result.get("toto").getValue(), -1, 0);
    Assert.assertEquals(result.get("tata").getValue(), -50.2, 0);
    Assert.assertNull(result.get("tutu"));
}
Also used : AggregationResult(org.talend.dataprep.transformation.aggregation.api.AggregationResult) Test(org.junit.Test)

Example 9 with AggregationResult

use of org.talend.dataprep.transformation.aggregation.api.AggregationResult in project data-prep by Talend.

the class AverageTest method shouldComputeAverage.

@Test
public void shouldComputeAverage() {
    AggregationResult result = new AggregationResult(Operator.AVERAGE);
    aggregator.accept(getRow("toto", "10"), result);
    aggregator.accept(getRow("toto", "2"), result);
    aggregator.accept(getRow("toto", "3.6"), result);
    aggregator.accept(getRow("toto", ""), result);
    aggregator.accept(getRow("toto", "8.2"), result);
    aggregator.accept(getRow("tata", "10"), result);
    aggregator.accept(getRow("toto", "-8"), result);
    aggregator.accept(getRow("toto", "12.3"), result);
    aggregator.accept(getRow("tata", "5"), result);
    final Average.AverageContext toto = (Average.AverageContext) result.get("toto");
    assertEquals(4.683d, toto.getValue(), 0.001d);
    final Average.AverageContext tata = (Average.AverageContext) result.get("tata");
    assertEquals(7.5d, tata.getValue(), 0);
}
Also used : AggregationResult(org.talend.dataprep.transformation.aggregation.api.AggregationResult) Test(org.junit.Test)

Aggregations

AggregationResult (org.talend.dataprep.transformation.aggregation.api.AggregationResult)9 Test (org.junit.Test)8 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)1 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)1 DataSetRow (org.talend.dataprep.api.dataset.row.DataSetRow)1 TDPException (org.talend.dataprep.exception.TDPException)1 Aggregator (org.talend.dataprep.transformation.aggregation.operation.Aggregator)1