+ /**
+ * Test adding elements in a random order then iterate over the list, this
+ * is an atypical degenerate use case.
+ */
+ @Test
+ public void test8AddFuzzyOrderThenIterateByStartTime() {
+ int size = 1000;
+ int[] fuzz = new int[size];
+ Random rng = new Random(10);
+ for (int i = 0; i < size; i++) {
+ fuzz[i] = rng.nextInt(1000);
+ }
+ String name = new Object() {
+ }.getClass().getEnclosingMethod().getName();
+ assertNotNull(name);
+ runIterateCompare(size, fuzz, name, SegmentComparators.INTERVAL_START_COMPARATOR);
+ }
+
+ /**
+ * Test adding elements in a random order then iterate over the list, this
+ * is an atypical degenerate use case.
+ */
+ @Test
+ public void test9AddFuzzyOrderThenIterateByEndTime() {
+ int size = 1000;
+ int[] fuzz = new int[size];
+ Random rng = new Random(10);
+ for (int i = 0; i < size; i++) {
+ fuzz[i] = rng.nextInt(1000);
+ }
+ String name = new Object() {
+ }.getClass().getEnclosingMethod().getName();
+ assertNotNull(name);
+ runIterateCompare(size, fuzz, name, SegmentComparators.INTERVAL_END_COMPARATOR);
+ }
+
+ /**
+ * Test adding elements in a random order then iterate over the list, this
+ * is an atypical degenerate use case.
+ */
+ @Test
+ public void testAAddFuzzyOrderThenIterateByDuration() {
+ int size = 1000;
+ int[] fuzz = new int[size];
+ Random rng = new Random(10);
+ for (int i = 0; i < size; i++) {
+ fuzz[i] = rng.nextInt(1000);
+ }
+ String name = new Object() {
+ }.getClass().getEnclosingMethod().getName();
+ assertNotNull(name);
+ runIterateCompare(size, fuzz, name, SegmentComparators.INTERVAL_LENGTH_COMPARATOR);
+ }
+
+ private void runIterateCompare(int size, int[] fuzz, String method, @NonNull Comparator<@NonNull ISegment> comparator) {
+ long start = System.nanoTime();
+ populate(size, fuzz, fSegStore);
+ long startTime = fuzz[0];
+ long endTime = fSegStore.size() - 1 + fuzz[fSegStore.size() % size];
+ iterateCompare(startTime, endTime, fSegStore, comparator);
+ long end = System.nanoTime();
+ long duration = end - start;
+ outputResults(duration, method);
+ }
+