public static String randomString(Random random) { int length = randomLength(random); char[] chars = new char[length]; for (int i = 0; i < length; i++) chars[i] = (char)('a'+random.nextInt('z'-'a')); return new String(chars); }
public static ByteBuffer randomBytes(Random random) { byte[] bytes = new byte[randomLength(random)]; random.nextBytes(bytes); return ByteBuffer.wrap(bytes); }
@Test public void testInts() throws Exception { FILE.delete(); ColumnFileWriter out = new ColumnFileWriter(createFileMeta(), new ColumnMetaData("test", ValueType.INT)); Random random = TestUtil.createRandom(); for (int i = 0; i < COUNT; i++) out.writeRow(TestUtil.randomLength(random)); out.writeTo(FILE); random = TestUtil.createRandom(); ColumnFileReader in = new ColumnFileReader(FILE); Assert.assertEquals(COUNT, in.getRowCount()); Assert.assertEquals(1, in.getColumnCount()); Iterator<Integer> i = in.getValues("test"); int count = 0; while (i.hasNext()) { Assert.assertEquals(TestUtil.randomLength(random), (int)i.next()); count++; } Assert.assertEquals(COUNT, count); }
@Test public void testRandomLength() { long total = 0; int count = 1024 * 1024; int min = Short.MAX_VALUE; int max = 0; Random r = createRandom(); for (int i = 0; i < count; i++) { int length = randomLength(r); if (min > length) min = length; if (max < length) max = length; total += length; } Assert.assertEquals(0, min); Assert.assertTrue(max > 1024 * 32); float average = total / (float)count; Assert.assertTrue(average > 16.0f); Assert.assertTrue(average < 64.0f); }
public static String randomString(Random random) { int length = randomLength(random); char[] chars = new char[length]; for (int i = 0; i < length; i++) chars[i] = (char)('a'+random.nextInt('z'-'a')); return new String(chars); }
public static ByteBuffer randomBytes(Random random) { byte[] bytes = new byte[randomLength(random)]; random.nextBytes(bytes); return ByteBuffer.wrap(bytes); }
@Test public void testInts() throws Exception { FILE.delete(); ColumnFileWriter out = new ColumnFileWriter(createFileMeta(), new ColumnMetaData("test", ValueType.INT)); Random random = TestUtil.createRandom(); for (int i = 0; i < COUNT; i++) out.writeRow(TestUtil.randomLength(random)); out.writeTo(FILE); random = TestUtil.createRandom(); ColumnFileReader in = new ColumnFileReader(FILE); Assert.assertEquals(COUNT, in.getRowCount()); Assert.assertEquals(1, in.getColumnCount()); Iterator<Integer> i = in.getValues("test"); int count = 0; while (i.hasNext()) { Assert.assertEquals(TestUtil.randomLength(random), (int)i.next()); count++; } Assert.assertEquals(COUNT, count); }
@Test public void testRandomLength() { long total = 0; int count = 1024 * 1024; int min = Short.MAX_VALUE; int max = 0; Random r = createRandom(); for (int i = 0; i < count; i++) { int length = randomLength(r); if (min > length) min = length; if (max < length) max = length; total += length; } Assert.assertEquals(0, min); Assert.assertTrue(max > 1024 * 32); float average = total / (float)count; Assert.assertTrue(average > 16.0f); Assert.assertTrue(average < 64.0f); }