diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2024-01-21 12:30:10 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2024-01-21 12:30:10 +0100 |
commit | 4b3edc347a7a81763055aaeed07aecc110546248 (patch) | |
tree | 1f4790bc86639a20d7656b73bf4d5205d68d6fe4 /vespajlib | |
parent | 98f964da6b0b916a4f7fc6c9c630e111549f698f (diff) |
Add basic testing of TensorAddress
Diffstat (limited to 'vespajlib')
-rw-r--r-- | vespajlib/src/test/java/com/yahoo/tensor/TensorAddressTestCase.java | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/vespajlib/src/test/java/com/yahoo/tensor/TensorAddressTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/TensorAddressTestCase.java new file mode 100644 index 00000000000..79202e3f07e --- /dev/null +++ b/vespajlib/src/test/java/com/yahoo/tensor/TensorAddressTestCase.java @@ -0,0 +1,44 @@ +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.tensor; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; + +/** + * Test for tensor address. + * + * @author baldersheim + */ +public class TensorAddressTestCase { + private void equal(Object a, Object b) { + assertEquals(a.hashCode(), b.hashCode()); + assertEquals(a, b); + } + private void notEqual(Object a, Object 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)); + } + @Test + void testInEquality() { + notEqual(TensorAddress.ofLabels("1"), TensorAddress.ofLabels("2")); + notEqual(TensorAddress.of(1), TensorAddress.of(2)); + } + @Test + void testDimensionsEffectsEqualityAndHash() { + notEqual(TensorAddress.ofLabels("1"), TensorAddress.ofLabels("1", "1")); + notEqual(TensorAddress.of(1), TensorAddress.of(1, 1)); + } + @Test + void testAllowNullDimension() { + TensorAddress s1 = TensorAddress.ofLabels("1", null, "2"); + TensorAddress s2 = TensorAddress.ofLabels("1", "2"); + assertNotEquals(s1, s2); + assertEquals(s1.hashCode(), s2.hashCode()); + } +} |