未验证 提交 0af05d53 编写于 作者: X Xiangdong Huang 提交者: GitHub

Fix float precision test in memtable (#90)

* fix float precision in PrimitiveMemTableTest
上级 90746f90
......@@ -25,14 +25,23 @@ import java.util.Random;
import org.apache.iotdb.db.utils.MathUtils;
import org.apache.iotdb.db.utils.TimeValuePair;
import org.apache.iotdb.db.utils.TsPrimitiveType;
import org.apache.iotdb.tsfile.common.conf.TSFileConfig;
import org.apache.iotdb.tsfile.exception.write.UnSupportedDataTypeException;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.utils.Binary;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class PrimitiveMemTableTest {
double delta;
@Before
public void setUp() {
delta = Math.pow(0.1, TSFileConfig.floatPrecision);
}
@Test
public void memSeriesCloneTest() {
TSDataType dataType = TSDataType.INT32;
......@@ -105,17 +114,26 @@ public class PrimitiveMemTableTest {
TimeValuePair next = tvPair.next();
Assert.assertEquals(pair.getTimestamp(), next.getTimestamp());
if (dataType == TSDataType.DOUBLE) {
Assert.assertEquals(MathUtils.roundWithGivenPrecision(pair.getValue().getDouble()),
next.getValue().getDouble(), 0.0001);
Assert.assertEquals(pair.getValue().getDouble(),
MathUtils.roundWithGivenPrecision(next.getValue().getDouble()), delta);
} else if (dataType == TSDataType.FLOAT) {
Assert.assertEquals(MathUtils.roundWithGivenPrecision(pair.getValue().getFloat()),
next.getValue().getFloat(), 0.0001);
float expected = pair.getValue().getFloat();
float actual = MathUtils.roundWithGivenPrecision(next.getValue().getFloat());
Assert.assertEquals(expected, actual, delta+ Float.MIN_NORMAL);
} else {
Assert.assertEquals(pair.getValue(), next.getValue());
}
}
}
@Test
public void testFloatType() {
IMemTable memTable = new PrimitiveMemTable();
String deviceId = "d1";
int size = 1000000;
write(memTable, deviceId, "s1", TSDataType.FLOAT, size);
}
@Test
public void testAllType() {
IMemTable memTable = new PrimitiveMemTable();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册