@Test
    public void shouldHandleShuffleCorrectly() {
        MultiComparator<Object> comparator = new MultiComparator<>(Arrays.asList(Order.asc, Order.desc, Order.shuffle));
        assertTrue(comparator.isShuffle()); // because its a shuffle, the comparator simply returns 0
        for (int i = 0; i < 100; i++) {
            assertEquals(0, comparator.compare(RANDOM.nextInt(), RANDOM.nextInt()));
        }
        //
        comparator = new MultiComparator<>(Arrays.asList(Order.asc, Order.shuffle, Order.desc));
        assertEquals(1, comparator.compare(1, 2));
        assertEquals(-1, comparator.compare(2, 1));
        assertEquals(0, comparator.compare(2, 2));
        assertEquals(2, comparator.startIndex);
        assertFalse(comparator.isShuffle());
        //
        comparator = new MultiComparator<>(Arrays.asList(Order.asc, Order.shuffle, Order.desc, Order.shuffle, Order.asc));
        assertEquals(-1, comparator.compare(1, 2));
        assertEquals(1, comparator.compare(2, 1));
        assertEquals(0, comparator.compare(2, 2));
        assertEquals(4, comparator.startIndex);
        assertFalse(comparator.isShuffle());
        //
        comparator = new MultiComparator<>(Collections.emptyList());
        assertEquals(-1, comparator.compare(1, 2));
        assertEquals(1, comparator.compare(2, 1));
        assertEquals(0, comparator.compare(2, 2));
        assertEquals(0, comparator.startIndex);
        assertFalse(comparator.isShuffle());
    }
@author Marko A. Rodriguez (http://markorodriguez.com)
gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/util/function/MultiComparatorTest.java