|
|
@@ -8,11 +8,12 @@ package net.ranides.assira.collection.lookups;
|
|
|
|
|
|
import java.util.Map;
|
|
|
import java.util.SortedMap;
|
|
|
-import net.ranides.assira.test.TMap;
|
|
|
+import java.util.TreeMap;
|
|
|
import net.ranides.assira.collection.mockup.TPoint;
|
|
|
-import static net.ranides.assira.collection.mockup.TPointUtils.*;
|
|
|
import net.ranides.assira.collection.suite.CollectionSuite;
|
|
|
import static net.ranides.assira.junit.QAssert.*;
|
|
|
+import net.ranides.assira.test.TComparator;
|
|
|
+import net.ranides.assira.test.TMap.TItems;
|
|
|
import org.junit.Test;
|
|
|
import static org.junit.Assert.*;
|
|
|
|
|
|
@@ -22,13 +23,11 @@ import static org.junit.Assert.*;
|
|
|
* @author Ranides Atterwim <ranides@gmail.com>
|
|
|
*/
|
|
|
public class AVLTreeLookupTest {
|
|
|
-
|
|
|
- private static final TMap<TPoint, Integer> $map = TPoint.STD_INT_MAP;
|
|
|
-
|
|
|
+
|
|
|
@Test
|
|
|
public void testSuite() {
|
|
|
CollectionSuite.SUITE
|
|
|
- .param("map!", $map)
|
|
|
+ .param("map!", TPoint.INT_MAP)
|
|
|
.run(() -> new AVLTreeLookup<>(TPoint.SUM));
|
|
|
}
|
|
|
|
|
|
@@ -40,81 +39,22 @@ public class AVLTreeLookupTest {
|
|
|
|
|
|
@Test
|
|
|
public void testConstructCopy() {
|
|
|
- // inaczej to z comparem trzeba. bo jednak generowanie punktów
|
|
|
- // różnych dla STD, a takich samych dla SUM to trudne jest.
|
|
|
- //
|
|
|
- // a w ogóle to URANGE nam generuje z 60 liczb tylko 120 unikalnych dla STD (z definicji 60 to kolizje hash&equals, 60 to kolizje hash)
|
|
|
- //
|
|
|
- // a tutaj chcemy coś w stylu
|
|
|
- // A) brak kolizji z STD / kolizje z SUM
|
|
|
- // B) trochę STD / więcej z SUM
|
|
|
- //
|
|
|
- // w ogóle to muszą być po prostu dane spreparowane i chuj
|
|
|
- //
|
|
|
- // zrobimy to w ogóle zupełnie inaczej :)
|
|
|
- // 1. robimy unikalne punkty ze względu na "klasyczne equals" (to już mamy)
|
|
|
- // 2. konstruujemy PartitionComparator (todo)
|
|
|
- // 3. podajemy mu punkty oraz equality/hash numbers. Czyli:
|
|
|
+ TItems<TPoint, Integer> items = TPoint.INT_MAP.range(180);
|
|
|
+ TComparator<TPoint> cmp1 = new TComparator<>(items);
|
|
|
+ TComparator<TPoint> cmp2 = new TComparator<>(items).uorder();
|
|
|
+ TComparator<TPoint> cmp3 = new TComparator<>(items).hash(1,2,3,4).order(1,2,3,4,5,6,7,8);
|
|
|
+ items.shuffle(777);
|
|
|
|
|
|
- /*
|
|
|
- PartitionComparator cmp = new PartitionComparator();
|
|
|
- cmp.add(1, 0, $map.item(0));
|
|
|
- cmp.add(1, 0, $map.item(1));
|
|
|
- cmp.add(1, 1, $map.item(2));
|
|
|
- cmp.add(1, 1, $map.item(3));
|
|
|
- cmp.add(1, 2, $map.item(4));
|
|
|
- cmp.add(2, 3, $map.item(5));
|
|
|
- cmp.add(2, 4, $map.item(6));
|
|
|
- cmp.add(3, 5, $map.item(7));
|
|
|
+ AVLTreeLookup<TPoint> smap1 = new AVLTreeLookup<>(items.keys(), items.valuesInt(), cmp1);
|
|
|
+ AVLTreeLookup<TPoint> smap2 = new AVLTreeLookup<>(items.keys(), items.valuesInt(), cmp2);
|
|
|
+ AVLTreeLookup<TPoint> smap3 = new AVLTreeLookup<>(items.keys(), items.valuesInt(), cmp3);
|
|
|
|
|
|
- ALBO
|
|
|
-
|
|
|
- PartitionComparator cmp = new PartitionComparator($map);
|
|
|
- cmp.add(1, 0);
|
|
|
- cmp.add(1, 0);
|
|
|
- cmp.add(1, 1);
|
|
|
- cmp.add(1, 1);
|
|
|
- cmp.add(1, 2);
|
|
|
- cmp.add(2, 3);
|
|
|
- cmp.add(2, 4);
|
|
|
- cmp.add(3, 5);
|
|
|
-
|
|
|
- ALBO
|
|
|
-
|
|
|
- PartitionComparator cmp = new PartitionComparator($items);
|
|
|
- cmp.hash(1, 1, 1, 1, 1, 2, 2, 3) // podajemy hashe
|
|
|
- cmp.order(0, 0, 1, 1, 2, 3, 4, 5) // grupujemy "equals", w zasadzie mamy też porządkowanie zrobione
|
|
|
-
|
|
|
- ALBO ZAKRESY
|
|
|
-
|
|
|
- cmp.hashRange(1, 1, 5);
|
|
|
- cmp.hashRange(2, 5, 7);
|
|
|
- cmp.hashRange(3, 7, 8);
|
|
|
+ assertEquals(180, smap1.size());
|
|
|
+ assertEquals(120, smap2.size());
|
|
|
+ assertEquals(8, smap3.size());
|
|
|
|
|
|
- cmp.groupRange(0, 0, 2);
|
|
|
- cmp.groupRange(1, 2, 4);
|
|
|
- cmp.groupRange(2, 4, 5);
|
|
|
- cmp.groupRange(3, 5, 6);
|
|
|
- cmp.groupRange(4, 6, 7);
|
|
|
- cmp.groupRange(5, 7, 8);
|
|
|
+ Map<TPoint, Integer> imap = items.into(new TreeMap<>(cmp1));
|
|
|
|
|
|
- Nasz comparator mądry potrafi porównywać i hashować
|
|
|
-
|
|
|
- No i genialnie. W ten sposób możemy mieć normalne testy na unikalnych punktach
|
|
|
- a potem jakoś testować brzegowe przypadki własnymi komparatorami.
|
|
|
-
|
|
|
- W przypadku testowania map, które comparatora nie pobierają to i tak
|
|
|
- będzie trzeba robić ręcznie, wbrew pozorom, bo niby jak się zrobi kolizje
|
|
|
- "automatycznie" w IdentityMap albo (jeszcze gorzej) w Lookup'ach, które
|
|
|
- z definicji hashują te liczby w sposób silnie zależny od implementacji.
|
|
|
- A testować kolizje trzeba.
|
|
|
-
|
|
|
- */
|
|
|
-
|
|
|
- Map<TPoint, Integer> imap = $map($ukeys(60));
|
|
|
- AVLTreeLookup<TPoint> smap1 = new AVLTreeLookup<>($ukeys(60), $values(180), TPoint.STD);
|
|
|
- AVLTreeLookup<TPoint> smap2 = new AVLTreeLookup<>($ukeys(60), $values(180), TPoint.SUM);
|
|
|
-
|
|
|
assertEquals(180, new AVLTreeLookup<>(imap).size());
|
|
|
assertEquals(180, new AVLTreeLookup<>((SortedMap<TPoint,Integer>)imap).size());
|
|
|
|
|
|
@@ -124,11 +64,14 @@ public class AVLTreeLookupTest {
|
|
|
assertEquals(180, new AVLTreeLookup<>((Lookup<TPoint>)smap1).size());
|
|
|
assertEquals(120, new AVLTreeLookup<>((Lookup<TPoint>)smap2).size());
|
|
|
|
|
|
- assertEquals(120, new AVLTreeLookup<>($ukeys(60), $values(180), TPoint.SUM).size());
|
|
|
- assertEquals(180, new AVLTreeLookup<>($ukeys(60), $values(180) ).size());
|
|
|
+ assertEquals(180, new AVLTreeLookup<>(items.keys(), items.valuesInt(), cmp1).size());
|
|
|
+ assertEquals(120, new AVLTreeLookup<>(items.keys(), items.valuesInt(), cmp2).size());
|
|
|
+ assertEquals(8, new AVLTreeLookup<>(items.keys(), items.valuesInt(), cmp3).size());
|
|
|
|
|
|
+ assertEquals(180, new AVLTreeLookup<>(items.keys(), items.valuesInt()).size());
|
|
|
+
|
|
|
assertThrows(IllegalArgumentException.class, () ->
|
|
|
- new AVLTreeLookup<>($ukeys(60), $values(10), TPoint.SUM)
|
|
|
+ new AVLTreeLookup<>(TPoint.INT_MAP.range(60).keys(), TPoint.INT_MAP.range(40).valuesInt(), cmp1)
|
|
|
);
|
|
|
}
|
|
|
|