Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CharArrayMapTest.java')
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CharArrayMapTest.java139
1 files changed, 69 insertions, 70 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CharArrayMapTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CharArrayMapTest.java
index 25ab9a7017f..3617853de35 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CharArrayMapTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CharArrayMapTest.java
@@ -34,11 +34,13 @@ public class CharArrayMapTest extends TestCase {
final char[] chars;
final int start;
final int length;
+
public Slice(char[] chars, int start, int length) {
this.chars = chars;
this.length = length;
this.start = start;
}
+
@Override
public String toString() {
return new String(chars, start, length);
@@ -49,7 +51,7 @@ public class CharArrayMapTest extends TestCase {
final int iterations = 10000;
// insert tons of keys
char[][] keys = new char[iterations][];
- for(int i = 0; i < keys.length; i++) {
+ for (int i = 0; i < keys.length; i++) {
keys[i] = String.valueOf(i).toCharArray();
}
@@ -67,11 +69,11 @@ public class CharArrayMapTest extends TestCase {
private static long timeMap(char[][] keys) {
long start = System.currentTimeMillis();
CharArrayMap<Integer> map = new CharArrayMap<Integer>(keys.length);
- for(int i = 0; i < keys.length; i++) {
+ for (int i = 0; i < keys.length; i++) {
map.put(keys[i], i);
}
assertEquals(keys.length, map.size());
- for(int i = 0; i < keys.length; i++) {
+ for (int i = 0; i < keys.length; i++) {
assertEquals(Integer.valueOf(i), map.get(keys[i]));
}
return System.currentTimeMillis() - start;
@@ -80,11 +82,11 @@ public class CharArrayMapTest extends TestCase {
private static long timeOldMap(char[][] keys) {
long start = System.currentTimeMillis();
CharArrayObjectMap oldMap = new CharArrayObjectMap(keys.length);
- for(int i = 0; i < keys.length; i++) {
+ for (int i = 0; i < keys.length; i++) {
oldMap.put(keys[i], Integer.valueOf(i));
}
assertEquals(keys.length, oldMap.size());
- for(int i = 0; i < keys.length; i++) {
+ for (int i = 0; i < keys.length; i++) {
assertEquals(Integer.valueOf(i), oldMap.get(keys[i]));
}
return System.currentTimeMillis() - start;
@@ -129,17 +131,17 @@ public class CharArrayMapTest extends TestCase {
values.add(3);
values.add(4);
- for(int i : map.values()) {
+ for (int i : map.values()) {
assertTrue(values.remove(i));
}
// remove a mapping
assertEquals(Integer.valueOf(1), map.remove(key1));
assertEquals(3, map.size());
- assertNull(map.get(key1));
- assertFalse(map.containsKey(key1));
- assertFalse(map.containsValue(1));
- assertNull(map.remove(key1)); // its already removed
+ assertNull(map.get(key1));
+ assertFalse(map.containsKey(key1));
+ assertFalse(map.containsValue(1));
+ assertNull(map.remove(key1)); // its already removed
map.clear();
assertTrue(map.isEmpty());
@@ -169,31 +171,18 @@ public class CharArrayMapTest extends TestCase {
public void testBasicUsage2() {
char[] chars = "pantera, megadeth, soulfly, metallica, in flames, lamb of god, carcass".toCharArray();
- Slice[] slices = {
- new Slice(chars, 0, 7),
- new Slice(chars, 9, 8),
- new Slice(chars, 19, 7),
- new Slice(chars, 28, 9),
- new Slice(chars, 39, 9),
- new Slice(chars, 50, 11),
- new Slice(chars, 63, 7)
- };
-
- char[][] keys = {
- "pantera".toCharArray(),
- "megadeth".toCharArray(),
- "soulfly".toCharArray(),
- "metallica".toCharArray(),
- "in flames".toCharArray(),
- "lamb of god".toCharArray(),
- "carcass".toCharArray()
- };
+ Slice[] slices = { new Slice(chars, 0, 7), new Slice(chars, 9, 8), new Slice(chars, 19, 7),
+ new Slice(chars, 28, 9), new Slice(chars, 39, 9), new Slice(chars, 50, 11), new Slice(chars, 63, 7) };
+
+ char[][] keys = { "pantera".toCharArray(), "megadeth".toCharArray(), "soulfly".toCharArray(),
+ "metallica".toCharArray(), "in flames".toCharArray(), "lamb of god".toCharArray(),
+ "carcass".toCharArray() };
CharArrayMap<Integer> map = new CharArrayMap<Integer>();
assertTrue(map.isEmpty());
assertEquals(0, map.size());
- for(int i = 0; i < slices.length; i++) {
+ for (int i = 0; i < slices.length; i++) {
Slice slice = slices[i];
map.put(slice.chars, slice.start, slice.length, i);
}
@@ -202,7 +191,7 @@ public class CharArrayMapTest extends TestCase {
assertEquals(7, map.size());
// 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];
assertEquals(Integer.valueOf(i), map.get(slice.chars, slice.start, slice.length));
assertEquals(Integer.valueOf(i), map.get(keys[i]));
@@ -212,11 +201,11 @@ public class CharArrayMapTest extends TestCase {
}
Set<Integer> values = new HashSet<Integer>();
- for(int i = 0; i < keys.length; i++) {
+ for (int i = 0; i < keys.length; i++) {
values.add(i);
}
- for(int i : map.values()) {
+ for (int i : map.values()) {
assertTrue(values.remove(i));
}
@@ -227,7 +216,7 @@ public class CharArrayMapTest extends TestCase {
assertEquals(5, map.size());
// remaining keys should still be there
- for(int i = 0; i < 5; i++) {
+ for (int i = 0; i < 5; i++) {
Slice slice = slices[i];
assertEquals(Integer.valueOf(i), map.get(slice.chars, slice.start, slice.length));
assertEquals(Integer.valueOf(i), map.get(keys[i]));
@@ -241,48 +230,41 @@ public class CharArrayMapTest extends TestCase {
assertEquals(0, map.size());
}
-
public void testOrderedMap() {
char[] chars = "alpha beta aaa cappa almost".toCharArray();
- Slice[] slices = {
- new Slice(chars, 0, 5),
- new Slice(chars, 6, 4),
- new Slice(chars, 11, 3),
- new Slice(chars, 15, 5),
- new Slice(chars, 21, 6)
- };
- int[] order = {3, 4, 1, 5, 2};
-
+ Slice[] slices = { new Slice(chars, 0, 5), new Slice(chars, 6, 4), new Slice(chars, 11, 3),
+ new Slice(chars, 15, 5), new Slice(chars, 21, 6) };
+ int[] order = { 3, 4, 1, 5, 2 };
+
CharArrayMap<Integer> map = CharArrayMap.createOrderedMap();
-
- for(int i = 0; i < slices.length; i++) {
+
+ for (int i = 0; i < slices.length; i++) {
Slice slice = slices[i];
map.put(slice.chars, slice.start, slice.length, order[i]);
}
-
+
List<String> properOrder = Arrays.asList("aaa", "almost", "alpha", "beta", "cappa");
-
+
Collection<char[]> keys = map.keys();
assertEquals(5, keys.size());
{
int i = 0;
- for(char[] key : keys) {
+ for (char[] key : keys) {
assertEquals(properOrder.get(i), String.valueOf(key));
i++;
}
}
-
+
Collection<Integer> values = map.values();
assertEquals(5, values.size());
{
int i = 1;
- for(int value : values) {
+ for (int value : values) {
assertEquals(i++, value);
}
}
}
-
-
+
public void testProperFail() {
char[] hello = "hello".toCharArray();
CharArrayMap<Integer> map = new CharArrayMap<Integer>();
@@ -291,85 +273,102 @@ public class CharArrayMapTest extends TestCase {
try {
map.put(null, value);
fail();
- } catch(NullPointerException expectedException) {}
+ } catch (NullPointerException expectedException) {
+ }
try {
map.put(hello, -1, 5, value);
fail();
- } catch(IndexOutOfBoundsException expectedException) {}
+ } catch (IndexOutOfBoundsException expectedException) {
+ }
try {
map.put(hello, 0, -1, value);
fail();
- } catch(IndexOutOfBoundsException expectedException) {}
+ } catch (IndexOutOfBoundsException expectedException) {
+ }
try {
map.put(hello, 0, 100, value);
fail();
- } catch(IndexOutOfBoundsException expectedException) {}
+ } catch (IndexOutOfBoundsException expectedException) {
+ }
try {
map.get(null);
fail();
- } catch(NullPointerException expectedException) {}
+ } catch (NullPointerException expectedException) {
+ }
try {
map.get(hello, -1, 5);
fail();
- } catch(IndexOutOfBoundsException expectedException) {}
+ } catch (IndexOutOfBoundsException expectedException) {
+ }
try {
map.get(hello, 0, -1);
fail();
- } catch(IndexOutOfBoundsException expectedException) {}
+ } catch (IndexOutOfBoundsException expectedException) {
+ }
try {
map.get(hello, 0, 100);
fail();
- } catch(IndexOutOfBoundsException expectedException) {}
+ } catch (IndexOutOfBoundsException expectedException) {
+ }
try {
map.remove(null);
fail();
- } catch(NullPointerException expectedException) {}
+ } catch (NullPointerException expectedException) {
+ }
try {
map.remove(hello, -1, 5);
fail();
- } catch(IndexOutOfBoundsException expectedException) {}
+ } catch (IndexOutOfBoundsException expectedException) {
+ }
try {
map.remove(hello, 0, -1);
fail();
- } catch(IndexOutOfBoundsException expectedException) {}
+ } catch (IndexOutOfBoundsException expectedException) {
+ }
try {
map.remove(hello, 0, 100);
fail();
- } catch(IndexOutOfBoundsException expectedException) {}
+ } catch (IndexOutOfBoundsException expectedException) {
+ }
try {
map.containsKey(null);
fail();
- } catch(NullPointerException expectedException) {}
+ } catch (NullPointerException expectedException) {
+ }
try {
map.containsKey(hello, -1, 5);
fail();
- } catch(IndexOutOfBoundsException expectedException) {}
+ } catch (IndexOutOfBoundsException expectedException) {
+ }
try {
map.containsKey(hello, 0, -1);
fail();
- } catch(IndexOutOfBoundsException expectedException) {}
+ } catch (IndexOutOfBoundsException expectedException) {
+ }
try {
map.containsKey(hello, 0, 100);
fail();
- } catch(IndexOutOfBoundsException expectedException) {}
+ } catch (IndexOutOfBoundsException expectedException) {
+ }
try {
new CharArrayMap<Integer>(-1);
- } catch(IllegalArgumentException expectedException) {}
+ } catch (IllegalArgumentException expectedException) {
+ }
}
}

Back to the top