diff options
Diffstat (limited to 'vespajlib/src/test/java/com/yahoo/collections/ByteArrayComparatorTestCase.java')
-rw-r--r-- | vespajlib/src/test/java/com/yahoo/collections/ByteArrayComparatorTestCase.java | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/vespajlib/src/test/java/com/yahoo/collections/ByteArrayComparatorTestCase.java b/vespajlib/src/test/java/com/yahoo/collections/ByteArrayComparatorTestCase.java new file mode 100644 index 00000000000..68b5812dd1e --- /dev/null +++ b/vespajlib/src/test/java/com/yahoo/collections/ByteArrayComparatorTestCase.java @@ -0,0 +1,38 @@ +// Copyright 2016 Yahoo Inc. 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)); + } + +} |