@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--; } }
@Test @Category(CorrectnessTests.class) public void Foreach_ShouldEnumerate_CountElements() { LimitedMemoryCollection<String, Integer> collection = new LimitedMemoryCollection<>(4); String[] keys = {"A", "B", "C", "D"}; for (String key : keys) { collection.set(key, 1); } int count = 0; for (Pair<String, Integer> record : collection) { count++; } Assert.assertEquals(count, collection.getCount()); }
@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--; } }