Example #1
0
  @Test
  @Category(CorrectnessTests.class)
  public void Foreach_ShouldReturn_InOrder_MostRecentlyRequested() {
    LimitedMemoryCollection<Character, Integer> collection = new LimitedMemoryCollection<>(4);
    Character[] keys = {'A', 'B', 'C', 'D'};

    for (Character key : keys) {
      collection.set(key, key + 1);
    }

    int order = collection.getCount() - 1;
    for (Pair<Character, Integer> record : collection) {
      Assert.assertEquals(record.getKey(), keys[order]);
      Assert.assertEquals((long) record.getValue(), keys[order] + 1);
      order--;
    }
  }
Example #2
0
  @Test
  @Category(CorrectnessTests.class)
  public void Foreach_Should_Return_InOrder_MostRecentlyRequested_4() {
    LimitedMemoryCollection<Character, Integer> collection = new LimitedMemoryCollection<>(4);
    Character[] keys = {'A', 'B', 'C', 'D'};

    for (Character key : keys) {
      collection.set(key, key + 1);
    }

    collection.set(keys[1], 5);
    Character[] expectedOrder = {keys[0], keys[2], keys[3], keys[1]};

    int order = collection.getCount() - 1;
    for (Pair<Character, Integer> record : collection) {
      Assert.assertEquals(record.getKey(), expectedOrder[order]);
      order--;
    }
  }