use of com.srotya.sidewinder.core.functions.list.ReduceFunction in project sidewinder by srotya.
the class TestSingleValueAggregators method testMeanAggregator.
@Test
public void testMeanAggregator() {
double[] values = { 2.2, 1.1, 3.3, 4.4 };
List<DataPoint> dps = new ArrayList<>();
long ts = System.currentTimeMillis();
for (double d : values) {
dps.add(MiscUtils.buildDataPoint(ts, d));
}
ReduceFunction sva = new MeanFunction();
SeriesOutput series = new SeriesOutput();
series.setFp(true);
series.setDataPoints(dps);
SeriesOutput result = sva.apply(series);
assertEquals(2.75, result.getDataPoints().get(0).getValue(), 0.01);
dps.clear();
long[] vals = { 1, 2, 3, 4, 5 };
for (long l : vals) {
dps.add(MiscUtils.buildDataPoint(ts, l));
}
series.setFp(false);
for (int p = 0; p < 1000; p++) {
result = sva.apply(series);
}
assertEquals(3, result.getDataPoints().get(0).getLongValue(), 0.01);
}
use of com.srotya.sidewinder.core.functions.list.ReduceFunction in project sidewinder by srotya.
the class TestSingleValueAggregators method testSumAggregator.
@Test
public void testSumAggregator() {
double[] values = { 2.2, 1.1, 3.3, 4.4 };
List<DataPoint> dps = new ArrayList<>();
long ts = System.currentTimeMillis();
for (double d : values) {
dps.add(MiscUtils.buildDataPoint(ts, d));
}
ReduceFunction sva = new SumFunction();
SeriesOutput series = new SeriesOutput();
series.setFp(true);
series.setDataPoints(dps);
SeriesOutput result = sva.apply(series);
assertEquals(11, result.getDataPoints().get(0).getValue(), 0.01);
dps.clear();
long[] vals = { 1, 2, 3, 4, 5 };
for (long l : vals) {
dps.add(MiscUtils.buildDataPoint(ts, l));
}
series.setFp(false);
result = sva.apply(series);
assertEquals(15, result.getDataPoints().get(0).getLongValue(), 0.01);
}
Aggregations