aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib/src/test/java/com/yahoo/collections/ByteArrayComparatorTestCase.java
blob: 57f5d21f749452ed865634e13872a20b6480a8f8 (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
// 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 static org.junit.Assert.assertEquals;

/**
 * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a>
 */
public class ByteArrayComparatorTestCase {
    @Test
    public void arrayLength() {
        byte[] shortArr = new byte[]{(byte) 1, (byte) 2};
        byte[] longArr = new byte[]{(byte) 0, (byte) 3, (byte) 3, (byte) 3, (byte) 3, (byte) 3};

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

    @Test
    public void compareArrays() {
        byte[] one = new byte[]{(byte) 1, (byte) 2, (byte) 3, (byte) 3, (byte) 3, (byte) 3};
        byte[] two = new byte[]{(byte) 0, (byte) 3, (byte) 3, (byte) 3, (byte) 3, (byte) 3};

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

    @Test
    public void compareEqualArrays() {
        byte[] one = new byte[]{(byte) 1, (byte) 2, (byte) 3, (byte) 3, (byte) 3, (byte) 3, (byte) 9};
        byte[] two = new byte[]{(byte) 1, (byte) 2, (byte) 3, (byte) 3, (byte) 3, (byte) 3, (byte) 9};

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

}