Skip to content

Commit

Permalink
add more UT
Browse files Browse the repository at this point in the history
  • Loading branch information
HTHou committed Dec 25, 2024
1 parent 2a23976 commit 3f5ece7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ public float readFloat(ByteBuffer buffer) {
public double readDouble(ByteBuffer buffer) {
readMaxPointValue(buffer);
long value = decoder.readLong(buffer);
return value / getMaxPointValue();
double result = value / getMaxPointValue();
position++;
return result;
}

private double getMaxPointValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.ArrayList;
import java.util.List;

import static org.apache.tsfile.utils.EncodingUtils.roundWithGivenPrecision;
import static org.junit.Assert.assertEquals;

public class FloatDecoderTest {
Expand Down Expand Up @@ -219,12 +220,20 @@ public void testBigFloat() throws Exception {
assertEquals(roundWithGivenPrecision(b, 2), decoder.readFloat(buffer), delta);
}

public static float roundWithGivenPrecision(float data, int size) {
if (size == 0) {
return Math.round(data);
}
return Math.round(data)
+ Math.round(((data - Math.round(data)) * Math.pow(10, size))) / (float) Math.pow(10, size);
@Test
public void testBigDouble() throws Exception {
double a = 0.333;
double b = 9.223372036854E18;
Encoder encoder = new FloatEncoder(TSEncoding.RLE, TSDataType.DOUBLE, 2);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
encoder.encode(a, baos);
encoder.encode(b, baos);
encoder.flush(baos);

ByteBuffer buffer = ByteBuffer.wrap(baos.toByteArray());
Decoder decoder = new FloatDecoder(TSEncoding.RLE, TSDataType.DOUBLE);
assertEquals(roundWithGivenPrecision(a, 2), decoder.readDouble(buffer), delta);
assertEquals(roundWithGivenPrecision(b, 2), decoder.readDouble(buffer), delta);
}

// private void testDecimalLenght(TSEncoding encoding, List<Double> valueList,
Expand Down

0 comments on commit 3f5ece7

Please sign in to comment.