@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()); }
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; }
.withMaxRows(49) .withSortOrder(SortOrder.ASCENDING) .withStartDate(LocalDate.of(2010, 1, 1)) .withEndDate(LocalDate.of(2011, 1, 1)) .build(); .withMaxRows(49) .withSortOrder(SortOrder.ASCENDING) .withStartDate(LocalDate.of(2010, 1, 1)) .withEndDate(LocalDate.of(2011, 1, 1)) .build(); .withMaxRows(49) .withSortOrder(SortOrder.ASCENDING) .withStartDate(LocalDate.of(2010, 1, 1)) .withEndDate(LocalDate.of(2011, 1, 1)) .build(); .withMaxRows(49) .withSortOrder(SortOrder.ASCENDING) .withStartDate(LocalDate.of(2010, 1, 1)) .withEndDate(LocalDate.of(2011, 1, 1)) .build(); .withStartDate(LocalDate.of(2010, 1, 1)) .withEndDate(LocalDate.of(2011, 1, 1)) .build(); .withMaxRows(49)
.withMaxRows(49) .withSortOrder(SortOrder.ASCENDING) .withStartDate(LocalDate.of(2010, 1, 1)) .withEndDate(LocalDate.of(2011, 1, 1)) .build(); .withMaxRows(49) .withSortOrder(SortOrder.ASCENDING) .withStartDate(LocalDate.of(2010, 1, 1)) .withEndDate(LocalDate.of(2011, 1, 1)) .build(); .withMaxRows(49) .withSortOrder(SortOrder.ASCENDING) .withStartDate(LocalDate.of(2010, 1, 1)) .withEndDate(LocalDate.of(2011, 1, 1)) .build(); .withMaxRows(49) .withSortOrder(SortOrder.ASCENDING) .withStartDate(LocalDate.of(2010, 1, 1)) .withEndDate(LocalDate.of(2011, 1, 1)) .build(); .withStartDate(LocalDate.of(2010, 1, 1)) .withEndDate(LocalDate.of(2011, 1, 1)) .build(); .withMaxRows(49)
builder.withStartDate(request.getStartDate());
/** * The main body of the code. */ private void run() { ClassicQuandlSession session = ClassicQuandlSession.create(); TabularResult tabularResult = session.getDataSet( DataSetRequest.Builder .of("SSE/VROS") // VERIANOS REAL ESTATE AG on Boerse Stuttgart .withColumn(3) // Last (looked up previously) .withStartDate(RECENTISH_DATE) .withFrequency(Frequency.MONTHLY) .build()); System.out.println("Header definition: " + tabularResult.getHeaderDefinition()); for (final Row row : tabularResult) { LocalDate date = row.getLocalDate("Date"); Double value = row.getDouble("Last"); System.out.println("Value on date " + date + " was " + value); } }
@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 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() { 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); }
@Test(expectedExceptions = QuandlRuntimeException.class) public final void testDataSetRequestStartDate() { DataSetRequest.Builder.of("Hello").withStartDate(null).build(); }
@Test(expectedExceptions = QuandlRuntimeException.class) public final void testDataSetRequestStartDate() { DataSetRequest.Builder.of("Hello").withStartDate(null).build(); }
@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 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); }