コード例 #1
0
  /**
   * check that the cache is immutable by changing the data passed in the constructor and returned
   * from methods.
   *
   * @throws TimeStampedCacheException
   */
  @Test
  public void testImmutable() throws TimeStampedCacheException {
    // setup
    List<AbsoluteDate> actuals;
    List<AbsoluteDate> expecteds = new ArrayList<AbsoluteDate>(data);
    AbsoluteDate different = date.shiftedBy(-50);

    // actions + verify

    // check constructor
    data.set(0, different);
    Assert.assertArrayEquals(cache.getAll().toArray(), expecteds.toArray());

    // check getAll
    actuals = cache.getAll();
    try {
      actuals.set(0, different);
    } catch (UnsupportedOperationException e) {
      // exception ok
    }
    Assert.assertArrayEquals(cache.getAll().toArray(), expecteds.toArray());

    // check getNeighbors
    actuals = cache.getNeighbors(date);
    try {
      actuals.set(0, different);
    } catch (UnsupportedOperationException e) {
      // exception ok
    }
    Assert.assertArrayEquals(cache.getAll().toArray(), expecteds.toArray());
  }
コード例 #2
0
  /** check {@link ImmutableTimeStampedCache#emptyCache()}. */
  @Test
  public void testEmptyCache() {
    // setup
    cache = ImmutableTimeStampedCache.emptyCache();

    // actions + verify
    try {
      cache.getNeighbors(date);
      Assert.fail("Expected Exception");
    } catch (TimeStampedCacheException e) {
      // expected
    }
    try {
      cache.getEarliest();
      Assert.fail("Expected Exception");
    } catch (IllegalStateException e) {
      // expected
    }
    try {
      cache.getLatest();
      Assert.fail("Expected Exception");
    } catch (IllegalStateException e) {
      // expected
    }
    Assert.assertEquals(cache.getAll().size(), 0);
    Assert.assertEquals(cache.getNeighborsSize(), 0);
  }
コード例 #3
0
  /**
   * check {@link ImmutableTimeStampedCache#getNeighbors(AbsoluteDate)} at a series of different
   * dates designed to test all logic paths.
   *
   * @throws TimeStampedCacheException
   */
  @Test
  public void testGetNeighbors() throws TimeStampedCacheException {
    // setup
    int size = data.size();

    // actions + verify

    // before fist data
    try {
      cache.getNeighbors(data.get(0).shiftedBy(-1));
      Assert.fail("Expected Exception");
    } catch (TimeStampedCacheException e) {
      // expected
    }

    // on fist date
    Assert.assertArrayEquals(
        cache.getNeighbors(data.get(0)).toArray(), data.subList(0, 3).toArray());
    // between fist and second date
    Assert.assertArrayEquals(
        cache.getNeighbors(data.get(0).shiftedBy(0.5)).toArray(), data.subList(0, 3).toArray());
    // in the middle on a date
    Assert.assertArrayEquals(
        cache.getNeighbors(data.get(2)).toArray(), data.subList(1, 4).toArray());
    // in the middle between dates
    Assert.assertArrayEquals(
        cache.getNeighbors(data.get(2).shiftedBy(0.5)).toArray(), data.subList(1, 4).toArray());
    // just before last date
    Assert.assertArrayEquals(
        cache.getNeighbors(data.get(size - 1).shiftedBy(-0.5)).toArray(),
        data.subList(size - 3, size).toArray());
    // on last date
    Assert.assertArrayEquals(
        cache.getNeighbors(data.get(size - 1)).toArray(), data.subList(size - 3, size).toArray());

    // after last date
    try {
      cache.getNeighbors(data.get(size - 1).shiftedBy(1));
      Assert.fail("Expected Exception");
    } catch (TimeStampedCacheException e) {
      // expected
    }
  }
コード例 #4
0
 /** check {@link ImmutableTimeStampedCache#getAll()} */
 @Test
 public void testGetAll() {
   Assert.assertArrayEquals(cache.getAll().toArray(), data.toArray());
 }
コード例 #5
0
 /** check {@link ImmutableTimeStampedCache#getLatest()} */
 @Test
 public void testGetLatest() {
   Assert.assertEquals(cache.getLatest(), data.get(data.size() - 1));
 }
コード例 #6
0
 /** check {@link ImmutableTimeStampedCache#getEarliest()} */
 @Test
 public void testGetEarliest() {
   Assert.assertEquals(cache.getEarliest(), data.get(0));
 }
コード例 #7
0
 /** check {@link ImmutableTimeStampedCache#getNeighborsSize()} */
 @Test
 public void testGetNeighborsSize() {
   Assert.assertEquals(cache.getNeighborsSize(), 3);
 }