|
27 | 27 | import org.junit.Assert; |
28 | 28 | import org.junit.Test; |
29 | 29 |
|
| 30 | +import java.util.ArrayList; |
| 31 | +import java.util.HashSet; |
| 32 | +import java.util.List; |
| 33 | +import java.util.Random; |
| 34 | +import java.util.Set; |
| 35 | +import java.util.stream.Collectors; |
| 36 | +import java.util.stream.IntStream; |
| 37 | + |
| 38 | +import static org.apache.iotdb.commons.pipe.datastructure.pattern.IoTDBTreePattern.applyReversedIndexesOnList; |
| 39 | + |
30 | 40 | public class IoTDBTreePatternTest { |
31 | 41 |
|
32 | 42 | @Test |
@@ -109,4 +119,29 @@ public void testIotdbPipePattern() { |
109 | 119 | Assert.assertFalse(new IoTDBTreePattern(t).matchesMeasurement(device, measurement)); |
110 | 120 | } |
111 | 121 | } |
| 122 | + |
| 123 | + @Test |
| 124 | + public void testApplyReversedIndexes() { |
| 125 | + final int elementNum = 10_000_000; |
| 126 | + final int filteredNum = elementNum / 10; |
| 127 | + final Random random = new Random(); |
| 128 | + final List<Integer> originalList = |
| 129 | + IntStream.range(0, elementNum).boxed().collect(Collectors.toList()); |
| 130 | + List<Integer> filteredIndexes = new ArrayList<>(filteredNum); |
| 131 | + for (int i = 0; i < filteredNum; i++) { |
| 132 | + filteredIndexes.add(random.nextInt(elementNum)); |
| 133 | + } |
| 134 | + filteredIndexes = filteredIndexes.stream().sorted().distinct().collect(Collectors.toList()); |
| 135 | + |
| 136 | + final long start = System.currentTimeMillis(); |
| 137 | + final List<Integer> appliedList = applyReversedIndexesOnList(filteredIndexes, originalList); |
| 138 | + System.out.println(System.currentTimeMillis() - start); |
| 139 | + final Set<Integer> appliedSet = new HashSet<>(appliedList); |
| 140 | + for (Integer filteredIndex : filteredIndexes) { |
| 141 | + if (appliedSet.contains(filteredIndex)) { |
| 142 | + System.out.println("Incorrect implementation"); |
| 143 | + System.exit(-1); |
| 144 | + } |
| 145 | + } |
| 146 | + } |
112 | 147 | } |
0 commit comments