|
|
@@ -6,7 +6,12 @@
|
|
|
*/
|
|
|
package net.ranides.assira.collection.mockup;
|
|
|
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Iterator;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Random;
|
|
|
+import java.util.Set;
|
|
|
+import net.ranides.assira.collection.lists.IntList;
|
|
|
import net.ranides.assira.collection.lookups.Lookup;
|
|
|
import static net.ranides.assira.collection.mockup.TPointEnum.*;
|
|
|
import static org.junit.Assert.*;
|
|
|
@@ -15,7 +20,7 @@ import static org.junit.Assert.*;
|
|
|
*
|
|
|
* @author Ranides Atterwim <ranides@gmail.com>
|
|
|
*/
|
|
|
-public final class ALookupTester extends TPointTester {
|
|
|
+public class ALookupTester extends TPointTester {
|
|
|
|
|
|
public ALookupTester(TPointGenerator generator) {
|
|
|
super(generator);
|
|
|
@@ -73,22 +78,39 @@ public final class ALookupTester extends TPointTester {
|
|
|
assertEquals(prev + 2, target.size());
|
|
|
}
|
|
|
|
|
|
- public void basicReplaceInt(Lookup<TPoint> target, int count) {
|
|
|
+ public void basicPutReplaceInt(Lookup<TPoint> target, int count) {
|
|
|
int prev = target.size();
|
|
|
for (TPoint point : $ukeys(count)) {
|
|
|
target.put(point, $value(B1));
|
|
|
}
|
|
|
assertEquals(prev + (2 * count), target.size());
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- public void basicReplaceInteger(Map<TPoint, Integer> target, int count) {
|
|
|
+
|
|
|
+ public void basicPutReplaceInteger(Map<TPoint, Integer> target, int count) {
|
|
|
int prev = target.size();
|
|
|
for (TPoint point : $ukeys(count)) {
|
|
|
target.put(point, $object(B1));
|
|
|
}
|
|
|
assertEquals(prev + (2 * count), target.size());
|
|
|
}
|
|
|
+
|
|
|
+ public void basicPutRandomInt(Lookup<TPoint> target, int count) {
|
|
|
+ int prev = target.size();
|
|
|
+ for (TPoint point : shuffle($ukeys(count))) {
|
|
|
+ target.put(point, $value(B1));
|
|
|
+ }
|
|
|
+ assertEquals(prev + (2 * count), target.size());
|
|
|
+ }
|
|
|
+
|
|
|
+ public void basicPutRandomInteger(Map<TPoint, Integer> target, int count) {
|
|
|
+ int prev = target.size();
|
|
|
+ for (TPoint point :shuffle($ukeys(count))) {
|
|
|
+ target.put(point, $object(B1));
|
|
|
+ }
|
|
|
+ assertEquals(prev + (2 * count), target.size());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
public void basicRemoveInt(Lookup<TPoint> target) {
|
|
|
target.defaultReturnValue(-1);
|
|
|
@@ -245,6 +267,62 @@ public final class ALookupTester extends TPointTester {
|
|
|
assertEquals(false, target.containsValue($object(A1_NE)));
|
|
|
assertEquals(false, target.containsValue($object(C1)));
|
|
|
}
|
|
|
+
|
|
|
+ public void basicClear(Map<TPoint, Integer> target) {
|
|
|
+ assertEquals(0, target.size());
|
|
|
+
|
|
|
+ put(target, A1, A1_NE, B1);
|
|
|
+ assertSize(3, target);
|
|
|
+ assertEquals(false, target.isEmpty());
|
|
|
+
|
|
|
+ target.clear();
|
|
|
+ assertSize(0, target);
|
|
|
+ assertEquals(true, target.isEmpty());
|
|
|
+
|
|
|
+ target.clear();
|
|
|
+ assertSize(0, target);
|
|
|
+ assertEquals(true, target.isEmpty());
|
|
|
+ }
|
|
|
+
|
|
|
+ public void basicEntrySet(Lookup<TPoint> target) {
|
|
|
+ Set<Lookup.LookupEntry<TPoint>> set = target.fastEntrySet();
|
|
|
+
|
|
|
+ assertEquals(0, set.size());
|
|
|
+ put(target, A1, A1_NE, B1, C1);
|
|
|
+ assertEquals(4, set.size());
|
|
|
+
|
|
|
+ for(Lookup.LookupEntry<TPoint> entry : set) {
|
|
|
+ assertEquals(target.getInt(entry.getKey()), entry.getIntValue());
|
|
|
+ }
|
|
|
+
|
|
|
+ Iterator<Lookup.LookupEntry<TPoint>> itr1 = set.iterator();
|
|
|
+ while(itr1.hasNext()) {
|
|
|
+ Lookup.LookupEntry<TPoint> entry = itr1.next();
|
|
|
+ entry.setValue(991);
|
|
|
+ }
|
|
|
+
|
|
|
+ assertArrayEquals(new int[]{991, 991, 991, 991}, target.values().toIntArray());
|
|
|
+
|
|
|
+ Iterator<Lookup.LookupEntry<TPoint>> itr2 = set.iterator();
|
|
|
+ while(itr2.hasNext()) {
|
|
|
+ TPoint key = itr2.next().getKey();
|
|
|
+ boolean f1 = TPoint.SUM.equals(key, $key(A1_NE));
|
|
|
+ boolean f2 = TPoint.SUM.equals(key, $key(C1));
|
|
|
+ if(f1 || f2) {
|
|
|
+ itr2.remove();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ assertArrayEquals(new int[]{991, 991}, target.values().toIntArray());
|
|
|
+
|
|
|
+ assertEquals(true, target.containsKey($key(A1)));
|
|
|
+ assertEquals(true, target.containsKey($key(B1)));
|
|
|
+ assertEquals(false, target.containsKey($key(A1_NE)));
|
|
|
+ assertEquals(false, target.containsKey($key(C1)));
|
|
|
+ }
|
|
|
+
|
|
|
+// public void basicEntrySet(Map<TPoint, Integer> target) {
|
|
|
+//
|
|
|
+// }
|
|
|
|
|
|
protected void assertRemoveInt(Lookup<TPoint> target, TPointEnum key, TPointEnum prev) {
|
|
|
int size = target.size();
|
|
|
@@ -289,5 +367,25 @@ public final class ALookupTester extends TPointTester {
|
|
|
assertEquals(false, target.containsKey($key(key)));
|
|
|
assertEquals(null, target.get($key(key)));
|
|
|
}
|
|
|
+
|
|
|
+ protected void assertSize(int size, Map<TPoint, Integer> target) {
|
|
|
+ assertEquals(size, target.size());
|
|
|
+ assertEquals(size, target.entrySet().size());
|
|
|
+ assertEquals(size, target.keySet().size());
|
|
|
+ assertEquals(size, target.values().size());
|
|
|
+ }
|
|
|
+
|
|
|
+ private TPoint[] shuffle(TPoint[] array) {
|
|
|
+ int n = array.length;
|
|
|
+ Random random = new Random(777);
|
|
|
+ for(int i=0; i<n; i++) {
|
|
|
+ int a = random.nextInt(n);
|
|
|
+ int b = random.nextInt(n);
|
|
|
+ TPoint point = array[a];
|
|
|
+ array[a] = array[b];
|
|
|
+ array[b] = point;
|
|
|
+ }
|
|
|
+ return array;
|
|
|
+ }
|
|
|
|
|
|
}
|