mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Removed unused imports.
This commit is contained in:
parent
617c5a8476
commit
c847fa362e
1 changed files with 50 additions and 65 deletions
|
@ -10,9 +10,7 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.core.parser.tests.ast2;
|
package org.eclipse.cdt.core.parser.tests.ast2;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
@ -21,7 +19,7 @@ import org.eclipse.cdt.core.parser.util.CharArrayMap;
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Mike Kucera
|
* @author Mike Kucera
|
||||||
*/
|
*/
|
||||||
public class CharArrayMapTest extends TestCase {
|
public class CharArrayMapTest extends TestCase {
|
||||||
|
@ -39,9 +37,7 @@ public class CharArrayMapTest extends TestCase {
|
||||||
return new String(chars, start, length);
|
return new String(chars, start, length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void disabled_testPerformance() {
|
public void disabled_testPerformance() {
|
||||||
final int iterations = 10000;
|
final int iterations = 10000;
|
||||||
// insert tons of keys
|
// insert tons of keys
|
||||||
|
@ -49,10 +45,10 @@ public class CharArrayMapTest extends TestCase {
|
||||||
for(int i = 0; i < keys.length; i++) {
|
for(int i = 0; i < keys.length; i++) {
|
||||||
keys[i] = String.valueOf(i).toCharArray();
|
keys[i] = String.valueOf(i).toCharArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
System.gc();
|
System.gc();
|
||||||
long mapTime = timeMap(keys);
|
long mapTime = timeMap(keys);
|
||||||
|
|
||||||
System.gc();
|
System.gc();
|
||||||
long oldMapTime = timeOldMap(keys);
|
long oldMapTime = timeOldMap(keys);
|
||||||
|
|
||||||
|
@ -60,8 +56,7 @@ public class CharArrayMapTest extends TestCase {
|
||||||
System.out.println("oldMapTime: " + oldMapTime);
|
System.out.println("oldMapTime: " + oldMapTime);
|
||||||
assertTrue(oldMapTime > mapTime);
|
assertTrue(oldMapTime > mapTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static long timeMap(char[][] keys) {
|
private static long timeMap(char[][] keys) {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
CharArrayMap<Integer> map = new CharArrayMap<Integer>(keys.length);
|
CharArrayMap<Integer> map = new CharArrayMap<Integer>(keys.length);
|
||||||
|
@ -74,8 +69,7 @@ public class CharArrayMapTest extends TestCase {
|
||||||
}
|
}
|
||||||
return System.currentTimeMillis() - start;
|
return System.currentTimeMillis() - start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static long timeOldMap(char[][] keys) {
|
private static long timeOldMap(char[][] keys) {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
CharArrayObjectMap oldMap = new CharArrayObjectMap(keys.length);
|
CharArrayObjectMap oldMap = new CharArrayObjectMap(keys.length);
|
||||||
|
@ -88,51 +82,50 @@ public class CharArrayMapTest extends TestCase {
|
||||||
}
|
}
|
||||||
return System.currentTimeMillis() - start;
|
return System.currentTimeMillis() - start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testBasicUsage1() {
|
public void testBasicUsage1() {
|
||||||
char[] key1 = "first key".toCharArray();
|
char[] key1 = "first key".toCharArray();
|
||||||
char[] key2 = "second key".toCharArray();
|
char[] key2 = "second key".toCharArray();
|
||||||
char[] key3 = "third key".toCharArray();
|
char[] key3 = "third key".toCharArray();
|
||||||
char[] key4 = "forth key".toCharArray();
|
char[] key4 = "forth key".toCharArray();
|
||||||
|
|
||||||
CharArrayMap<Integer> map = new CharArrayMap<Integer>();
|
CharArrayMap<Integer> map = new CharArrayMap<Integer>();
|
||||||
assertTrue(map.isEmpty());
|
assertTrue(map.isEmpty());
|
||||||
assertEquals(0, map.size());
|
assertEquals(0, map.size());
|
||||||
|
|
||||||
map.put(key1, 1);
|
map.put(key1, 1);
|
||||||
map.put(key2, 2);
|
map.put(key2, 2);
|
||||||
map.put(key3, 3);
|
map.put(key3, 3);
|
||||||
map.put(key4, 4);
|
map.put(key4, 4);
|
||||||
|
|
||||||
assertFalse(map.isEmpty());
|
assertFalse(map.isEmpty());
|
||||||
assertEquals(4, map.size());
|
assertEquals(4, map.size());
|
||||||
|
|
||||||
assertEquals(new Integer(1), map.get(key1));
|
assertEquals(new Integer(1), map.get(key1));
|
||||||
assertEquals(new Integer(2), map.get(key2));
|
assertEquals(new Integer(2), map.get(key2));
|
||||||
assertEquals(new Integer(3), map.get(key3));
|
assertEquals(new Integer(3), map.get(key3));
|
||||||
assertEquals(new Integer(4), map.get(key4));
|
assertEquals(new Integer(4), map.get(key4));
|
||||||
|
|
||||||
assertTrue(map.containsKey(key1));
|
assertTrue(map.containsKey(key1));
|
||||||
assertTrue(map.containsKey(key2));
|
assertTrue(map.containsKey(key2));
|
||||||
assertTrue(map.containsKey(key3));
|
assertTrue(map.containsKey(key3));
|
||||||
assertTrue(map.containsKey(key4));
|
assertTrue(map.containsKey(key4));
|
||||||
|
|
||||||
assertTrue(map.containsValue(1));
|
assertTrue(map.containsValue(1));
|
||||||
assertTrue(map.containsValue(2));
|
assertTrue(map.containsValue(2));
|
||||||
assertTrue(map.containsValue(3));
|
assertTrue(map.containsValue(3));
|
||||||
assertTrue(map.containsValue(4));
|
assertTrue(map.containsValue(4));
|
||||||
|
|
||||||
Set<Integer> values = new HashSet<Integer>();
|
Set<Integer> values = new HashSet<Integer>();
|
||||||
values.add(1);
|
values.add(1);
|
||||||
values.add(2);
|
values.add(2);
|
||||||
values.add(3);
|
values.add(3);
|
||||||
values.add(4);
|
values.add(4);
|
||||||
|
|
||||||
for(int i : map.values()) {
|
for(int i : map.values()) {
|
||||||
assertTrue(values.remove(i));
|
assertTrue(values.remove(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove a mapping
|
// remove a mapping
|
||||||
assertEquals(new Integer(1), map.remove(key1));
|
assertEquals(new Integer(1), map.remove(key1));
|
||||||
assertEquals(3, map.size());
|
assertEquals(3, map.size());
|
||||||
|
@ -140,18 +133,18 @@ public class CharArrayMapTest extends TestCase {
|
||||||
assertFalse(map.containsKey(key1));
|
assertFalse(map.containsKey(key1));
|
||||||
assertFalse(map.containsValue(1));
|
assertFalse(map.containsValue(1));
|
||||||
assertNull(map.remove(key1)); // its already removed
|
assertNull(map.remove(key1)); // its already removed
|
||||||
|
|
||||||
map.clear();
|
map.clear();
|
||||||
assertTrue(map.isEmpty());
|
assertTrue(map.isEmpty());
|
||||||
assertEquals(0, map.size());
|
assertEquals(0, map.size());
|
||||||
|
|
||||||
// test null values
|
// test null values
|
||||||
map.put(key1, null);
|
map.put(key1, null);
|
||||||
assertEquals(1, map.size());
|
assertEquals(1, map.size());
|
||||||
assertNull(map.get(key1));
|
assertNull(map.get(key1));
|
||||||
assertTrue(map.containsKey(key1));
|
assertTrue(map.containsKey(key1));
|
||||||
assertTrue(map.containsValue(null));
|
assertTrue(map.containsValue(null));
|
||||||
|
|
||||||
// overrideing values should
|
// overrideing values should
|
||||||
map.put(key1, 100);
|
map.put(key1, 100);
|
||||||
assertEquals(1, map.size());
|
assertEquals(1, map.size());
|
||||||
|
@ -165,11 +158,10 @@ public class CharArrayMapTest extends TestCase {
|
||||||
assertTrue(map.containsValue(200));
|
assertTrue(map.containsValue(200));
|
||||||
assertFalse(map.containsValue(100));
|
assertFalse(map.containsValue(100));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testBasicUsage2() {
|
public void testBasicUsage2() {
|
||||||
char[] chars = "pantera, megadeth, soulfly, metallica, in flames, lamb of god, carcass".toCharArray();
|
char[] chars = "pantera, megadeth, soulfly, metallica, in flames, lamb of god, carcass".toCharArray();
|
||||||
|
|
||||||
Slice[] slices = new Slice[7];
|
Slice[] slices = new Slice[7];
|
||||||
slices[0] = new Slice(chars, 0, 7);
|
slices[0] = new Slice(chars, 0, 7);
|
||||||
slices[1] = new Slice(chars, 9, 8);
|
slices[1] = new Slice(chars, 9, 8);
|
||||||
|
@ -178,7 +170,7 @@ public class CharArrayMapTest extends TestCase {
|
||||||
slices[4] = new Slice(chars, 39, 9);
|
slices[4] = new Slice(chars, 39, 9);
|
||||||
slices[5] = new Slice(chars, 50, 11);
|
slices[5] = new Slice(chars, 50, 11);
|
||||||
slices[6] = new Slice(chars, 63, 7);
|
slices[6] = new Slice(chars, 63, 7);
|
||||||
|
|
||||||
char[][] keys = new char[7][];
|
char[][] keys = new char[7][];
|
||||||
keys[0] = "pantera".toCharArray();
|
keys[0] = "pantera".toCharArray();
|
||||||
keys[1] = "megadeth".toCharArray();
|
keys[1] = "megadeth".toCharArray();
|
||||||
|
@ -187,20 +179,19 @@ public class CharArrayMapTest extends TestCase {
|
||||||
keys[4] = "in flames".toCharArray();
|
keys[4] = "in flames".toCharArray();
|
||||||
keys[5] = "lamb of god".toCharArray();
|
keys[5] = "lamb of god".toCharArray();
|
||||||
keys[6] = "carcass".toCharArray();
|
keys[6] = "carcass".toCharArray();
|
||||||
|
|
||||||
|
|
||||||
CharArrayMap<Integer> map = new CharArrayMap<Integer>();
|
CharArrayMap<Integer> map = new CharArrayMap<Integer>();
|
||||||
assertTrue(map.isEmpty());
|
assertTrue(map.isEmpty());
|
||||||
assertEquals(0, map.size());
|
assertEquals(0, map.size());
|
||||||
|
|
||||||
for(int i = 0; i < slices.length; i++) {
|
for(int i = 0; i < slices.length; i++) {
|
||||||
Slice slice = slices[i];
|
Slice slice = slices[i];
|
||||||
map.put(slice.chars, slice.start, slice.length, i);
|
map.put(slice.chars, slice.start, slice.length, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
assertFalse(map.isEmpty());
|
assertFalse(map.isEmpty());
|
||||||
assertEquals(7, map.size());
|
assertEquals(7, map.size());
|
||||||
|
|
||||||
// should still work with equivalent keys
|
// should still work with equivalent keys
|
||||||
for(int i = 0; i < keys.length; i++) {
|
for(int i = 0; i < keys.length; i++) {
|
||||||
Slice slice = slices[i];
|
Slice slice = slices[i];
|
||||||
|
@ -215,17 +206,17 @@ public class CharArrayMapTest extends TestCase {
|
||||||
for(int i = 0; i < keys.length; i++) {
|
for(int i = 0; i < keys.length; i++) {
|
||||||
values.add(i);
|
values.add(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i : map.values()) {
|
for(int i : map.values()) {
|
||||||
assertTrue(values.remove(i));
|
assertTrue(values.remove(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove the last two keys
|
// remove the last two keys
|
||||||
map.remove(keys[5]);
|
map.remove(keys[5]);
|
||||||
map.remove(slices[6].chars, slices[6].start, slices[6].length);
|
map.remove(slices[6].chars, slices[6].start, slices[6].length);
|
||||||
|
|
||||||
assertEquals(5, map.size());
|
assertEquals(5, map.size());
|
||||||
|
|
||||||
// remaining keys should still be there
|
// remaining keys should still be there
|
||||||
for(int i = 0; i < 5; i++) {
|
for(int i = 0; i < 5; i++) {
|
||||||
Slice slice = slices[i];
|
Slice slice = slices[i];
|
||||||
|
@ -235,103 +226,97 @@ public class CharArrayMapTest extends TestCase {
|
||||||
assertTrue(map.containsKey(keys[i]));
|
assertTrue(map.containsKey(keys[i]));
|
||||||
assertTrue(map.containsValue(i));
|
assertTrue(map.containsValue(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
map.clear();
|
map.clear();
|
||||||
assertTrue(map.isEmpty());
|
assertTrue(map.isEmpty());
|
||||||
assertEquals(0, map.size());
|
assertEquals(0, map.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testProperFail() {
|
public void testProperFail() {
|
||||||
char[] hello = "hello".toCharArray();
|
char[] hello = "hello".toCharArray();
|
||||||
CharArrayMap<Integer> map = new CharArrayMap<Integer>();
|
CharArrayMap<Integer> map = new CharArrayMap<Integer>();
|
||||||
Integer value = new Integer(9);
|
Integer value = new Integer(9);
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
map.put(null, value);
|
map.put(null, value);
|
||||||
fail();
|
fail();
|
||||||
} catch(NullPointerException _) {}
|
} catch(NullPointerException _) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
map.put(hello, -1, 5, value);
|
map.put(hello, -1, 5, value);
|
||||||
fail();
|
fail();
|
||||||
} catch(IndexOutOfBoundsException _) {}
|
} catch(IndexOutOfBoundsException _) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
map.put(hello, 0, -1, value);
|
map.put(hello, 0, -1, value);
|
||||||
fail();
|
fail();
|
||||||
} catch(IndexOutOfBoundsException _) {}
|
} catch(IndexOutOfBoundsException _) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
map.put(hello, 0, 100, value);
|
map.put(hello, 0, 100, value);
|
||||||
fail();
|
fail();
|
||||||
} catch(IndexOutOfBoundsException _) {}
|
} catch(IndexOutOfBoundsException _) {}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
map.get(null);
|
map.get(null);
|
||||||
fail();
|
fail();
|
||||||
} catch(NullPointerException _) {}
|
} catch(NullPointerException _) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
map.get(hello, -1, 5);
|
map.get(hello, -1, 5);
|
||||||
fail();
|
fail();
|
||||||
} catch(IndexOutOfBoundsException _) {}
|
} catch(IndexOutOfBoundsException _) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
map.get(hello, 0, -1);
|
map.get(hello, 0, -1);
|
||||||
fail();
|
fail();
|
||||||
} catch(IndexOutOfBoundsException _) {}
|
} catch(IndexOutOfBoundsException _) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
map.get(hello, 0, 100);
|
map.get(hello, 0, 100);
|
||||||
fail();
|
fail();
|
||||||
} catch(IndexOutOfBoundsException _) {}
|
} catch(IndexOutOfBoundsException _) {}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
map.remove(null);
|
map.remove(null);
|
||||||
fail();
|
fail();
|
||||||
} catch(NullPointerException _) {}
|
} catch(NullPointerException _) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
map.remove(hello, -1, 5);
|
map.remove(hello, -1, 5);
|
||||||
fail();
|
fail();
|
||||||
} catch(IndexOutOfBoundsException _) {}
|
} catch(IndexOutOfBoundsException _) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
map.remove(hello, 0, -1);
|
map.remove(hello, 0, -1);
|
||||||
fail();
|
fail();
|
||||||
} catch(IndexOutOfBoundsException _) {}
|
} catch(IndexOutOfBoundsException _) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
map.remove(hello, 0, 100);
|
map.remove(hello, 0, 100);
|
||||||
fail();
|
fail();
|
||||||
} catch(IndexOutOfBoundsException _) {}
|
} catch(IndexOutOfBoundsException _) {}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
map.containsKey(null);
|
map.containsKey(null);
|
||||||
fail();
|
fail();
|
||||||
} catch(NullPointerException _) {}
|
} catch(NullPointerException _) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
map.containsKey(hello, -1, 5);
|
map.containsKey(hello, -1, 5);
|
||||||
fail();
|
fail();
|
||||||
} catch(IndexOutOfBoundsException _) {}
|
} catch(IndexOutOfBoundsException _) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
map.containsKey(hello, 0, -1);
|
map.containsKey(hello, 0, -1);
|
||||||
fail();
|
fail();
|
||||||
} catch(IndexOutOfBoundsException _) {}
|
} catch(IndexOutOfBoundsException _) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
map.containsKey(hello, 0, 100);
|
map.containsKey(hello, 0, 100);
|
||||||
fail();
|
fail();
|
||||||
} catch(IndexOutOfBoundsException _) {}
|
} catch(IndexOutOfBoundsException _) {}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
new CharArrayMap<Integer>(-1);
|
new CharArrayMap<Integer>(-1);
|
||||||
} catch(IllegalArgumentException _) {}
|
} catch(IllegalArgumentException _) {}
|
||||||
|
|
Loading…
Add table
Reference in a new issue