Ver código fonte

TMap: broken

Ranides Atterwim 10 anos atrás
pai
commit
60fcacd0ae

+ 22 - 0
assira/src/main/java/net/ranides/assira/collection/arrays/ArrayUtils.java

@@ -156,6 +156,20 @@ public final class ArrayUtils {
         return true;
     }
     
+    public static <K> K[] head(K[] values, K value) {
+        return islice(values, 0, ifind(values, value, 0));
+    }
+    
+    public static <K> K[] tail(K[] values, K value) {
+        return islice(values, ifind(values, value, 0), values.length);
+    }
+    
+    public static <K> K[] slice(K[] values, K begin, K end) {
+        int bi = ifind(values, begin, 0);
+        int ei = ifind(values, end, bi);
+        return islice(values, bi, ei);
+    }
+    
     public static <K> K[] head(K[] values, K value, Comparator<K> cmp) {
         return islice(values, 0, ifind(values, value, 0, cmp));
     }
@@ -178,6 +192,14 @@ public final class ArrayUtils {
         return i;
     }
     
+    private static <K> int ifind(K[] values, K value, int begin) {
+        int i = begin;
+        while(i<values.length && !value.equals(values[i])) {
+            i++;
+        }
+        return i;
+    }
+    
     private static <K> K[] islice(K[] values, int begin, int end) {
         int size = end - begin;
         K[] result = ArrayAllocator.allocate(values, size);

+ 28 - 0
assira/src/main/java/net/ranides/assira/test/TGenerator.java

@@ -0,0 +1,28 @@
+/*
+ * @author Ranides Atterwim <ranides@gmail.com>
+ * @copyright Ranides Atterwim
+ * @license WTFPL
+ * @url http://ranides.net/projects/???
+ */
+package net.ranides.assira.test;
+
+import java.util.function.IntFunction;
+
+/**
+ *
+ * @author Ranides Atterwim <ranides@gmail.com>
+ */
+public interface TGenerator<T> extends IntFunction<T> {
+    
+    public T value(int index);
+    
+    public default int valueInt(int index) {
+        return ((Number)value(index)).intValue();
+    }
+
+    @Override
+    public default T apply(int index) {
+        return value(index);
+    }
+    
+}

+ 18 - 2
assira/src/main/java/net/ranides/assira/test/TMap.java

@@ -56,13 +56,17 @@ public abstract class TMap<K,V> {
             return new AbstractMap.SimpleImmutableEntry<>(key, value);
         }
         
+        public Entry<K,V> entry(int value) {
+            return new AbstractMap.SimpleImmutableEntry<>(key, that.value(value));
+        }
+        
 		public Map<K,V> into(Map<K,V> target) {
 			target.put(key(), value());
 			return target;
 		}
         
     }
-    
+        
     public static final class TItems<K,V> implements Iterable<TItem<K,V>> {
         
         protected final TMap<K,V> that;
@@ -163,7 +167,7 @@ public abstract class TMap<K,V> {
 			}
 			return target;
 		}
-		
+        
 		public void dump() {
 			System.err.printf("TItems(%d)%n", data.size());
 			for(int i=0,n=data.size(); i<n; i++) {
@@ -226,5 +230,17 @@ public abstract class TMap<K,V> {
     public TItems<K,V> urange(int count) {
         return urange(0,count);
     }
+    
+    public TGenerator<K> keys() {
+        return (int index) -> item(index).key();
+    }
+    
+    public TGenerator<V> values() {
+        return (int index) -> item(index).value();
+    }
+    
+    public TGenerator<Entry<K,V>> entries() {
+        return (int index) -> item(index).entry();
+    }
 
 }

+ 1 - 1
assira/src/test/java/net/ranides/assira/collection/lookups/AVLTreeLookupTest.java

@@ -28,7 +28,7 @@ public class AVLTreeLookupTest {
     public void testSuite() {
         CollectionSuite.SUITE
 			.param("map!", TPoint.INT_MAP)
-			.run(() -> new AVLTreeLookup<>(TPoint.SUM));
+			.run(() -> new AVLTreeLookup<>(TPoint.STD));
     }
     
     @Test

+ 7 - 5
assira/src/test/java/net/ranides/assira/collection/mockup/ValueGenerator.java

@@ -6,17 +6,14 @@
  */
 package net.ranides.assira.collection.mockup;
 
-import java.lang.reflect.Array;
-import java.util.Random;
 import net.ranides.assira.collection.HashComparator;
-import net.ranides.assira.collection.arrays.ArrayAllocator;
-import net.ranides.assira.generic.CompareUtils;
+import net.ranides.assira.test.TGenerator;
 
 /**
  *
  * @author Ranides Atterwim <ranides@gmail.com>
  */
-public interface ValueGenerator<Q, E extends Enum<E>> {
+public interface ValueGenerator<Q, E extends Enum<E>> extends TGenerator<Q> {
     
     HashComparator<Q> comparator();
 
@@ -24,4 +21,9 @@ public interface ValueGenerator<Q, E extends Enum<E>> {
     
     Q object(int key);
 
+    @Override
+    public default Q value(int index) {
+        return object(index);
+    }
+
 }

+ 0 - 1
assira/src/test/java/net/ranides/assira/collection/suite/CollectionSuite.java

@@ -25,7 +25,6 @@ public final class CollectionSuite {
         .append(new AHashMapTester())
         .append(new SortedMapTester())
         .param("map!", TPoint.INT_MAP)
-		.param("sum!", TPoint.STD);
 		;
     
     public static final QTesterSuite INT_SUITE = new QTesterSuite(System.err)

+ 21 - 22
assira/src/test/java/net/ranides/assira/collection/suite/LookupTester.java

@@ -10,7 +10,6 @@ import java.util.Iterator;
 import java.util.NoSuchElementException;
 import java.util.Set;
 import javax.annotation.Resource;
-import net.ranides.assira.collection.HashComparator;
 import net.ranides.assira.collection.IntCollection;
 import net.ranides.assira.collection.iterators.IntIterator;
 import net.ranides.assira.collection.lookups.Lookup;
@@ -31,9 +30,6 @@ public final class LookupTester<K> {
     @Resource(name = "map!")
     private TMap<K,Integer> $map;
 	
-	@Resource(name = "sum!")
-    private HashComparator<K> $cmp;
-    
     private static final int BASIC_PUT_MANY = 128;
     
     private static final int BASIC_PUT_REPLACE = 40;
@@ -47,8 +43,8 @@ public final class LookupTester<K> {
     @Test
     public void basicPut(Lookup<K> target) {
         int prev = target.size();
-        for(TItem<K,Integer> item :$map.range(0, BASIC_PUT_MANY)) {
-            target.put(item.key(), item.value());
+        for(TItem<K,?> item :$map.range(0, BASIC_PUT_MANY)) {
+            target.put(item.key(), item.valueInt());
         }
         assertEquals(prev + BASIC_PUT_MANY, target.size());
         
@@ -60,13 +56,13 @@ public final class LookupTester<K> {
         int prev = target.size();
         TItem<K,Integer> item1 = $map.item(1001,0);
         TItem<K,Integer> item2 = $map.item(1001,1);
-        target.put(item1.key(), item1.value());
+        target.put(item1.key(), item1.valueInt());
         assertEquals(prev + 1, target.size());
         
-        target.put(item1.key(), item1.value());
+        target.put(item1.key(), item1.valueInt());
         assertEquals(prev + 1, target.size());
         
-        target.put(item2.key(), item2.value()); // identical hash but not eq
+        target.put(item2.key(), item2.valueInt()); // identical hash but not eq
         assertEquals(prev + 2, target.size());
     }
     
@@ -74,7 +70,7 @@ public final class LookupTester<K> {
     public void basicPutReplace(Lookup<K> target) {
         int prev = target.size();
         for (TItem<K,Integer> item : $map.urange(0, BASIC_PUT_REPLACE)) {
-            target.put(item.key(), item.value());
+            target.put(item.key(), item.valueInt());
         }
         assertEquals(prev + (2 * BASIC_PUT_REPLACE), target.size());
     }
@@ -83,7 +79,7 @@ public final class LookupTester<K> {
     public void basicPutRandom(Lookup<K> target) {
         int prev = target.size();
         for (TItem<K,Integer> item : $map.urange(0, BASIC_PUT_RANDOM)) {
-            target.put(item.key(), item.value());
+            target.put(item.key(), item.valueInt());
         }
         assertEquals(prev + (2 * BASIC_PUT_RANDOM), target.size());
     }
@@ -137,11 +133,12 @@ public final class LookupTester<K> {
     
     @Test
     public void basicGet(Lookup<K> target) {
-        assertEquals(0, target.getInt($map.item(1).key()));
+        target.defaultReturnValue(-1);
+        assertEquals(-1, target.getInt($map.item(1).key()));
 
         $map.list(1,2,3).into(target);
         assertEquals(3, target.size());
-        assertEquals(0, target.getInt($map.item(1,1).key()));
+        assertEquals(-1, target.getInt($map.item(1,1).key()));
         
         assertEquals($map.item(1).valueInt(), target.getInt($map.item(1).key()));
         assertEquals($map.item(2).valueInt(), target.getInt($map.item(2).key()));
@@ -206,19 +203,21 @@ public final class LookupTester<K> {
 		$map.list().item(1).item(1,1).item(2).item(3).into(target);
 		K k1 = $map.item(1).key();
 		K k2 = $map.item(2).key();
+        int v1 = $map.item(101).valueInt();
+        int v2 = $map.item(102).valueInt();
 		
 		Iterator<Lookup.LookupEntry<K>> iterator = set.iterator();
 		while(iterator.hasNext()) {
 			Lookup.LookupEntry<K> entry = iterator.next();
-			if($cmp.equals(k1, entry.getKey())) {
-				entry.setValue(667);
+			if(k1.equals(entry.getKey())) {
+				entry.setValue(v1);
 			}
-			if($cmp.equals(k2, entry.getKey())) {
-				entry.setValue(668);
+			if(k2.equals(entry.getKey())) {
+				entry.setValue(v2);
 			}
 		}
-		assertContains(target, $map.item(1).key(), 667);
-		assertContains(target, $map.item(2).key(), 668);
+		assertContains(target, $map.item(1).key(), v1);
+		assertContains(target, $map.item(2).key(), v2);
 		assertContains(target, $map.item(1,1));
 		assertContains(target, $map.item(3));
 	}
@@ -285,10 +284,10 @@ public final class LookupTester<K> {
 		while(iterator.hasNext()) {
 			int var = iterator.next();
 			
-            if(var == $map.item(1).value()) {
+            if(var == $map.item(1).valueInt()) {
                 iterator.remove();
             }
-            if(var == $map.item(2).value()) {
+            if(var == $map.item(2).valueInt()) {
                 iterator.remove();
                 QAssert.assertThrows(IllegalStateException.class, ()-> iterator.remove());
             }
@@ -322,7 +321,7 @@ public final class LookupTester<K> {
     }
     
     private void assertContains(Lookup<K> target, TItem<K,Integer> item) {
-		assertContains(target, item.key(), item.value());
+		assertContains(target, item.key(), item.valueInt());
     }
     
     private void assertNotContains(Lookup<K> target, TItem<K,Integer> item) {

+ 256 - 235
assira/src/test/java/net/ranides/assira/collection/suite/MapTester.java

@@ -13,11 +13,16 @@ import java.util.Map.Entry;
 import java.util.NoSuchElementException;
 import java.util.Set;
 import java.util.function.Supplier;
+import javax.annotation.Resource;
+import net.ranides.assira.collection.lookups.Lookup;
 import net.ranides.assira.collection.mockup.TPoint;
-import net.ranides.assira.collection.mockup.ValueEnum;
-import static net.ranides.assira.collection.mockup.ValueEnum.*;
-import static net.ranides.assira.collection.mockup.TPointUtils.*;
+//import net.ranides.assira.collection.mockup.ValueEnum;
+//import static net.ranides.assira.collection.mockup.ValueEnum.*;
+//import static net.ranides.assira.collection.mockup.TPointUtils.*;
 import net.ranides.assira.junit.QAssert;
+import net.ranides.assira.test.TMap;
+import net.ranides.assira.test.TMap.TItem;
+import net.ranides.assira.test.TMap.TItems;
 import static org.junit.Assert.*;
 import org.junit.Test;
 
@@ -26,8 +31,8 @@ import org.junit.Test;
  * @author Ranides Atterwim <ranides@gmail.com>
  */
 @SuppressWarnings("PMD.MethodNameRules")
-public final class MapTester {
-    
+public final class MapTester<K,V> {
+        
     private static final int BASIC_PUT = 128;
     
     private static final int BASIC_PUT_REPLACE = 40;
@@ -38,155 +43,148 @@ public final class MapTester {
     
     private static final int BASIC_REMOVE_RANDOM = 273;
     
+    @Resource(name = "map!")
+    private TMap<K,V> $map;
+    
     @Test
-    public void basicPut(Map<TPoint, Integer> target) {
-        int prev = target.size();
-        int value = 200;
-        for (TPoint point : $keys(BASIC_PUT)) {
-            target.put(point, value++);
+    public void basicPut(Map<K, V> target) {
+        for(TItem<K,V> item : $map.range(BASIC_PUT)) {
+            target.put(item.key(), item.value());
         }
-        assertEquals(prev + BASIC_PUT, target.size());
+        assertEquals(BASIC_PUT, target.size());
         
         logicPut(target);
     }
 
     @Test
-    public void logicPut(Map<TPoint, Integer> target) {
+    public void logicPut(Map<K, V> target) {
         int prev = target.size();
-        target.put($key(A1), $object(A1));
+        TItem<K,V> item1 = $map.item(1001,0);
+        TItem<K,V> item2 = $map.item(1001,1);
+        target.put(item1.key(), item1.value());
         assertEquals(prev + 1, target.size());
         
-        target.put($key(A1_EQ), $object(A1_EQ)); // identical hash & eq
+        target.put(item1.key(), item1.value());
         assertEquals(prev + 1, target.size());
         
-        target.put($key(A1_NE), $object(A1_NE)); // identical hash but not eq
+        target.put(item2.key(), item2.value()); // identical hash but not eq
         assertEquals(prev + 2, target.size());
     }
 	
     @Test
-    public void basicPutReplace(Map<TPoint, Integer> target) {
+    public void basicPutReplace(Map<K, V> target) {
         int prev = target.size();
-        for (TPoint point : $ukeys(BASIC_PUT_REPLACE)) {
-            target.put(point, $object(B1));
+        for (TItem<K,V> item : $map.urange(0, BASIC_PUT_REPLACE)) {
+            target.put(item.key(), item.value());
         }
         assertEquals(prev + (2 * BASIC_PUT_REPLACE), target.size());
     }
 	
 	@Test
-    public void basicPutRandom(Map<TPoint, Integer> target) {
+    public void basicPutRandom(Map<K, V> target) {
         int prev = target.size();
-        for (TPoint point : $shuffle($ukeys(BASIC_PUT_RANDOM))) {
-            target.put(point, $object(B1));
+        for (TItem<K,V> item : $map.urange(0, BASIC_PUT_RANDOM)) {
+            target.put(item.key(), item.value());
         }
         assertEquals(prev + (2 * BASIC_PUT_RANDOM), target.size());
     }
 	    
     @Test
-    public void basicRemove(Map<TPoint, Integer> target) {
-        $put(target, A1, B1, C1);
+    public void basicRemove(Map<K, V> target) {
+        $map.list(1,2,3).into(target);
         
-        assertNotRemove(target, A1_NE);
+        assertNotRemove(target, $map.item(1,1));
         
-        assertRemove(target, A1_EQ, A1);
-        assertRemove(target, B1, B1);
-        assertRemove(target, C1, C1);
+        assertRemove(target, $map.item(1));
+        assertRemove(target, $map.item(2));
+        assertRemove(target, $map.item(3));
         
         assertEquals(0, target.size());
         
-        assertNotRemove(target, C1);
+        assertNotRemove(target, $map.item(3));
     }
    
     @Test
-    public void basicRemoveAll(Map<TPoint, Integer> target) {
+    public void basicRemoveAll(Map<K, V> target) {
         assertEquals(0, target.size());
-        TPoint[] keys = $keys(BASIC_REMOVE_ALL);
-        Integer[] values = $objects(BASIC_REMOVE_ALL);
+        TItems<K,V> items = $map.range(0, BASIC_REMOVE_ALL);
         
-        for(int i=0; i<BASIC_REMOVE_ALL; i++) {
-            target.put(keys[i], values[i]);
-        }
+        items.into(target);
         assertEquals(BASIC_REMOVE_ALL, target.size());
         
         for(int i=0; i<BASIC_REMOVE_ALL; i++) {
-            assertEquals(values[i], target.remove(keys[i]));
+            assertEquals(items.at(i).valueInt(), target.remove(items.at(i).key()));
             assertEquals(BASIC_REMOVE_ALL-i-1, target.size());
         }
         assertEquals(0, target.size());
     }
     
     @Test
-    public void basicRemoveRandom(Map<TPoint, Integer> target) {
+    public void basicRemoveRandom(Map<K, V> target) {
         assertEquals(0, target.size());
-        TPoint[] keys = $keys(BASIC_REMOVE_RANDOM);
-        Integer[] objects = $objects(BASIC_REMOVE_RANDOM);
+        TItems<K,V> items = $map.range(0, BASIC_REMOVE_RANDOM);
         
-        for(int i=0; i<BASIC_REMOVE_RANDOM; i++) {
-            target.put(keys[i], objects[i]);
-        }
+        items.into(target);
         assertEquals(BASIC_REMOVE_RANDOM, target.size());
 
-        $shuffle(keys, objects);
+        items.shuffle(777);
         for(int i=0; i<BASIC_REMOVE_RANDOM; i++) {
-            assertEquals(objects[i], target.remove(keys[i]));
+            assertEquals(items.at(i).valueInt(), target.remove(items.at(i).key()));
             assertEquals(BASIC_REMOVE_RANDOM-i-1, target.size());
         }
         assertEquals(0, target.size());
     }
     
     @Test
-    public void basicGet(Map<TPoint, Integer> target) {
-        assertEquals(null, target.get($key(A1)));
-        
-        $put(target, A1, B1, C1);
-        
-        assertEquals(null, target.get($key(A1_NE)));
+    public void basicGet(Map<K, V> target) {
+        assertEquals(null, target.get($map.item(1).key()));
+
+        $map.list(1,2,3).into(target);
+        assertEquals(3, target.size());
+        assertEquals(null, target.get($map.item(1,1).key()));
         
-        assertEquals($object(A1), target.get($key(A1)));
-        assertEquals($object(A1), target.get($key(A1_EQ)));
-        assertEquals($object(B1), target.get($key(B1)));
-        assertEquals($object(C1), target.get($key(C1)));
+        assertEquals($map.item(1).valueInt(), target.get($map.item(1).key()));
+        assertEquals($map.item(2).valueInt(), target.get($map.item(2).key()));
+        assertEquals($map.item(3).valueInt(), target.get($map.item(3).key()));
     }
     
     @Test
-    public void logicRemove(Map<TPoint, Integer> target) {
-        $put(target, A1, B1, C1);
+    public void logicRemove(Map<K, V> target) {
+		$map.list(1,2,3).into(target);
         
-        assertEquals(null, target.remove($key(A1_NE)));
+        assertEquals(null, target.remove($map.item(1,1).key()));
         assertEquals(3, target.size());
-
-        assertContains(target, A1_EQ, A1);
-        assertContains(target, A1, A1);
-        assertRemove(target, A1_EQ, A1);
-        assertNotContains(target, A1_EQ);
-        assertNotContains(target, A1);
-        
-        assertContains(target, B1, B1);
-        assertRemove(target, B1, B1);
-        assertNotContains(target, B1);
-        
-        assertContains(target, C1, C1);
-        assertRemove(target, C1, C1);
-        assertNotContains(target, C1);
+		
+        assertContains(target, $map.item(1));
+        assertRemove(target, $map.item(1));
+        assertNotContains(target, $map.item(1));
+        
+        assertContains(target, $map.item(2));
+        assertRemove(target, $map.item(2));
+        assertNotContains(target, $map.item(2));
+        
+        assertContains(target, $map.item(3));
+        assertRemove(target, $map.item(3));
+        assertNotContains(target, $map.item(3));
     }
     
     @Test
-    public void basicContains(Map<TPoint, Integer> target) {
+    public void basicContains(Map<K, V> target) {
         assertEquals(0, target.size());
-        $put(target, A1, B1);
+		$map.list(1,2).into(target);
         
-        assertEquals(true, target.containsValue($object(A1)));
-        assertEquals(true, target.containsValue($object(B1)));
+        assertEquals(true, target.containsValue($map.item(1).value()));
+        assertEquals(true, target.containsValue($map.item(2).value()));
         
-        assertEquals(false, target.containsValue($object(A1_EQ)));
-        assertEquals(false, target.containsValue($object(A1_NE)));
-        assertEquals(false, target.containsValue($object(C1)));
+        assertEquals(false, target.containsValue($map.item(1,1).value()));
+        assertEquals(false, target.containsValue($map.item(3).value()));
     }
 	
 	@Test
-    public void basicClear(Map<TPoint, Integer> target) {
+    public void basicClear(Map<K, V> target) {
 		assertEquals(0, target.size());
 		
-		$put(target, A1, A1_NE, B1);
+        $map.list().item(1).item(1,1).item(2).into(target);
 		assertSize(3, target);
 		assertEquals(false, target.isEmpty());
 		
@@ -200,52 +198,52 @@ public final class MapTester {
 	}
     
     @Test
-    public void basicEntrySet_Contains(Map<TPoint, Integer> target) {
-        Set<Entry<TPoint, Integer>> set = target.entrySet();
+    public void basicEntrySet_Contains(Map<K, V> target) {
+        Set<Entry<K, V>> set = target.entrySet();
 		
         assertEquals(0, set.size());
 		
-        $put(target, A1, A1_NE, B1, C1);
+        $map.list().item(1).item(1,1).item(2).item(3).into(target);
 		assertEquals(4, set.size());
-        assertEquals(true, set.contains($entry(A1)));
-        assertEquals(true, set.contains($entry(A1_NE)));
-        assertEquals(true, set.contains($entry(B1)));
-        assertEquals(true, set.contains($entry(C1)));
+        assertEquals(true, set.contains($map.item(1).entry()));
+        assertEquals(true, set.contains($map.item(1,1).entry()));
+        assertEquals(true, set.contains($map.item(2).entry()));
+        assertEquals(true, set.contains($map.item(3).entry()));
         
-        assertEquals(false, set.contains($entry(D1)));
+        assertEquals(false, set.contains($map.item(4).entry()));
         assertEquals(false, set.contains(new Object()));
         
 	}
     
     @Test
-    public void basicEntrySet_Remove(Map<TPoint, Integer> target) {
-        Set<Entry<TPoint, Integer>> set = target.entrySet();
+    public void basicEntrySet_Remove(Map<K, V> target) {
+        Set<Entry<K, V>> set = target.entrySet();
 		
-        basicEntrySet_Contains(target);
+        $map.list().item(1).item(1,1).item(2).item(3).into(target);
 		
-        assertEquals(false, set.remove($entry(A1_EQ)));
-        assertEquals(true, set.remove($entry($key(A1_EQ), $value(A1))));
-        assertEquals(false, set.remove($entry(D1)));
+        assertEquals(false, set.remove($map.item(1).entry(5)));
+        assertEquals(true, set.remove($map.item(1).entry()));
+        assertEquals(false, set.remove($map.item(4).entry()));
         assertEquals(false, set.remove(new Object()));
         
-        assertEquals(false, set.contains($entry(A1)));
-        assertEquals(true, set.contains($entry(A1_NE)));
-        assertEquals(true, set.contains($entry(B1)));
-        assertEquals(true, set.contains($entry(C1)));
+        assertEquals(false, set.contains($map.item(1).entry()));
+        assertEquals(true, set.contains($map.item(1,1).entry()));
+        assertEquals(true, set.contains($map.item(2).entry()));
+        assertEquals(true, set.contains($map.item(3).entry()));
         
 	}
     
     @Test
-    public void basicEntrySet_Iterator(Map<TPoint, Integer> target) {
-        Set<Entry<TPoint, Integer>> set = target.entrySet();
+    public void basicEntrySet_Iterator(Map<K, V> target) {
+        Set<Entry<K, V>> set = target.entrySet();
 		
         assertEquals(0, set.size());
-		$put(target, A1, A1_NE, B1, C1);
+		$map.list().item(1).item(1,1).item(2).item(3).into(target);
 		assertEquals(4, set.size());
 
-        Iterator<Entry<TPoint, Integer>> iterator = set.iterator();
+        Iterator<Entry<K, V>> iterator = set.iterator();
         while(iterator.hasNext()) {
-            Entry<TPoint, Integer> entry = iterator.next();
+            Entry<K, V> entry = iterator.next();
             assertEquals(target.get(entry.getKey()), entry.getValue());
         }
         
@@ -253,57 +251,61 @@ public final class MapTester {
 	}
     
     @Test
-    public void basicEntrySet_Iterator_SetValue(Map<TPoint, Integer> target) {
-        Set<Entry<TPoint, Integer>> set = target.entrySet();
+    public void basicEntrySet_Iterator_SetValue(Map<K, V> target) {
+        Set<Entry<K, V>> set = target.entrySet();
                 
 		assertEquals(0, set.size());
-		$put(target, A1, A1_NE, B1, C1);
+		$map.list().item(1).item(1,1).item(2).item(3).into(target);
+        K k1 = $map.item(1).key();
+		K k2 = $map.item(2).key();
+        V v1 = $map.item(101).value();
+        V v2 = $map.item(102).value();
 		
-		Iterator<Entry<TPoint, Integer>> iterator = set.iterator();
+		Iterator<Entry<K, V>> iterator = set.iterator();
 		while(iterator.hasNext()) {
-			Entry<TPoint, Integer> entry = iterator.next();
-            TPoint key = entry.getKey();
-            
-			if($equals(key, A1_EQ)) {
-                entry.setValue($object(D1));
+			Entry<K, V> entry = iterator.next();
+			if(k1.equals(entry.getKey())) {
+                entry.setValue(v1);
             }
-            if($equals(key, B1)) {
-                entry.setValue($object(D2));
+            if(k2.equals(entry.getKey())) {
+                entry.setValue(v2);
             }
 		}
-		assertContains(target, A1, D1);
-		assertContains(target, B1, D2);
-		assertContains(target, A1_NE, A1_NE);
-		assertContains(target, C1, C1);
+		assertContains(target, $map.item(1).key(), v1);
+		assertContains(target, $map.item(2).key(), v2);
+		assertContains(target, $map.item(1,1));
+		assertContains(target, $map.item(3));
 	}
     
     @SuppressWarnings("unchecked")
     @Test
-    public void basicEntrySet_Iterator_Remove(Map<TPoint, Integer> target) {
-        Set<Entry<TPoint, Integer>> set = target.entrySet();
+    public void basicEntrySet_Iterator_Remove(Map<K, V> target) {
+        Set<Entry<K, V>> set = target.entrySet();
         
 		assertEquals(0, set.size());
-		$put(target, A1, A1_NE, B1, C1);
+		$map.list().item(1).item(1,1).item(2).item(3).into(target);
+        K k1 = $map.item(1).key();
+		K k2 = $map.item(2).key();
 		
-		Iterator<Entry<TPoint, Integer>> iterator = set.iterator();
+		Iterator<Entry<K, V>> iterator = set.iterator();
 		while(iterator.hasNext()) {
-			Entry<TPoint, Integer> entry = iterator.next();
-			TPoint key = entry.getKey();
-			
-            if($equals(key, A1_EQ)) {
+			Entry<K, V> entry = iterator.next();
+            K key = entry.getKey();
+            
+			if(k1.equals(key)) {
                 iterator.remove();
             }
-            if($equals(key, B1)) {
+            if(k2.equals(key)) {
                 iterator.remove();
                 QAssert.assertThrows(IllegalStateException.class, ()-> iterator.remove());
             }
 		}
         
         assertEquals(2, target.size());
-        assertNotContains(target, A1);
-        assertNotContains(target, B1);
-		assertContains(target, A1_NE, A1_NE);
-		assertContains(target, C1, C1);
+        assertNotContains(target, $map.item(1));
+        assertNotContains(target, $map.item(2));
+		assertContains(target, $map.item(1,1));
+		assertContains(target, $map.item(3));
         
         set.clear();
         assertEquals(0, target.size());
@@ -311,13 +313,13 @@ public final class MapTester {
     
     @SuppressWarnings("unchecked")
     @Test
-    public void basicEntrySet_Iterator_RemoveAll(Map<TPoint, Integer> target) {
-        Set<Entry<TPoint, Integer>> set = target.entrySet();
+    public void basicEntrySet_Iterator_RemoveAll(Map<K, V> target) {
+        Set<Entry<K, V>> set = target.entrySet();
         
 		assertEquals(0, set.size());
-        $put(target, $ukeys(1024));
+        $map.urange(1024).into(target);
             
-		Iterator<Entry<TPoint, Integer>> iterator = set.iterator();
+		Iterator<Entry<K, V>> iterator = set.iterator();
 		while(iterator.hasNext()) {
 			iterator.next();
             iterator.remove();
@@ -326,87 +328,101 @@ public final class MapTester {
 	}
     
     @Test
-    public void basicEquals(Supplier<Map<TPoint, Integer>> generator) {
-        Map<TPoint, Integer> map1 = generator.get();
-        Map<TPoint, Integer> map2 = generator.get();
-        Map<TPoint, Integer> map3 = generator.get();
-        Map<TPoint, Integer> map4 = generator.get();
-        Map<TPoint, Integer> map5 = generator.get();
-        Map<TPoint, Integer> map6 = generator.get();
-        
-        $put(map1, E1, B1, C1);
-        $put(map2, E1, B1, C1);
-        $put(map3, E1_NE, B1, C1);
-        $put(map4, B1, C1);
-        $put(map5, B1, C1, D1);
-        $put(map6, E1_NE, C1, D1);
-        
+    public void basicEquals(Supplier<Map<K, V>> generator) {
+        Map<K, V> map1 = generator.get();
+        Map<K, V> map2 = generator.get();
+        Map<K, V> map3 = generator.get();
+        Map<K, V> map4 = generator.get();
+        Map<K, V> map5 = generator.get();
+        
+        $map.list().item(5,0).item(2).item(3).into(map1);
+        $map.list().item(5,0).item(2).item(3).into(map2);
+        $map.list().item(5,1).item(2).item(3).into(map3);
+        $map.list()          .item(2).item(3).into(map4);
+        $map.list().item(5,1)        .item(3).item(4).into(map5);
+        
+        // entry(5,1) should have identical value as entry(5,0) because we want identical hashcode
+        map3.put($map.item(5,1).key(), $map.item(5,0).value());
+
         QAssert.assertEquality(map1, map2, map3, map4);
-        QAssert.assertEquality(map1, map2, map3, map6);
+        QAssert.assertEquality(map1, map2, map3, map5);
     }
     
     @Test
-    public void basicEquals_Entry(Map<TPoint, Integer> target) {
-        $put(target, E1, E1_EQ, E1_NE, B1);
+    public void basicEquals_Entry(Map<K, V> target) {
+        $map.list().item(5).item(5).item(5,1).item(2).into(target);
+        
+        // entry(5,1) should have identical value as entry(5,0) because we want identical hashcode
+        target.put($map.item(5,1).key(), $map.item(5,0).value());
         
         QAssert.assertEquality(
-            $find(target, E1), 
-            $find(target, E1_EQ), 
-            $find(target, E1_NE), 
-            $find(target, B1)
+            findEntry(target, $map.item(5).key()), 
+            findEntry(target, $map.item(5).key()), 
+            findEntry(target, $map.item(5,1).key()), 
+            findEntry(target, $map.item(2).key())
         );
     }
     
+    private Entry<K,V> findEntry(Map<K, V> target, K key) {
+        for(Entry<K,V> e : target.entrySet()) {
+            if(key.equals(e.getKey())) {
+                return e;
+            }
+        }
+        fail("Entry not found: " + key);
+        return null;
+    }
+    
     @Test
-    public void basicSerializable(Map<TPoint, Integer> target) {
-        $put(target, A1, A1_EQ, A1_NE, B1, C1);
+    public void basicSerializable(Map<K, V> target) {
+        $map.list().item(1).item(1,1).item(2).item(3).into(target);
         QAssert.assertSerializable(target);
     }
     
     @Test
-    public void basicKeySet_Contains(Map<TPoint, Integer> target) {
-        Set<TPoint> set = target.keySet();
+    public void basicKeySet_Contains(Map<K, V> target) {
+        Set<K> set = target.keySet();
 		
         assertEquals(0, set.size());
 		
-        $put(target, A1, A1_NE, B1, C1);
+        $map.list().item(1).item(1,1).item(2).item(3).into(target);
 		assertEquals(4, set.size());
-        assertEquals(true, set.contains($key(A1)));
-        assertEquals(true, set.contains($key(A1_NE)));
-        assertEquals(true, set.contains($key(B1)));
-        assertEquals(true, set.contains($key(C1)));
+        assertEquals(true, set.contains($map.item(1).key()));
+        assertEquals(true, set.contains($map.item(1,1).key()));
+        assertEquals(true, set.contains($map.item(2).key()));
+        assertEquals(true, set.contains($map.item(3).key()));
         
-        assertEquals(false, set.contains($key(D1)));
+        assertEquals(false, set.contains($map.item(5).key()));
         assertEquals(false, set.contains(new Object()));
 	}
     
     @Test
-    public void basicKeySet_Remove(Map<TPoint, Integer> target) {
-        Set<TPoint> set = target.keySet();
+    public void basicKeySet_Remove(Map<K, V> target) {
+        Set<K> set = target.keySet();
 		
         basicEntrySet_Contains(target);
 		
-        assertEquals(true, set.remove($key(A1_EQ)));
-        assertEquals(false, set.remove($key(D1)));
+        assertEquals(true, set.remove($map.item(1).key()));
+        assertEquals(false, set.remove($map.item(4).key()));
         assertEquals(false, set.remove(new Object()));
         
-        assertEquals(false, set.contains($key(A1)));
-        assertEquals(true, set.contains($key(A1_NE)));
-        assertEquals(true, set.contains($key(B1)));
-        assertEquals(true, set.contains($key(C1)));
+        assertEquals(false, set.contains($map.item(1).key()));
+        assertEquals(true, set.contains($map.item(1,1).key()));
+        assertEquals(true, set.contains($map.item(2).key()));
+        assertEquals(true, set.contains($map.item(3).key()));
 	}
         
     @Test
-    public void basicKeySet_Iterator(Map<TPoint, Integer> target) {
-        Set<TPoint> set = target.keySet();
+    public void basicKeySet_Iterator(Map<K, V> target) {
+        Set<K> set = target.keySet();
 		
         assertEquals(0, set.size());
-		$put(target, A1, A1_NE, B1, C1);
+		$map.list().item(1).item(1,1).item(2).item(3).into(target);
 		assertEquals(4, set.size());
 
-        Iterator<TPoint> iterator = set.iterator();
+        Iterator<K> iterator = set.iterator();
         while(iterator.hasNext()) {
-            TPoint key = iterator.next();
+            K key = iterator.next();
             assertEquals(true, target.containsKey(key));
         }
         
@@ -415,79 +431,80 @@ public final class MapTester {
     
     @SuppressWarnings("unchecked")
     @Test
-    public void basicKeySet_Iterator_Remove(Map<TPoint, Integer> target) {
-        Set<TPoint> set = target.keySet();
+    public void basicKeySet_Iterator_Remove(Map<K, V> target) {
+        Set<K> set = target.keySet();
         
 		assertEquals(0, set.size());
-		$put(target, A1, A1_NE, B1, C1);
-		
-		Iterator<TPoint> iterator = set.iterator();
+		$map.list().item(1).item(1,1).item(2).item(3).into(target);
+		K k1 = $map.item(1).key();
+		K k2 = $map.item(2).key();
+        
+		Iterator<K> iterator = set.iterator();
 		while(iterator.hasNext()) {
-			TPoint key = iterator.next();
-			
-            if($equals(key, A1_EQ)) {
+			K key = iterator.next();
+			if(k1.equals(key)) {
                 iterator.remove();
             }
-            if($equals(key, B1)) {
+            if(k2.equals(key)) {
                 iterator.remove();
                 QAssert.assertThrows(IllegalStateException.class, ()-> iterator.remove());
             }
 		}
         
         assertEquals(2, target.size());
-        assertNotContains(target, A1);
-        assertNotContains(target, B1);
-		assertContains(target, A1_NE, A1_NE);
-		assertContains(target, C1, C1);
+        assertNotContains(target, $map.item(1));
+        assertNotContains(target, $map.item(2));
+		assertContains(target, $map.item(1,1));
+		assertContains(target, $map.item(3));
         
         set.clear();
         assertEquals(0, target.size());
 	}
     
     @Test
-    public void basicValues_Contains(Map<TPoint, Integer> target) {
-        Collection<Integer> set = target.values();
+    public void basicValues_Contains(Map<K, V> target) {
+        Collection<V> set = target.values();
 		
         assertEquals(0, set.size());
 		
-        $put(target, A1, A1_NE, B1, C1);
+        $map.list().item(1).item(1,1).item(2).item(3).into(target);
 		assertEquals(4, set.size());
-        assertEquals(true, set.contains($object(A1)));
-        assertEquals(true, set.contains($object(A1_NE)));
-        assertEquals(true, set.contains($object(B1)));
-        assertEquals(true, set.contains($object(C1)));
+        assertEquals(true, set.contains($map.item(1).value()));
+        assertEquals(true, set.contains($map.item(1,1).value()));
+        assertEquals(true, set.contains($map.item(2).value()));
+        assertEquals(true, set.contains($map.item(3).value()));
         
-        assertEquals(false, set.contains($object(D1)));
+        assertEquals(false, set.contains($map.item(4).value()));
         assertEquals(false, set.contains(new Object()));
 	}
     
     @Test
-    public void basicValues_Remove(Map<TPoint, Integer> target) {
-        Collection<Integer> set = target.values();
+    public void basicValues_Remove(Map<K, V> target) {
+        Collection<V> set = target.values();
 		
         basicValues_Contains(target);
 		
-        assertEquals(true, set.remove($object(A1)));
-        assertEquals(false, set.remove($object(D1)));
+        assertEquals(true, set.remove($map.item(1).value()));
+        assertEquals(false, set.remove($map.item(4).value()));
         assertEquals(false, set.remove(new Object()));
         
-        assertEquals(false, set.contains($object(A1)));
-        assertEquals(true, set.contains($object(A1_NE)));
-        assertEquals(true, set.contains($object(B1)));
-        assertEquals(true, set.contains($object(C1)));
+        assertEquals(false, set.contains($map.item(1).value()));
+        assertEquals(true, set.contains($map.item(1,1).value()));
+        assertEquals(true, set.contains($map.item(2).value()));
+        assertEquals(true, set.contains($map.item(3).value()));
 	}
     
     @Test
-    public void basicValues_Iterator(Map<TPoint, Integer> target) {
-        Collection<Integer> set = target.values();
+    public void basicValues_Iterator(Map<K, V> target) {
+        Collection<V> set = target.values();
 		
         assertEquals(0, set.size());
-		$put(target, A1, A1_NE, B1, C1);
+		$map.list().item(1).item(1,1).item(2).item(3).into(target);
 		assertEquals(4, set.size());
 
-        Iterator<Integer> iterator = set.iterator();
+        Iterator<V> iterator = set.iterator();
         while(iterator.hasNext()) {
-            Integer var = iterator.next();
+            V var = iterator.next();
             assertEquals(true, target.containsValue(var));
         }
         
@@ -496,58 +513,62 @@ public final class MapTester {
     
     @SuppressWarnings("unchecked")
     @Test
-    public void basicValues_Iterator_Remove(Map<TPoint, Integer> target) {
-        Collection<Integer> set = target.values();
+    public void basicValues_Iterator_Remove(Map<K, V> target) {
+        Collection<V> set = target.values();
         
 		assertEquals(0, set.size());
-		$put(target, A1, A1_NE, B1, C1);
+		$map.list().item(1).item(1,1).item(2).item(3).into(target);
 		
-		Iterator<Integer> iterator = set.iterator();
+		Iterator<V> iterator = set.iterator();
 		while(iterator.hasNext()) {
-			Integer var = iterator.next();
+			V var = iterator.next();
 			
-            if(var.equals($object(A1))) {
+            if(var.equals($map.item(1).value())) {
                 iterator.remove();
             }
-            if(var.equals($object(B1))) {
+            if(var.equals($map.item(2).value())) {
                 iterator.remove();
                 QAssert.assertThrows(IllegalStateException.class, ()-> iterator.remove());
             }
 		}
         
         assertEquals(2, target.size());
-        assertNotContains(target, A1);
-        assertNotContains(target, B1);
-		assertContains(target, A1_NE, A1_NE);
-		assertContains(target, C1, C1);
+        assertNotContains(target, $map.item(1));
+        assertNotContains(target, $map.item(2));
+		assertContains(target, $map.item(1,1));
+		assertContains(target, $map.item(3));
         
         set.clear();
         assertEquals(0, target.size());
 	}
     
-    private static void assertRemove(Map<TPoint, Integer> target, ValueEnum key, ValueEnum prev) {
+    private void assertRemove(Map<K,V> target, TItem<K,V> item) {
         int size = target.size();
-        assertEquals($object(prev), target.remove($key(key)));
+        assertEquals(item.valueInt(), target.remove(item.key()));
         assertEquals(size-1, target.size());
     }
     
-    private static void assertNotRemove(Map<TPoint, Integer> target, ValueEnum key) {
+    private void assertNotRemove(Map<K,V> target, TItem<K,V> item) {
         int size = target.size();
-        assertEquals(null, target.remove($key(key)));
+        assertEquals(null, target.remove(item.key()));
         assertEquals(size, target.size());
     }
+	
+	private void assertContains(Map<K,V> target, K key, V value) {
+        assertEquals(true, target.containsKey(key));
+        assertEquals(value, target.get(key));
+    }
     
-    private static void assertContains(Map<TPoint, Integer> target, ValueEnum key, ValueEnum value) {
-        assertEquals(true, target.containsKey($key(key)));
-        assertEquals($object(value), target.get($key(key)));
+    private void assertContains(Map<K,V> target, TItem<K,V> item) {
+		assertContains(target, item.key(), item.value());
     }
     
-    private static void assertNotContains(Map<TPoint, Integer> target, ValueEnum key) {
-        assertEquals(false, target.containsKey($key(key)));
-        assertEquals(null, target.get($key(key)));
+    private void assertNotContains(Map<K,V> target, TItem<K,V> item) {
+        assertEquals(false, target.containsKey(item.key()));
+        assertEquals(null, target.get(item.key()));
     }
 	
-	private static void assertSize(int size, Map<TPoint, Integer> target) {
+	private void assertSize(int size, Map<K,V> target) {
 		assertEquals(size, target.size());
 		assertEquals(size, target.entrySet().size());
 		assertEquals(size, target.keySet().size());

+ 29 - 31
assira/src/test/java/net/ranides/assira/collection/suite/SetTester.java

@@ -9,10 +9,8 @@ package net.ranides.assira.collection.suite;
 import java.util.NoSuchElementException;
 import java.util.SortedSet;
 import net.ranides.assira.collection.arrays.ArrayUtils;
-import net.ranides.assira.collection.mockup.ValueGenerator;
-import net.ranides.assira.collection.mockup.ValueEnum;
-import static net.ranides.assira.collection.mockup.ValueEnum.*;
 import net.ranides.assira.junit.QAssert;
+import net.ranides.assira.test.TGenerator;
 import static org.junit.Assert.*;
 import org.junit.Ignore;
 
@@ -22,21 +20,21 @@ import org.junit.Ignore;
  */
 public class SetTester {
     
-    public static <V> void checkHead(ValueGenerator<V, ValueEnum> generator, SortedSet<V> target, V[] content) {
+    public static <V> void checkHead(TGenerator<V> generator, SortedSet<V> target, V[] content) {
         checkHead(true, generator, target, content);
     }
     
-    private static <V> void checkHead(boolean nested, ValueGenerator<V, ValueEnum> generator, SortedSet<V> target, V[] content) {
+    private static <V> void checkHead(boolean nested, TGenerator<V>  generator, SortedSet<V> target, V[] content) {
         int n = content.length;
-        assertEquals(0, target.headSet(generator.object(SUB_MIN)).size());
-        assertEquals(n, target.headSet(generator.object(SUB_MAX)).size());
+        assertEquals(0, target.headSet(generator.value(0)).size());
+        assertEquals(n, target.headSet(generator.value(1000)).size());
         checkRange(target, content);
         
-        assertEquals(0, target.headSet(generator.object(SUB_MIN)).headSet(generator.object(SUB_MAX)).size());
+        assertEquals(0, target.headSet(generator.value(0)).headSet(generator.value(1000)).size());
 
         for(int i=0; i<n; i++) {
             V point = content[i];
-            V[] exp = ArrayUtils.head(content, point, generator.comparator());
+            V[] exp = ArrayUtils.head(content, point);
             SortedSet<V> map = target.headSet(point);
             assertEquals(exp.length, map.size());
             if(nested) {
@@ -48,19 +46,19 @@ public class SetTester {
     }
     
     @Ignore
-    public static <V> void checkTail(ValueGenerator<V, ValueEnum> generator, SortedSet<V> target, V[] content) {
+    public static <V> void checkTail(TGenerator<V> generator, SortedSet<V> target, V[] content) {
         checkTail(true, generator, target, content);
     }
     
-    private static <V> void checkTail(boolean nested, ValueGenerator<V, ValueEnum> generator, SortedSet<V> target, V[] content) {
+    private static <V> void checkTail(boolean nested, TGenerator<V> generator, SortedSet<V> target, V[] content) {
         int n = content.length;
-        assertEquals(n, target.tailSet(generator.object(SUB_MIN)).size());
-        assertEquals(0, target.tailSet(generator.object(SUB_MAX)).size());
+        assertEquals(n, target.tailSet(generator.value(0)).size());
+        assertEquals(0, target.tailSet(generator.value(1000)).size());
         checkRange(target, content);
         
         for(int i=0; i<n; i++) {
             V entry = content[i];
-            V[] exp = ArrayUtils.tail(content, entry, generator.comparator());
+            V[] exp = ArrayUtils.tail(content, entry);
             SortedSet<V> map = target.tailSet(entry);
             assertEquals(exp.length, map.size());
             if(nested) {
@@ -72,31 +70,31 @@ public class SetTester {
     }
     
     @Ignore
-    public static <V> void checkSub(ValueGenerator<V, ValueEnum> generator, SortedSet<V> target, V[] content) {
+    public static <V> void checkSub(TGenerator<V> generator, SortedSet<V> target, V[] content) {
         checkSub(true, generator, target, content);
     }
     
-    private static <V> void checkSub(boolean nested, ValueGenerator<V, ValueEnum> generator, SortedSet<V> target, V[] content) {
-        checkSub(nested, generator, target, A1, SUB_MAX, content);
-        checkSub(nested, generator, target, C1, SUB_MAX, content);
+    private static <V> void checkSub(boolean nested, TGenerator<V> generator, SortedSet<V> target, V[] content) {
+        checkSub(nested, generator, target, 3, 1000, content);
+        checkSub(nested, generator, target, 5, 1000, content);
             
-        checkSub(nested, generator, target, A1, E1, content);
-        checkSub(nested, generator, target, A1, D1, content);
-        checkSub(nested, generator, target, B1, D1, content);
-        checkSub(nested, generator, target, C1, D1, content);
+        checkSub(nested, generator, target, 3, 7, content);
+        checkSub(nested, generator, target, 3, 6, content);
+        checkSub(nested, generator, target, 4, 6, content);
+        checkSub(nested, generator, target, 5, 6, content);
 
-        checkSub(nested, generator, target, D1, E1, content);
-        checkSub(nested, generator, target, D1, D1, content);
+        checkSub(nested, generator, target, 6, 5, content);
+        checkSub(nested, generator, target, 6, 6, content);
         
-        checkSub(nested, generator, target, SUB_MIN, A1, content);
-        checkSub(nested, generator, target, SUB_MIN, C1, content);
-        checkSub(nested, generator, target, SUB_MIN, SUB_MAX, content);
+        checkSub(nested, generator, target, 0, 3, content);
+        checkSub(nested, generator, target, 0, 5, content);
+        checkSub(nested, generator, target, 0, 1000, content);
     }
     
-    private static <V> void checkSub(boolean nested, ValueGenerator<V, ValueEnum> generator, SortedSet<V> target, ValueEnum ibegin, ValueEnum iend, V[] content) {
-        V begin = generator.object(ibegin);
-        V end = generator.object(iend);
-        V[] exp = ArrayUtils.slice(content, begin, end, generator.comparator());
+    private static <V> void checkSub(boolean nested, TGenerator<V> generator, SortedSet<V> target, int ibegin, int iend, V[] content) {
+        V begin = generator.value(ibegin);
+        V end = generator.value(iend);
+        V[] exp = ArrayUtils.slice(content, begin, end);
         SortedSet<V> map = target.subSet(begin, end);
         assertEquals(exp.length, map.size());
         checkRange(map, exp);

+ 12 - 9
assira/src/test/java/net/ranides/assira/collection/suite/SortedLookupTester.java

@@ -8,12 +8,12 @@ package net.ranides.assira.collection.suite;
 
 import java.util.NoSuchElementException;
 import java.util.SortedSet;
+import javax.annotation.Resource;
 import net.ranides.assira.collection.lookups.Lookup.LookupEntry;
 import net.ranides.assira.collection.lookups.SortedLookup;
-import net.ranides.assira.collection.mockup.TPoint;
-import static net.ranides.assira.collection.mockup.ValueEnum.*;
-import static net.ranides.assira.collection.mockup.TPointUtils.*;
+
 import net.ranides.assira.junit.QAssert;
+import net.ranides.assira.test.TMap;
 import static org.junit.Assert.*;
 import org.junit.Test;
 
@@ -22,20 +22,23 @@ import org.junit.Test;
  * @author Ranides Atterwim <ranides@gmail.com>
  */
 @SuppressWarnings("PMD.MethodNameRules")
-public final class SortedLookupTester {
+public final class SortedLookupTester<K> {
+    
+    @Resource(name = "map!")
+    private TMap<K,Integer> $map;
     
     @Test
-    public void basicBounds_EntrySet(SortedLookup<TPoint> target) {
-        SortedSet<LookupEntry<TPoint>> set = target.fastEntrySet();
+    public void basicBounds_EntrySet(SortedLookup<K> target) {
+        SortedSet<LookupEntry<K>> set = target.fastEntrySet();
         QAssert.assertThrows(NoSuchElementException.class, ()->
             set.first()
         );
         QAssert.assertThrows(NoSuchElementException.class, ()->
             set.last()
         );
-        $put(target, B1, E1, C1, A1, D1);
-        assertEquals( set.first(), $entry(A1) );
-        assertEquals( set.last(), $entry(E1) );
+        $map.list(2,5,3,1,4).into(target);
+        assertEquals( set.first(), $map.item(1).entry() );
+        assertEquals( set.last(), $map.item(5).entry() );
     }
     
 //        

+ 129 - 118
assira/src/test/java/net/ranides/assira/collection/suite/SortedMapTester.java

@@ -12,12 +12,13 @@ import java.util.NoSuchElementException;
 import java.util.Set;
 import java.util.SortedMap;
 import java.util.SortedSet;
+import javax.annotation.Resource;
 import net.ranides.assira.collection.arrays.ArrayUtils;
-import net.ranides.assira.collection.mockup.TPoint;
-import static net.ranides.assira.collection.mockup.ValueEnum.*;
-import static net.ranides.assira.collection.mockup.TPointUtils.*;
 import net.ranides.assira.collection.sets.ASortedSet;
 import net.ranides.assira.junit.QAssert;
+import net.ranides.assira.test.TMap;
+import net.ranides.assira.test.TMap.TItem;
+import net.ranides.assira.test.TMap.TItems;
 import static org.junit.Assert.*;
 import org.junit.Test;
 
@@ -26,80 +27,83 @@ import org.junit.Test;
  * @author Ranides Atterwim <ranides@gmail.com>
  */
 @SuppressWarnings("PMD.MethodNameRules")
-public final class SortedMapTester {
+public final class SortedMapTester<K,V> {
+    
+    @Resource(name = "map!")
+    private TMap<K,V> $map;
     
     @Test
-    public void basicBounds(SortedMap<TPoint, Integer> target) {
+    public void basicBounds(SortedMap<K, V> target) {
         QAssert.assertThrows(NoSuchElementException.class, ()->
             target.firstKey()
         );
         QAssert.assertThrows(NoSuchElementException.class, ()->
             target.lastKey()
         );
-        $put(target, B1, E1, C1, A1, D1);
-        assertEquals($key(A1), target.firstKey());
-        assertEquals($key(E1), target.lastKey());
+        $map.list(2,5,3,1,4).into(target);
+        assertEquals($map.item(1).key(), target.firstKey());
+        assertEquals($map.item(5).key(), target.lastKey());
     }
     
     @Test
-    public void basicBounds_KeySet(SortedMap<TPoint, Integer> target) {
-        SortedSet<TPoint> set = (SortedSet<TPoint>)target.keySet();
+    public void basicBounds_KeySet(SortedMap<K, V> target) {
+        SortedSet<K> set = (SortedSet<K>)target.keySet();
         QAssert.assertThrows(NoSuchElementException.class, ()->
             set.first()
         );
         QAssert.assertThrows(NoSuchElementException.class, ()->
             set.last()
         );
-        $put(target, B1, E1, C1, A1, D1);
-        assertEquals($key(A1), set.first());
-        assertEquals($key(E1), set.last());
+        $map.list(2,5,3,1,4).into(target);
+        assertEquals($map.item(1).key(), set.first());
+        assertEquals($map.item(5).key(), set.last());
     }
     
     @Test
-    public void basicBounds_EntrySet(SortedMap<TPoint, Integer> target) {
-        SortedSet<Entry<TPoint, Integer>> set = (SortedSet<Entry<TPoint, Integer>>)target.entrySet();
+    public void basicBounds_EntrySet(SortedMap<K, V> target) {
+        SortedSet<Entry<K, V>> set = (SortedSet<Entry<K, V>>)target.entrySet();
         QAssert.assertThrows(NoSuchElementException.class, ()->
             set.first()
         );
         QAssert.assertThrows(NoSuchElementException.class, ()->
             set.last()
         );
-        $put(target, B1, E1, C1, A1, D1);
-        assertEquals( set.first(), $entry(A1) );
-        assertEquals( set.last(), $entry(E1) );
+        $map.list(2,5,3,1,4).into(target);
+        assertEquals($map.item(1).entry(), set.first());
+        assertEquals($map.item(5).entry(), set.last());
     }
     
     @Test
-    public void basicMap_Head(SortedMap<TPoint, Integer> target) {
+    public void basicMap_Head(SortedMap<K, V> target) {
         checkHead(true, target);
-        $put(target, B1, E1, C1, A1, D1);
-        checkHead(true, target, $keys(A1, B1, C1, D1, E1));
+        $map.list(4,7,5,3,6).into(target);
+        checkHead(true, target, $map.list(3,4,5,6,7).keys());
     }
     
     @Test
-    public void basicMap_Tail(SortedMap<TPoint, Integer> target) {
+    public void basicMap_Tail(SortedMap<K, V> target) {
         checkTail(true, target);
-        $put(target, B1, E1, C1, A1, D1);
-        checkTail(true, target, $keys(A1, B1, C1, D1, E1));
+        $map.list(4,7,5,3,6).into(target);
+        checkTail(true, target, $map.list(3,4,5,6,7).keys());
     }
     
     @Test
-    public void basicMap_Sub(SortedMap<TPoint, Integer> target) {
+    public void basicMap_Sub(SortedMap<K, V> target) {
         checkTail(true, target);
-        $put(target, B1, E1, C1, A1, D1);
-        checkSub(true, target, $keys(A1, B1, C1, D1, E1));
+        $map.list(4,7,5,3,6).into(target);
+        checkSub(true, target, $map.list(3,4,5,6,7).keys());
     }
     
-    private static void checkHead(boolean nested, SortedMap<TPoint, Integer> target, TPoint... content) {
+    private void checkHead(boolean nested, SortedMap<K, V> target, K... content) {
         int n = content.length;
-        assertEquals(0, target.headMap($key(SUB_MIN)).size());
-        assertEquals(n, target.headMap($key(SUB_MAX)).size());
+        assertEquals(0, target.headMap($map.item(0).key()).size());
+        assertEquals(n, target.headMap($map.item(9).key()).size());
         checkRange(target, content);
         
         for(int i=0; i<n; i++) {
-            TPoint point = content[i];
-            TPoint[] exp = ArrayUtils.head(content, point, TPoint.SUM);
-            SortedMap<TPoint, Integer> map = target.headMap(point);
+            K point = content[i];
+            K[] exp = ArrayUtils.head(content, point);
+            SortedMap<K, V> map = target.headMap(point);
             assertEquals(exp.length, map.size());
             if(nested) {
                 checkHead(false, map, exp);
@@ -109,16 +113,16 @@ public final class SortedMapTester {
         }
     }
     
-    private static void checkTail(boolean nested, SortedMap<TPoint, Integer> target, TPoint... content) {
+    private void checkTail(boolean nested, SortedMap<K, V> target, K... content) {
         int n = content.length;
-        assertEquals(n, target.tailMap($key(SUB_MIN)).size());
-        assertEquals(0, target.tailMap($key(SUB_MAX)).size());
+        assertEquals(n, target.tailMap($map.item(0).key()).size());
+        assertEquals(0, target.tailMap($map.item(9).key()).size());
         checkRange(target, content);
         
         for(int i=0; i<n; i++) {
-            TPoint point = content[i];
-            TPoint[] exp = ArrayUtils.tail(content, point, TPoint.SUM);
-            SortedMap<TPoint, Integer> map = target.tailMap(point);
+            K point = content[i];
+            K[] exp = ArrayUtils.tail(content, point);
+            SortedMap<K, V> map = target.tailMap(point);
             assertEquals(exp.length, map.size());
             if(nested) {
                 checkHead(false, map, exp);
@@ -128,27 +132,27 @@ public final class SortedMapTester {
         }
     }
     
-    private static void checkSub(boolean nested, SortedMap<TPoint, Integer> target, TPoint... content) {
-        checkSub(nested, target, $key(A1), $key(SUB_MAX), content);
-        checkSub(nested, target, $key(C1), $key(SUB_MAX), content);
+    private void checkSub(boolean nested, SortedMap<K, V> target, K... content) {
+        checkSub(nested, target, $map.item(3), $map.item(9), content);
+        checkSub(nested, target, $map.item(5), $map.item(9), content);
             
-        checkSub(nested, target, $key(A1), $key(E1), content);
-        checkSub(nested, target, $key(A1), $key(D1), content);
-        checkSub(nested, target, $key(B1), $key(D1), content);
-        checkSub(nested, target, $key(C1), $key(D1), content);
+        checkSub(nested, target, $map.item(3), $map.item(7), content);
+        checkSub(nested, target, $map.item(3), $map.item(6), content);
+        checkSub(nested, target, $map.item(4), $map.item(6), content);
+        checkSub(nested, target, $map.item(5), $map.item(6), content);
 
-        checkSub(nested, target, $key(D1), $key(E1), content);
-        checkSub(nested, target, $key(D1), $key(D1), content);
+        checkSub(nested, target, $map.item(6), $map.item(7), content);
+        checkSub(nested, target, $map.item(6), $map.item(6), content);
         
-        checkSub(nested, target, $key(SUB_MIN), $key(A1), content);
-        checkSub(nested, target, $key(SUB_MIN), $key(C1), content);
-        checkSub(nested, target, $key(SUB_MIN), $key(SUB_MAX), content);
+        checkSub(nested, target, $map.item(0), $map.item(3), content);
+        checkSub(nested, target, $map.item(0), $map.item(5), content);
+        checkSub(nested, target, $map.item(0), $map.item(9), content);
     }
     
-    private static void checkSub(boolean nested, SortedMap<TPoint, Integer> target, TPoint begin, TPoint end, TPoint[] content) {
-        TPoint[] exp = ArrayUtils.slice(content, begin, end, TPoint.SUM);
+    private void checkSub(boolean nested, SortedMap<K, V> target, TItem<K,V> begin, TItem<K,V> end, K[] content) {
+        K[] exp = ArrayUtils.slice(content, begin.key(), end.key());
         
-        SortedMap<TPoint, Integer> map = target.subMap(begin, end);
+        SortedMap<K, V> map = target.subMap(begin.key(), end.key());
         assertEquals(exp.length, map.size());
         checkRange(map, exp);
        
@@ -159,7 +163,7 @@ public final class SortedMapTester {
         }
     }
     
-    private static <V> void checkRange(SortedMap<TPoint, Integer> target, TPoint[] content) {
+    private <V> void checkRange(SortedMap<K, V> target, K[] content) {
         if(content.length > 0) {
             assertEquals(content[0], target.firstKey());
             assertEquals(content[content.length-1], target.lastKey());
@@ -170,105 +174,112 @@ public final class SortedMapTester {
     }
     
     @Test
-    public void basicKeys_Head(SortedMap<TPoint, Integer> target) {
-        SetTester.checkHead(KEYS, sort(target.keySet()), $keys());
-        $put(target, B1, E1, C1, A1, D1);
-        SetTester.checkHead(KEYS, sort(target.keySet()), $keys(A1, B1, C1, D1, E1));
+    public void basicKeys_Head(SortedMap<K, V> target) {
+        SetTester.checkHead($map.keys(), sort(target.keySet()), $map.list().keys());
+        $map.list(4, 7, 5, 3, 6).into(target);
+        SetTester.checkHead($map.keys(), sort(target.keySet()), $map.list(3, 4, 5, 6, 7).keys());
     }
     
     @Test
-    public void basicKeys_Tail(SortedMap<TPoint, Integer> target) {
-        SetTester.checkTail(KEYS, sort(target.keySet()), $keys());
-        $put(target, B1, E1, C1, A1, D1);
-        SetTester.checkTail(KEYS, sort(target.keySet()), $keys(A1, B1, C1, D1, E1));
+    public void basicKeys_Tail(SortedMap<K, V> target) {
+        SetTester.checkTail($map.keys(), sort(target.keySet()), $map.list().keys());
+        $map.list(4, 7, 5, 3, 6).into(target);
+        SetTester.checkTail($map.keys(), sort(target.keySet()), $map.list(3, 4, 5, 6, 7).keys());
     }
     
     @Test
-    public void basicKeys_Sub(SortedMap<TPoint, Integer> target) {
-        SetTester.checkTail(KEYS, sort(target.keySet()), $keys());
-        $put(target, B1, E1, C1, A1, D1);
-        SetTester.checkTail(KEYS, sort(target.keySet()), $keys(A1, B1, C1, D1, E1));
+    public void basicKeys_Sub(SortedMap<K, V> target) {
+        SetTester.checkTail($map.keys(), sort(target.keySet()), $map.list().keys());
+        $map.list(4, 7, 5, 3, 6).into(target);
+        SetTester.checkTail($map.keys(), sort(target.keySet()), $map.list(3, 4, 5, 6, 7).keys());
     }
     
     @Test
-    public void basicEntries_Head(SortedMap<TPoint, Integer> target) {
-        SetTester.checkHead(ENTRIES, sort(target.entrySet()), $entries());
-        $put(target, B1, E1, C1, A1, D1);
-        SetTester.checkHead(ENTRIES, sort(target.entrySet()), $entries(A1, B1, C1, D1, E1));
+    public void basicEntries_Head(SortedMap<K, V> target) {
+        SetTester.checkHead($map.entries(), sort(target.entrySet()), $map.list().entries());
+        $map.list(4, 7, 5, 3, 6).into(target);
+        SetTester.checkHead($map.entries(), sort(target.entrySet()), $map.list(3, 4, 5, 6, 7).entries());
     }
     
     @Test
-    public void basicEntries_Tail(SortedMap<TPoint, Integer> target) {
-        SetTester.checkTail(ENTRIES, sort(target.entrySet()), $entries());
-        $put(target, B1, E1, C1, A1, D1);
-        SetTester.checkTail(ENTRIES, sort(target.entrySet()), $entries(A1, B1, C1, D1, E1));
+    public void basicEntries_Tail(SortedMap<K, V> target) {
+        SetTester.checkTail($map.entries(), sort(target.entrySet()), $map.list().entries());
+        $map.list(4, 7, 5, 3, 6).into(target);
+        SetTester.checkTail($map.entries(), sort(target.entrySet()), $map.list(3, 4, 5, 6, 7).entries());
     }
     
     @Test
-    public void basicEntries_Sub(SortedMap<TPoint, Integer> target) {
-        SetTester.checkSub(ENTRIES, sort(target.entrySet()), $entries());
-        $put(target, B1, E1, C1, A1, D1);
-        SetTester.checkSub(ENTRIES, sort(target.entrySet()), $entries(A1, B1, C1, D1, E1));
+    public void basicEntries_Sub(SortedMap<K, V> target) {
+        SetTester.checkSub($map.entries(), sort(target.entrySet()), $map.list().entries());
+        $map.list(4, 7, 5, 3, 6).into(target);
+        SetTester.checkSub($map.entries(), sort(target.entrySet()), $map.list(3, 4, 5, 6, 7).entries());
     }
     
     @SuppressWarnings("unchecked")
     @Test
-    public void basicIterator(SortedMap<TPoint, Integer> target) {
-        IteratorTester.basicIterator((ListIterator)target.keySet().iterator(), 0, $keys());
-        IteratorTester.basicIterator((ListIterator)target.entrySet().iterator(), 0, $entries());
-        IteratorTester.basicIterator((ListIterator)target.values().iterator(), 0, $objects());
+    public void basicIterator(SortedMap<K, V> target) {
+        TItems<K,V> list1 = $map.list();
+        TItems<K,V> list2 = $map.list(4, 7, 5, 3, 6);
+        
+        IteratorTester.basicIterator((ListIterator)target.keySet().iterator(), 0, list1.keys());
+        IteratorTester.basicIterator((ListIterator)target.entrySet().iterator(), 0, list1.entries());
+        IteratorTester.basicIterator((ListIterator)target.values().iterator(), 0, list1.values());
         
-        $put(target, B1, E1, C1, A1, D1);
+        list2.into(target);
         
-        IteratorTester.basicIterator((ListIterator)target.keySet().iterator(), 0, $keys(A1, B1, C1, D1, E1));
-        IteratorTester.basicIterator((ListIterator)target.entrySet().iterator(), 0, $entries(A1, B1, C1, D1, E1));
-        IteratorTester.basicIterator((ListIterator)target.values().iterator(), 0, $objects(A1, B1, C1, D1, E1));
+        IteratorTester.basicIterator((ListIterator)target.keySet().iterator(), 0, list2.keys());
+        IteratorTester.basicIterator((ListIterator)target.entrySet().iterator(), 0, list2.entries());
+        IteratorTester.basicIterator((ListIterator)target.values().iterator(), 0, list2.values());
     }
     
     @SuppressWarnings("unchecked")
     @Test
-    public void basicIteratorFrom(SortedMap<TPoint, Integer> target) {
-        IteratorTester.basicIterator((ListIterator)sort(target.keySet()).iterator($key(B1)), 0, $keys());
-        IteratorTester.basicIterator((ListIterator)sort(target.entrySet()).iterator($entry(B1)), 0, $entries());
+    public void basicIteratorFrom(SortedMap<K, V> target) {
+        TItems<K,V> list1 = $map.list();
+        TItems<K,V> list2 = $map.list(4, 7, 5, 3, 6);
+        TItem<K,V> item = $map.item(4);
+        
+        IteratorTester.basicIterator((ListIterator)sort(target.keySet()).iterator(item.key()), 0, list1.keys());
+        IteratorTester.basicIterator((ListIterator)sort(target.entrySet()).iterator(item.entry()), 0, list1.entries());
         
-        $put(target, B1, E1, C1, A1, D1);
+        $map.list(4, 7, 5, 3, 6).into(target);
         
-        IteratorTester.basicIterator((ListIterator)sort(target.keySet()).iterator($key(B1)), 2, $keys(A1, B1, C1, D1, E1));
-        IteratorTester.basicIterator((ListIterator)sort(target.entrySet()).iterator($entry(B1)), 2, $entries(A1, B1, C1, D1, E1));
+        IteratorTester.basicIterator((ListIterator)sort(target.keySet()).iterator(item.key()), 2, list2.keys());
+        IteratorTester.basicIterator((ListIterator)sort(target.entrySet()).iterator(item.entry()), 2, list2.entries());
     }
     
     @Test
-    public void basicSubMap_Put(SortedMap<TPoint, Integer> target) {
-        $put(target, B1, E1, A1, D1);
-        SortedMap<TPoint, Integer> map = target.subMap($key(A1), $key(E1));
+    public void basicSubMap_Put(SortedMap<K, V> target) {
+        $map.list(4, 7, 3, 6).into(target);
+        SortedMap<K, V> map = target.subMap($map.item(3).key(), $map.item(7).key());
         assertEquals(3, map.size());
         
-        assertNull( map.put($key(C1), $object(C1)) );
+        assertNull( map.put($map.item(5).key(), $map.item(5).value()) );
         
-        assertTrue( map.containsKey($key(C1)));
-        assertTrue( target.containsKey($key(C1)));
+        assertTrue( map.containsKey($map.item(5).key()));
+        assertTrue( target.containsKey($map.item(5).key()));
         assertEquals(4, map.size());
         assertEquals(5, target.size());
         
-        assertEquals($object(D1), map.put($key(D1), $object(D4)));
+        assertEquals($map.item(6).value(), map.put($map.item(6).key(), $map.item(6).value()));
         assertEquals(4, map.size());
         assertEquals(5, target.size());
-        assertEquals($object(D4), map.get($key(D1)));
-        assertEquals($object(D4), target.get($key(D1)));
+        assertEquals($map.item(6).value(), map.get($map.item(6).key()));
+        assertEquals($map.item(6).value(), target.get($map.item(6).key()));
         
         QAssert.assertThrows(IllegalArgumentException.class, ()->
-            map.put($key(SUB_MAX), $object(SUB_MAX))
+            map.put($map.item(20).key(), $map.item(20).value())
         );
         QAssert.assertThrows(IllegalArgumentException.class, ()->
-            map.put($key(SUB_MIN), $object(SUB_MIN))
+            map.put($map.item(0).key(), $map.item(0).value())
         );
         
     }
     
     @Test
-    public void basicSubMap_Clear(SortedMap<TPoint, Integer> target) {
-        $put(target, B1, E1, A1, C1, D1);
-        SortedMap<TPoint, Integer> map = target.subMap($key(B1), $key(D1));
+    public void basicSubMap_Clear(SortedMap<K, V> target) {
+        $map.list(4, 7, 5, 3, 6).into(target);
+        SortedMap<K, V> map = target.subMap($map.item(4).key(), $map.item(6).key());
         assertEquals(2, map.size());
         
         map.clear();
@@ -278,22 +289,22 @@ public final class SortedMapTester {
     }
     
     @Test
-    public void basicSubMap_Remove(SortedMap<TPoint, Integer> target) {
-        $put(target, B1, E1, A1, C1, D1);
-        SortedMap<TPoint, Integer> map = target.subMap($key(B1), $key(E1));
+    public void basicSubMap_Remove(SortedMap<K, V> target) {
+        $map.list(4, 7, 5, 3, 6).into(target);
+        SortedMap<K, V> map = target.subMap($map.item(4).key(), $map.item(6).key());
         assertEquals(5, target.size());
         assertEquals(3, map.size());
 
-        assertNull(map.remove($key(A1)));
-        assertNull(map.remove($key(A1_NE)));
-        assertNull(map.remove($key(E1)));
+        assertNull(map.remove($map.item(3).key()));
+        assertNull(map.remove($map.item(3,1).key()));
+        assertNull(map.remove($map.item(7).key()));
         assertNull(map.remove(new Object()));
         
-        assertEquals($object(D1), target.remove($key(D1)));
+        assertEquals($map.item(6).value(), target.remove($map.item(6).key()));
         assertEquals(4, target.size());
         assertEquals(2, map.size());
-        assertEquals($object(B1), map.remove($key(B1)));
-        assertEquals($object(C1), map.remove($key(C1)));
+        assertEquals($map.item(4).value(), map.remove($map.item(4).key()));
+        assertEquals($map.item(5).value(), map.remove($map.item(5).key()));
         
         assertEquals(2, target.size());
         assertEquals(0, map.size());
@@ -306,8 +317,8 @@ public final class SortedMapTester {
     }
     
     @Test
-    public void basicToString(SortedMap<TPoint, Integer> target) {
-        $put(target, B1, E1, A1, C1, D1);
+    public void basicToString(SortedMap<K, V> target) {
+        $map.list(2,5,1,3,4).into(target);
         assertEquals("{(7:4:6)=>17, (8:4:12)=>21, (9:4:13)=>22, (20:40:3)=>31, (33:42:6)=>81}", target.toString());
     }