use of io.questdb.std.str.StringSink in project questdb by bluestreak01.
the class GeoHashesTest method testLatLon.
@Test
public void testLatLon() throws NumericException {
String expected = "24 -> s\n" + "789 -> sp\n" + "25248 -> sp0\n" + "807941 -> sp05\n" + "25854114 -> sp052\n" + "827331676 -> sp052w\n" + "26474613641 -> sp052w9\n" + "847187636514 -> sp052w92\n" + "27110004368469 -> sp052w92p\n" + "867520139791009 -> sp052w92p1\n" + "27760644473312309 -> sp052w92p1p\n" + "888340623145993896 -> sp052w92p1p8\n";
final int maxGeoHashSizeChars = 12;
String[] expectedStr = new String[maxGeoHashSizeChars];
long[] expectedHash = new long[maxGeoHashSizeChars];
StringSink everything = new StringSink();
StringSink sink = Misc.getThreadLocalBuilder();
for (int precision = 1; precision <= maxGeoHashSizeChars; precision++) {
int numBits = precision * 5;
long hash = GeoHashes.fromCoordinatesDeg(39.982, 0.024, numBits);
sink.clear();
GeoHashes.appendChars(hash, precision, sink);
expectedStr[precision - 1] = sink.toString();
expectedHash[precision - 1] = hash;
everything.put(expectedHash[precision - 1]).put(" -> ").put(expectedStr[precision - 1]).put('\n');
}
for (int i = 0; i < maxGeoHashSizeChars; i++) {
final long gh = GeoHashes.fromString(expectedStr[i], 0, expectedStr[i].length());
Assert.assertEquals(expectedHash[i], gh);
sink.clear();
GeoHashes.appendChars(gh, expectedStr[i].length(), sink);
Assert.assertEquals(expectedStr[i], sink.toString());
}
Assert.assertEquals(expected, everything.toString());
}
use of io.questdb.std.str.StringSink in project questdb by bluestreak01.
the class GeoHashesTest method testFromStringIgnoreQuotesTruncateChars.
@Test
public void testFromStringIgnoreQuotesTruncateChars() throws NumericException {
Assert.assertEquals(807941, GeoHashes.fromString("'sp052w92p1p'", 1, 5));
StringSink sink = Misc.getThreadLocalBuilder();
GeoHashes.appendChars(807941, 4, sink);
Assert.assertEquals("sp05", sink.toString());
}
use of io.questdb.std.str.StringSink in project questdb by bluestreak01.
the class GeoHashesTest method testToStringInvalidSizeInChars.
@Test
public void testToStringInvalidSizeInChars() {
boolean assertsEnabled = false;
// Test only when assertions enabled
assert assertsEnabled = true;
if (assertsEnabled) {
StringSink sink = Misc.getThreadLocalBuilder();
Assert.assertThrows(AssertionError.class, () -> GeoHashes.appendChars(-0, 0, sink));
Assert.assertThrows(AssertionError.class, () -> GeoHashes.appendChars(-0, 31, sink));
}
}
use of io.questdb.std.str.StringSink in project questdb by bluestreak01.
the class TableReaderTest method testReadLong256One.
@Test
public void testReadLong256One() {
try (TableModel model = new TableModel(configuration, "w", PartitionBy.DAY).col("l", ColumnType.LONG256).timestamp()) {
CairoTestUtils.create(model);
}
final int N = 1_000_000;
final Rnd rnd = new Rnd();
long timestamp = 0;
try (TableWriter writer = new TableWriter(configuration, "w")) {
for (int i = 0; i < N; i++) {
TableWriter.Row row = writer.newRow(timestamp);
row.putLong256(0, "0x" + padHexLong(rnd.nextLong()));
row.append();
}
writer.commit();
}
rnd.reset();
final StringSink sink = new StringSink();
try (TableReader reader = new TableReader(configuration, "w")) {
final RecordCursor cursor = reader.getCursor();
final Record record = cursor.getRecord();
int count = 0;
while (cursor.hasNext()) {
sink.clear();
record.getLong256(0, sink);
TestUtils.assertEquals("0x" + padHexLong(rnd.nextLong()), sink);
count++;
}
Assert.assertEquals(N, count);
}
}
use of io.questdb.std.str.StringSink in project questdb by bluestreak01.
the class GeoHashesTest method testFromStringTruncatingNlIgnoreQuotesTruncateBits1.
@Test
public void testFromStringTruncatingNlIgnoreQuotesTruncateBits1() throws NumericException {
Assert.assertEquals(807941, GeoHashes.fromStringTruncatingNl("'sp052w92p1p'", 1, 11, 20));
StringSink sink = Misc.getThreadLocalBuilder();
GeoHashes.appendChars(807941, 4, sink);
Assert.assertEquals("sp05", sink.toString());
}
Aggregations