private DataSetRequest.Builder fuzz(final DataSetRequest.Builder reqBuilder) { DataSetRequest.Builder builder = reqBuilder; if (_random.nextDouble() > WITH_COLUMN_PROBABILITY) { builder = builder.withColumn((int) (_random.nextDouble() * MAX_COLUMN)); } if (_random.nextDouble() > WITH_FREQUENCY_PROBABILITY) { builder = builder.withFrequency(Frequency.values()[_random.nextInt(Frequency.values().length)]); } if (_random.nextDouble() > WITH_TRANSFORM_PROBABILITY) { builder = builder.withTransform(Transform.values()[_random.nextInt(Transform.values().length)]); } if (_random.nextDouble() > WITH_MAX_ROWS_PROBABILITY) { builder = builder.withMaxRows(_random.nextInt(MAX_ROWS)); } LocalDate startDate = LocalDate.ofEpochDay((int) ((_random.nextDouble() * DAYS_PER_YEAR) * MAX_YEARS_OUT) + (BASE_YEARS_FROM_EPOCH * DAYS_PER_YEAR)); if (_random.nextDouble() > WITH_START_DATE_PROBABILITY) { builder = builder.withStartDate(startDate); } if (_random.nextDouble() > WITH_END_DATE_PROBABILITY) { builder = builder.withEndDate(startDate.plusDays(_random.nextInt(DAYS_PER_YEAR * MAX_PLUS_YEARS))); } return builder; }
private DataSetRequest.Builder fuzz(final DataSetRequest.Builder reqBuilder) { DataSetRequest.Builder builder = reqBuilder; if (_random.nextDouble() > WITH_COLUMN_PROBABILITY) { builder = builder.withColumn((int) (_random.nextDouble() * MAX_COLUMN)); } if (_random.nextDouble() > WITH_FREQUENCY_PROBABILITY) { builder = builder.withFrequency(Frequency.values()[_random.nextInt(Frequency.values().length)]); } if (_random.nextDouble() > WITH_TRANSFORM_PROBABILITY) { builder = builder.withTransform(Transform.values()[_random.nextInt(Transform.values().length)]); } if (_random.nextDouble() > WITH_MAX_ROWS_PROBABILITY) { builder = builder.withMaxRows(_random.nextInt(MAX_ROWS)); } LocalDate startDate = LocalDate.ofEpochDay((int) ((_random.nextDouble() * DAYS_PER_YEAR) * MAX_YEARS_OUT) + (BASE_YEARS_FROM_EPOCH * DAYS_PER_YEAR)); if (_random.nextDouble() > WITH_START_DATE_PROBABILITY) { builder = builder.withStartDate(startDate); } if (_random.nextDouble() > WITH_END_DATE_PROBABILITY) { builder = builder.withEndDate(startDate.plusDays(_random.nextInt(DAYS_PER_YEAR * MAX_PLUS_YEARS))); } return builder; }
@Test public final void testComplexDataSetRequestEqualsAndHashCodeAgainstStringAndObject() { // Note that the tests on hashCode here are beyond the contract requirements of hashCode, we're saying they must differ if the object differs, which is // generally good, but not required. DataSetRequest request1 = DataSetRequest.Builder .of("CODE/CODE") .withColumn(3) .withFrequency(Frequency.NONE) .withMaxRows(49) .withSortOrder(SortOrder.ASCENDING) .withStartDate(LocalDate.of(2010, 1, 1)) .withEndDate(LocalDate.of(2011, 1, 1)) .build(); Assert.assertNotEquals(request1, "Hello"); Assert.assertNotEquals(request1, new Object()); }
.withColumn(3) .withFrequency(Frequency.NONE) .withMaxRows(49) .withSortOrder(SortOrder.ASCENDING) .withStartDate(LocalDate.of(2010, 1, 1)) .withColumn(3) .withFrequency(Frequency.NONE) .withMaxRows(49) .withSortOrder(SortOrder.ASCENDING) .withStartDate(LocalDate.of(2010, 1, 1)) .withColumn(0) .withFrequency(Frequency.NONE) .withMaxRows(49) .withSortOrder(SortOrder.ASCENDING) .withStartDate(LocalDate.of(2010, 1, 1)) .of("CODE/CODE") // no withColumn .withFrequency(Frequency.NONE) .withMaxRows(49) .withSortOrder(SortOrder.ASCENDING) .withStartDate(LocalDate.of(2010, 1, 1)) .withMaxRows(49) .withSortOrder(SortOrder.ASCENDING) .withStartDate(LocalDate.of(2010, 1, 1)) .of("CODE/CODE")
.withColumn(3) .withFrequency(Frequency.NONE) .withMaxRows(49) .withSortOrder(SortOrder.ASCENDING) .withStartDate(LocalDate.of(2010, 1, 1)) .withColumn(3) .withFrequency(Frequency.NONE) .withMaxRows(49) .withSortOrder(SortOrder.ASCENDING) .withStartDate(LocalDate.of(2010, 1, 1)) .withColumn(0) .withFrequency(Frequency.NONE) .withMaxRows(49) .withSortOrder(SortOrder.ASCENDING) .withStartDate(LocalDate.of(2010, 1, 1)) .of("CODE/CODE") // no withColumn .withFrequency(Frequency.NONE) .withMaxRows(49) .withSortOrder(SortOrder.ASCENDING) .withStartDate(LocalDate.of(2010, 1, 1)) .withMaxRows(49) .withSortOrder(SortOrder.ASCENDING) .withStartDate(LocalDate.of(2010, 1, 1)) .of("CODE/CODE")
builder.withMaxRows(request.getMaxRows());
@Test public final void testComplexDataSetRequestEqualsAndHashCodeAgainstStringAndObject() { // Note that the tests on hashCode here are beyond the contract requirements of hashCode, we're saying they must differ if the object differs, which is // generally good, but not required. DataSetRequest request1 = DataSetRequest.Builder .of("CODE/CODE") .withColumn(3) .withFrequency(Frequency.NONE) .withMaxRows(49) .withSortOrder(SortOrder.ASCENDING) .withStartDate(LocalDate.of(2010, 1, 1)) .withEndDate(LocalDate.of(2011, 1, 1)) .build(); Assert.assertNotEquals(request1, "Hello"); Assert.assertNotEquals(request1, new Object()); }
@Test public void testMostComplexGetDataSetDifferentOrder() { // now try a different order QuandlSession session = getTestSession("https://www.quandl.com/api/v3/datasets/WIKI/AAPL.csv?start_date=2009-01-01&end_date=2010-12-31&column_index=4&collapse=quarterly&limit=10&transform=normalize"); TabularResult tabularResult = session.getDataSet(DataSetRequest.Builder.of("WIKI/AAPL") .withFrequency(Frequency.QUARTERLY) .withColumn(CLOSE_COLUMN) .withStartDate(LocalDate.of(2009, 1, 1)) .withEndDate(LocalDate.of(2010, 12, 31)) .withMaxRows(10) .withTransform(Transform.NORMALIZE) .build()); Assert.assertEquals(TEST_TABULAR_RESULT, tabularResult); }
@Test public void testMostComplexGetDataSetDifferentOrder() { // now try a different order ClassicQuandlSessionInterface session = getTestSession("https://www.quandl.com/api/v3/datasets/WIKI/AAPL.csv?start_date=2009-01-01&end_date=2010-12-31&column_index=4&collapse=quarterly&limit=10&transform=normalize"); TabularResult tabularResult = session.getDataSet(DataSetRequest.Builder.of("WIKI/AAPL") .withFrequency(Frequency.QUARTERLY) .withColumn(CLOSE_COLUMN) .withStartDate(LocalDate.of(2009, 1, 1)) .withEndDate(LocalDate.of(2010, 12, 31)) .withMaxRows(10) .withTransform(Transform.NORMALIZE) .build()); Assert.assertEquals(TEST_TABULAR_RESULT, tabularResult); }
@Test public void testMostComplexGetDataSet() { QuandlSession session = getTestSession("https://www.quandl.com/api/v3/datasets/WIKI/AAPL.csv?start_date=2009-01-01&end_date=2010-12-31&column_index=4&collapse=quarterly&limit=10&transform=normalize"); TabularResult tabularResult = session.getDataSet(DataSetRequest.Builder.of("WIKI/AAPL") .withStartDate(LocalDate.of(2009, 1, 1)) .withEndDate(LocalDate.of(2010, 12, 31)) .withMaxRows(10) .withFrequency(Frequency.QUARTERLY) .withColumn(CLOSE_COLUMN) .withTransform(Transform.NORMALIZE) .build()); Assert.assertEquals(TEST_TABULAR_RESULT, tabularResult); }
@Test public void testMostComplexGetDataSet() { ClassicQuandlSessionInterface session = getTestSession("https://www.quandl.com/api/v3/datasets/WIKI/AAPL.csv?start_date=2009-01-01&end_date=2010-12-31&column_index=4&collapse=quarterly&limit=10&transform=normalize"); TabularResult tabularResult = session.getDataSet(DataSetRequest.Builder.of("WIKI/AAPL") .withStartDate(LocalDate.of(2009, 1, 1)) .withEndDate(LocalDate.of(2010, 12, 31)) .withMaxRows(10) .withFrequency(Frequency.QUARTERLY) .withColumn(CLOSE_COLUMN) .withTransform(Transform.NORMALIZE) .build()); Assert.assertEquals(TEST_TABULAR_RESULT, tabularResult); }
/** * The main body of the code. */ private void run() { TableSawQuandlSession session = TableSawQuandlSession.create(); Table table = session.getDataSet( DataSetRequest.Builder.of("WIKI/AAPL").withMaxRows(10).build()); System.out.println(table); }
/** * The main body of the code. */ private void run() { ClassicQuandlSession session = ClassicQuandlSession.create(); TabularResult tabularResult = session.getDataSet( DataSetRequest.Builder.of("WIKI/AAPL").withMaxRows(10).build()); System.out.println(tabularResult.toPrettyPrintedString()); }