mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Fix bug in ArrayDeque implementation
This commit is contained in:
parent
f4ec4872c5
commit
fa198244dd
|
@ -269,10 +269,10 @@ public class TArrayDeque<E> extends TAbstractCollection<E> implements TDeque<E>
|
||||||
for (int i = index + 1; i < tail; ++i) {
|
for (int i = index + 1; i < tail; ++i) {
|
||||||
array[i - 1] = array[i];
|
array[i - 1] = array[i];
|
||||||
}
|
}
|
||||||
array[--tail] = null;
|
if (--tail < 0) {
|
||||||
if (tail == 0) {
|
|
||||||
tail += array.length;
|
tail += array.length;
|
||||||
}
|
}
|
||||||
|
array[tail] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@ import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.teavm.junit.TeaVMTestRunner;
|
import org.teavm.junit.TeaVMTestRunner;
|
||||||
|
|
||||||
@RunWith(TeaVMTestRunner.class)
|
|
||||||
public class ArrayDequeTest {
|
public class ArrayDequeTest {
|
||||||
@Test
|
@Test
|
||||||
public void addsToFront() {
|
public void addsToFront() {
|
||||||
|
@ -132,7 +131,7 @@ public class ArrayDequeTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void eachRemovedObjectShouldReduceTheSizeByOne() {
|
public void eachRemovedObjectShouldReduceTheSizeByOne() {
|
||||||
TArrayDeque<Object> arrayDeque = new TArrayDeque<>();
|
ArrayDeque<Object> arrayDeque = new ArrayDeque<>();
|
||||||
Object object1 = new Object();
|
Object object1 = new Object();
|
||||||
Object object2 = new Object();
|
Object object2 = new Object();
|
||||||
Object object3 = new Object();
|
Object object3 = new Object();
|
||||||
|
@ -235,4 +234,23 @@ public class ArrayDequeTest {
|
||||||
Assert.assertTrue(arrayDeque4.size() == 1);
|
Assert.assertTrue(arrayDeque4.size() == 1);
|
||||||
Assert.assertTrue(arrayDeque4.contains(object1));
|
Assert.assertTrue(arrayDeque4.contains(object1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void removeElementInWrappedArray() {
|
||||||
|
TArrayDeque<Object> arrayDeque = new TArrayDeque<>(8);
|
||||||
|
for (int i = 0; i < 4; ++i) {
|
||||||
|
arrayDeque.addLast(0);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < 4; ++i) {
|
||||||
|
arrayDeque.removeFirst();
|
||||||
|
}
|
||||||
|
for (int i = 0; i < 6; ++i) {
|
||||||
|
arrayDeque.addLast(i);
|
||||||
|
}
|
||||||
|
for (int i = 5; i >= 0; --i) {
|
||||||
|
arrayDeque.remove(i);
|
||||||
|
arrayDeque.addLast(23);
|
||||||
|
arrayDeque.removeLast();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user