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);
}
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);
}
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"));
}
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);
}
Aggregations