/*
 * #%L
 * SciJava Common shared library for SciJava software.
 * %%
 * Copyright (C) 2009 - 2014 Board of Regents of the University of
 * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck
 * Institute of Molecular Cell Biology and Genetics.
 * %%
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 * #L%
 */

package org.scijava.util;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

/**
 * Tests the {@link LastRecentlyUsed} data structure.
 * 
 * @author Johannes Schindelin
 */
public class LastRecentlyUsedTest {

	@Test
	public void test() {
		int count = 3;
		final LastRecentlyUsed<String> lru = new LastRecentlyUsed<String>(count);

		for (int i = 1; i <= count; i++) {
			lru.add("" + i);
		}

		int position = -1;
		for (int i = 1; i <= count; i++) {
			position = lru.next(position);
			assertEquals("" + i, lru.get(position));
		}
		position = lru.next(position);
		assertEquals(-1, position);

		for (int i = count; i >= 1; i--) {
			position = lru.previous(position);
			assertEquals("" + i, lru.get(position));
		}
		position = lru.previous(position);
		assertEquals(-1, position);
	}
}

@@ -1651,16 +1651,88 @@
 tEquals;
+%0Aimport static org.junit.Assert.assertFalse;%0A%0Aimport java.util.Iterator;
 %0A%0Aimport
@@ -2464,11 +2464,631 @@
 ion);%0A%09%7D
+%0A%0A%09@Test%0A%09public void testRemove() %7B%0A%09%09final LastRecentlyUsed%3CString%3E lru = new LastRecentlyUsed%3CString%3E(3);%0A%09%09lru.add(%22a%22);%0A%09%09lru.add(%22b%22);%0A%09%09lru.add(%22c%22);%0A%0A%09%09lru.remove(%22b%22);%0A%0A%09%09Iterator%3CString%3E iter = lru.iterator();%0A%09%09assertEquals(%22c%22, iter.next());%0A%09%09assertEquals(%22a%22, iter.next());%0A%09%09assertFalse(iter.hasNext());%0A%0A%09%09lru.remove(%22a%22);%0A%0A%09%09iter = lru.iterator();%0A%09%09assertEquals(%22c%22, iter.next());%0A%09%09assertFalse(iter.hasNext());%0A%0A%09%09lru.remove(%22a%22);%0A%0A%09%09iter = lru.iterator();%0A%09%09assertEquals(%22c%22, iter.next());%0A%09%09assertFalse(iter.hasNext());%0A%0A%09%09lru.remove(%22c%22);%0A%0A%09%09iter = lru.iterator();%0A%09%09assertFalse(iter.hasNext());%0A%09%7D
 %0A%7D%0A

Test LastRecentlyUsed#remove(Object)