aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib/src/test/java/com/yahoo/collections/CollectionComparatorTestCase.java
blob: 54101c7f251b0e989db0293242347c45635e81b9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.collections;

import org.junit.Test;

import java.util.Arrays;
import java.util.List;

import static org.junit.Assert.assertEquals;

/**
 * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a>
 */
public class CollectionComparatorTestCase {
    @Test
    public void arrayLength() {
        List<String> shortArr = Arrays.asList("x", "y");
        List<String> longArr = Arrays.asList("a", "b", "c", "d", "e");

        assertEquals(-1, CollectionComparator.compare(shortArr, longArr));
    }

    @Test
    public void compareArrays() {
        List<String> one = Arrays.asList("b", "c", "d", "d", "e");
        List<String> two = Arrays.asList("a", "b", "c", "d", "e");

        assertEquals(1, CollectionComparator.compare(one, two));
        assertEquals(-1, CollectionComparator.compare(two, one));
    }

    @Test
    public void compareEqualArrays() {
        List<String> one = Arrays.asList("a", "b", "c", "d", "e");
        List<String> two = Arrays.asList("a", "b", "c", "d", "e");

        assertEquals(0, CollectionComparator.compare(one, two));
        assertEquals(0, CollectionComparator.compare(two, one));
    }
}