diff options
author | Jon Bratseth <bratseth@verizonmedia.com> | 2019-12-14 08:34:09 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@verizonmedia.com> | 2019-12-14 08:34:09 +0100 |
commit | f5ccf036b4f7368f217a6bcbffc1699aac5eac2d (patch) | |
tree | 749afd3b29f52b918c67099c1742cb9db50211cf /vespajlib/src/test/java/com | |
parent | 3954dbe2403bdbb21e9a558fbc55fd137afa40f8 (diff) |
Interpret dimensions in written order
Diffstat (limited to 'vespajlib/src/test/java/com')
-rw-r--r-- | vespajlib/src/test/java/com/yahoo/tensor/TensorParserTestCase.java | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/vespajlib/src/test/java/com/yahoo/tensor/TensorParserTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/TensorParserTestCase.java index b2aba5b02eb..9dfdee29845 100644 --- a/vespajlib/src/test/java/com/yahoo/tensor/TensorParserTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/tensor/TensorParserTestCase.java @@ -75,6 +75,19 @@ public class TensorParserTestCase { } @Test + public void testDenseWrongOrder() { + assertEquals("Opposite order of dimensions", + Tensor.Builder.of(TensorType.fromSpec("tensor(x[3],y[2])")) + .cell(1, 0, 0) + .cell(4, 0, 1) + .cell(2, 1, 0) + .cell(5, 1, 1) + .cell(3, 2, 0) + .cell(6, 2, 1).build(), + Tensor.from("tensor(y[2],x[3]):[[1,2,3],[4,5,6]]")); + } + + @Test public void testMixedParsing() { assertEquals(Tensor.Builder.of(TensorType.fromSpec("tensor(key{}, x[2])")) .cell(TensorAddress.ofLabels("a", "0"), 1) @@ -84,6 +97,28 @@ public class TensorParserTestCase { Tensor.from("tensor(key{}, x[2]):{a:[1, 2], b:[3, 4]}")); } + @Test + public void testMixedWrongOrder() { + assertEquals("Opposite order of dimensions", + Tensor.Builder.of(TensorType.fromSpec("tensor(key{},x[3],y[2])")) + .cell(TensorAddress.ofLabels("key1", "0", "0"), 1) + .cell(TensorAddress.ofLabels("key1", "0", "1"), 4) + .cell(TensorAddress.ofLabels("key1", "1", "0"), 2) + .cell(TensorAddress.ofLabels("key1", "1", "1"), 5) + .cell(TensorAddress.ofLabels("key1", "2", "0"), 3) + .cell(TensorAddress.ofLabels("key1", "2", "1"), 6) + .cell(TensorAddress.ofLabels("key2", "0", "0"), 7) + .cell(TensorAddress.ofLabels("key2", "0", "1"), 10) + .cell(TensorAddress.ofLabels("key2", "1", "0"), 8) + .cell(TensorAddress.ofLabels("key2", "1", "1"), 11) + .cell(TensorAddress.ofLabels("key2", "2", "0"), 9) + .cell(TensorAddress.ofLabels("key2", "2", "1"), 12).build(), + Tensor.from("tensor(key{},y[2],x[3]):{key1:[[1,2,3],[4,5,6]], key2:[[7,8,9],[10,11,12]]}")); + assertEquals("Opposite order of dimensions", + Tensor.from("tensor(key{},x[3],y[2]):{key1:[[1,4],[2,5],[3,6]], key2:[[7,10],[8,11],[9,12]]}"), + Tensor.from("tensor(key{},y[2],x[3]):{key1:[[1,2,3],[4,5,6]], key2:[[7,8,9],[10,11,12]]}")); + } + private void assertDense(Tensor expectedTensor, String denseFormat) { assertEquals(denseFormat, expectedTensor, Tensor.from(denseFormat)); assertEquals(denseFormat, expectedTensor.toString()); @@ -99,7 +134,7 @@ public class TensorParserTestCase { "{{\"x\":\"l0\", \"y\":\"l0\"}:1.0, {\"x\":\"l0\", \"y\":\"l1\"}:2.0}"); assertIllegal("At {x:0}: '1-.0' is not a valid double", "{{x:0}:1-.0}"); - assertIllegal("At position 1: '1-.0' is not a valid double", + assertIllegal("At value position 1: '1-.0' is not a valid double", "tensor(x[1]):[1-.0]"); } |