/* * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/* * @test * @bug 6359979 * @summary Compare List implementations for identical behavior * @author Martin Buchholz * @key randomness
*/
void lockSteps(List... lists) { for (int i = 0; i < lists.length; i++) if (maybe(4)) lists[i] = serialClone(lists[i]); for (final List list : lists)
testEmptyList(list); for (int i = 0; i < size; i++) {
ListFrobber adder = randomAdder(); for (final List list : lists) {
adder.frob(list);
equal(list.size(), i+1);
}
equalLists(lists);
}
{ final ListFrobber adder = randomAdder(); final ListFrobber remover = randomRemover(); for (final List list : lists) {
THROWS(ConcurrentModificationException.class, new F(){void f(){
Iterator it = list.iterator();
adder.frob(list);
it.next();}}, new F(){void f(){
Iterator it = asSubList(list).iterator();
remover.frob(list);
it.next();}}, new F(){void f(){
Iterator it = asSubList(asSubList(list)).iterator();
adder.frob(list);
it.next();}}, new F(){void f(){
List subList = asSubList(list);
remover.frob(list);
subList.get(0);}}, new F(){void f(){
List sl = asSubList(list);
List ssl = asSubList(sl);
adder.frob(sl);
ssl.get(0);}}, new F(){void f(){
List sl = asSubList(list);
List ssl = asSubList(sl);
remover.frob(sl);
ssl.get(0);}});
}
}
for (final List l : lists) { final List sl = asSubList(l); final List ssl = asSubList(sl);
ssl.add(0, 42);
equal(ssl.get(0), 42);
equal(sl.get(0), 42);
equal(l.get(0), 42); finalint s = l.size(); finalint rndIndex = rnd.nextInt(l.size()); THROWS(IndexOutOfBoundsException.class, new F(){void f(){l.subList(rndIndex, rndIndex).get(0);}}, new F(){void f(){l.subList(s/2, s).get(s/2 + 1);}}, new F(){void f(){l.subList(s/2, s).get(-1);}}
); THROWS(IllegalArgumentException.class, new F(){void f(){ l.subList(1, 0);}}, new F(){void f(){ sl.subList(1, 0);}}, new F(){void f(){ssl.subList(1, 0);}});
}
equalLists(lists);
for (final List list : lists) {
equalLists(list, asSubList(list));
equalLists(list, asSubList(asSubList(list)));
} for (final List list : lists)
System.out.println(list);
for (int i = lists[0].size(); i > 0; i--) {
ListFrobber remover = randomRemover(); for (final List list : lists)
remover.frob(list);
equalLists(lists);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.