blob: 7d5a949d3544868fabaa41344d66f2dfb9195e69 [file] [log] [blame]
/*
* Copyright 2017, Yahoo! Inc.
* Licensed under the terms of the Apache License 2.0. See LICENSE file at the project root for terms.
*/
package com.yahoo.sketches.pig.hll;
import org.apache.pig.EvalFunc;
import org.apache.pig.data.DataByteArray;
import org.apache.pig.data.TupleFactory;
import org.testng.annotations.Test;
import com.yahoo.sketches.hll.HllSketch;
import junit.framework.Assert;
public class SketchToEstimateTest {
private static final TupleFactory tupleFactory = TupleFactory.getInstance();
@Test
public void nullInputTuple() throws Exception {
EvalFunc<Double> func = new SketchToEstimate();
Double result = func.exec(null);
Assert.assertNull(result);
}
@Test
public void emptyInputTuple() throws Exception {
EvalFunc<Double> func = new SketchToEstimate();
Double result = func.exec(tupleFactory.newTuple());
Assert.assertNull(result);
}
@Test
public void normalCase() throws Exception {
EvalFunc<Double> func = new SketchToEstimate();
HllSketch sketch = new HllSketch(12);
sketch.update(1);
sketch.update(2);
Double result = func.exec(tupleFactory.newTuple(new DataByteArray(sketch.toCompactByteArray())));
Assert.assertNotNull(result);
Assert.assertEquals(result, 2.0, 0.01);
}
}