diff options
Diffstat (limited to 'vespajlib/src/test/java/com/yahoo/tensor/TensorAddressTestCase.java')
-rw-r--r-- | vespajlib/src/test/java/com/yahoo/tensor/TensorAddressTestCase.java | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/vespajlib/src/test/java/com/yahoo/tensor/TensorAddressTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/TensorAddressTestCase.java index 79202e3f07e..472ebca2360 100644 --- a/vespajlib/src/test/java/com/yahoo/tensor/TensorAddressTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/tensor/TensorAddressTestCase.java @@ -1,8 +1,13 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.tensor; +import static com.yahoo.tensor.TensorAddress.of; +import static com.yahoo.tensor.TensorAddress.ofLabels; + import org.junit.jupiter.api.Test; +import java.util.Arrays; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; @@ -12,33 +17,56 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals; * @author baldersheim */ public class TensorAddressTestCase { - private void equal(Object a, Object b) { + public static void equal(TensorAddress a, TensorAddress b) { assertEquals(a.hashCode(), b.hashCode()); assertEquals(a, b); + assertEquals(a.size(), b.size()); + for (int i = 0; i < a.size(); i++) { + assertEquals(a.label(i), b.label(i)); + assertEquals(a.numericLabel(i), b.numericLabel(i)); + } } - private void notEqual(Object a, Object b) { + public static void notEqual(TensorAddress a, TensorAddress b) { assertNotEquals(a.hashCode(), b.hashCode()); // This might not hold, but is bad if not very rare assertNotEquals(a, b); } @Test void testStringVersusNumericAddressEquality() { - equal(TensorAddress.ofLabels("1"), TensorAddress.of(1)); + equal(ofLabels("1"), of(1)); } @Test void testInEquality() { - notEqual(TensorAddress.ofLabels("1"), TensorAddress.ofLabels("2")); - notEqual(TensorAddress.of(1), TensorAddress.of(2)); + notEqual(ofLabels("1"), ofLabels("2")); + notEqual(of(1), of(2)); } @Test void testDimensionsEffectsEqualityAndHash() { - notEqual(TensorAddress.ofLabels("1"), TensorAddress.ofLabels("1", "1")); - notEqual(TensorAddress.of(1), TensorAddress.of(1, 1)); + notEqual(ofLabels("1"), ofLabels("1", "1")); + notEqual(of(1), of(1, 1)); } @Test void testAllowNullDimension() { - TensorAddress s1 = TensorAddress.ofLabels("1", null, "2"); - TensorAddress s2 = TensorAddress.ofLabels("1", "2"); + TensorAddress s1 = ofLabels("1", null, "2"); + TensorAddress s2 = ofLabels("1", "2"); assertNotEquals(s1, s2); - assertEquals(s1.hashCode(), s2.hashCode()); + assertEquals(-1, s1.numericLabel(1)); + assertEquals(null, s1.label(1)); + } + + private static void verifyWithLabel(int dimensions) { + int [] indexes = new int[dimensions]; + Arrays.fill(indexes, 1); + TensorAddress next = of(indexes); + for (int i = 0; i < dimensions; i++) { + indexes[i] = 3; + assertEquals(of(indexes), next = next.withLabel(i, 3)); + } } + @Test + void testWithLabel() { + for (int i=0; i < 10; i++) { + verifyWithLabel(i); + } + } + } |