⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tlist.java

📁 是一款用JAVA 编写的编译器 具有很强的编译功能
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright 2006 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, * CA 95054 USA or visit www.sun.com if you need additional information or * have any questions. *//* * @test * @bug 6267067 6351336 6389198 * @summary unit test for javac List */import java.util.*;import com.sun.tools.javac.util.List;public class TList {    public static void main(String[] args) {	new TList().run();    }    String[][] data = {	{ },	{ "1" },	{ "1", "2" },	{ "1", "2" }, // different but equal	{ "1", "2", "3", "4", "X", "X", "X", "8", "9", "10" } // contains duplicates    };    Map<java.util.List<String>,List<String>> examples;    void run() {	examples = new LinkedHashMap<java.util.List<String>,List<String>>();	for (String[] values: data) 	    examples.put(Arrays.asList(values), createList(values));	// 6351336: com.sun.tools.javac.util.List shouldn't extend java.util.AbstractList	test_AbstractList(); 	// general unit tests for java.util.List methods, including...	// 6389198: com.sun.tools.javac.util.List.equals() violates java.util.List.equals() contract	test_add_E();	test_add_int_E();	test_addAll_Collection();	test_addAll_int_Collection();	test_clear();	test_contains_Object();	test_contains_All();	test_equals_Object();	test_get_int();	test_hashCode();	test_indexOf_Object();	test_isEmpty();	test_iterator();	test_lastIndexOf_Object();	test_listIterator();	test_listIterator_int();	test_remove_int();	test_remove_Object();	test_removeAll_Collection();	test_retainAll_Collection();	test_set_int_E();	test_size();	test_subList_int_int();	test_toArray();	test_toArray_TArray();	// tests for additional methods	test_prependList_List();	test_reverse();    }    // 6351336    void test_AbstractList() {	System.err.println("test AbstractList");	if (AbstractList.class.isAssignableFrom(List.class))	    throw new AssertionError();    }    void test_add_E() {	System.err.println("test add(E)");	for (List<String> l: examples.values()) {	    try {		l.add("test");		throw new AssertionError();	    } catch (UnsupportedOperationException ex) {	    }	}    }    void test_add_int_E() {	System.err.println("test add(int,E)");	for (List<String> l: examples.values()) {	    try {		l.add(0, "test");		throw new AssertionError();	    } catch (UnsupportedOperationException ex) {	    }	}    }    void test_addAll_Collection() {	System.err.println("test addAll(Collection)");	for (List<String> l: examples.values()) {	    int l_size = l.size();	    for (java.util.List<String> arg: examples.keySet()) {		try {		    boolean modified = l.addAll(arg);		    if (modified)			throw new AssertionError();		} catch (UnsupportedOperationException e) {		}		if (l.size() != l_size)		    throw new AssertionError();	    }	}    }    void test_addAll_int_Collection() {	System.err.println("test addAll(int,Collection)");	for (List<String> l: examples.values()) {	    int l_size = l.size();	    for (java.util.List<String> arg: examples.keySet()) {		try {		    boolean modified = l.addAll(0, arg);		    if (modified)			throw new AssertionError();		} catch (UnsupportedOperationException e) {		}		if (l.size() != l_size)		    throw new AssertionError();	    }	}    }    void test_clear() {	System.err.println("test clear()");	for (List<String> l: examples.values()) {	    int l_size = l.size();	    try {		l.clear();		if (l_size > 0)		    throw new AssertionError();	    } catch (UnsupportedOperationException e) {	    }	    if (l.size() != l_size)		throw new AssertionError();	}    }    void test_contains_Object() {	System.err.println("test contains(Object)");	for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) {	    java.util.List<String> ref = e.getKey();	    List<String> l = e.getValue();	    boolean expect = ref.contains("1");	    boolean found = l.contains("1");	    if (expect != found)		throw new AssertionError();	}    }    void test_contains_All() {	System.err.println("test containsAll()");	for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) {	    java.util.List<String> ref = e.getKey();	    List<String> l = e.getValue();	    for (java.util.List<String> arg: examples.keySet()) {		boolean expect = ref.containsAll(arg);		boolean found = l.containsAll(arg);		if (expect != found)		    throw new AssertionError();	    }	}    }    // 6389198    void test_equals_Object() {	System.err.println("test equals(Object)");	for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) {	    java.util.List<String> ref = e.getKey();	    List<String> l = e.getValue();	    for (java.util.List<String> arg: examples.keySet()) {		boolean expect = ref.equals(arg);		boolean found = l.equals(arg);		if (expect != found) {		    System.err.println("ref: " + ref);		    System.err.println("l: " + l);		    System.err.println("arg: " + arg);		    System.err.println("expect: " + expect + ", found: " + found);		    throw new AssertionError();		}	    }	}    }    void test_get_int() {	System.err.println("test get(int)");	for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) {	    java.util.List<String> ref = e.getKey();	    List<String> l = e.getValue();	    for (int i = -1; i <= ref.size(); i++) {		boolean expectException = i < 0 || i >= ref.size();		String expectValue = (expectException ? null : ref.get(i));		try {		    String foundValue = l.get(i);		    if (expectException || !equal(expectValue, foundValue))			throw new AssertionError();		} catch (IndexOutOfBoundsException ex) {		    if (!expectException)			throw new AssertionError();		}	    }	}    }    void test_hashCode() {	System.err.println("test hashCode()");	for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) {	    java.util.List<String> ref = e.getKey();	    List<String> l = e.getValue();	    long expect = ref.hashCode();	    long found = l.hashCode();	    if (expect != found) {		System.err.println("ref: " + ref);		System.err.println("l: " + l);		System.err.println("expect: " + expect);		System.err.println("found: " + found);		throw new AssertionError();	    }	}    }    void test_indexOf_Object() {	System.err.println("test indexOf(Object)");	for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) {	    java.util.List<String> ref = e.getKey();	    List<String> l = e.getValue();	    for (int i = -1; i < ref.size(); i++) {		String arg = (i == -1 ? "NOT IN LIST" : ref.get(i));		int expect = ref.indexOf(arg);		int found = l.indexOf(arg);		if (expect != found) 		    throw new AssertionError();	    }	}    }    void test_isEmpty() {	System.err.println("test isEmpty()");	for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) {	    java.util.List<String> ref = e.getKey();	    List<String> l = e.getValue();	    boolean expect = ref.isEmpty();	    boolean found = l.isEmpty();	    if (expect != found)		throw new AssertionError();	}    }    void test_iterator() {	System.err.println("test iterator()");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -