diff options
author | Jon Bratseth <bratseth@verizonmedia.com> | 2019-12-17 11:42:21 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@verizonmedia.com> | 2019-12-17 11:42:21 +0100 |
commit | 3a84c90423e86bb95c9a620c1c9ccc1a055b2d37 (patch) | |
tree | bd7ffc5edc8b4f7216a2403e86001755efaf953f /vespajlib/src/test/java/com | |
parent | cbcd468e0f19421876a52ba1bd74f33fda73b855 (diff) |
Allow quoted labels in tensors
Diffstat (limited to 'vespajlib/src/test/java/com')
-rw-r--r-- | vespajlib/src/test/java/com/yahoo/tensor/TensorParserTestCase.java | 24 | ||||
-rw-r--r-- | vespajlib/src/test/java/com/yahoo/tensor/TensorTestCase.java | 3 |
2 files changed, 23 insertions, 4 deletions
diff --git a/vespajlib/src/test/java/com/yahoo/tensor/TensorParserTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/TensorParserTestCase.java index 6f9a5c13886..78afa1f7449 100644 --- a/vespajlib/src/test/java/com/yahoo/tensor/TensorParserTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/tensor/TensorParserTestCase.java @@ -19,6 +19,10 @@ public class TensorParserTestCase { assertEquals("If the type is specified, a dense tensor can be created from the sparse text form", Tensor.Builder.of(TensorType.fromSpec("tensor(x[1])")).cell(1.0, 0).build(), Tensor.from("tensor(x[1]):{{x:0}:1.0}")); + assertEquals(Tensor.Builder.of(TensorType.fromSpec("tensor(x{})")).cell().label("x", "..\",]}:..").value(1.0).build(), + Tensor.from("{{x:'..\",]}:..'}:1.0}")); + assertEquals(Tensor.Builder.of(TensorType.fromSpec("tensor(x{})")).cell().label("x", "..'..").value(1.0).build(), + Tensor.from("{{x:\"..'..\"}:1.0}")); } @Test @@ -95,6 +99,12 @@ public class TensorParserTestCase { .cell(TensorAddress.ofLabels("b", "0"), 3) .cell(TensorAddress.ofLabels("b", "1"), 4).build(), Tensor.from("tensor(key{}, x[2]):{a:[1, 2], b:[3, 4]}")); + assertEquals(Tensor.Builder.of(TensorType.fromSpec("tensor(key{}, x[2])")) + .cell(TensorAddress.ofLabels(",:", "0"), 1) + .cell(TensorAddress.ofLabels(",:", "1"), 2) + .cell(TensorAddress.ofLabels("b", "0"), 3) + .cell(TensorAddress.ofLabels("b", "1"), 4).build(), + Tensor.from("tensor(key{}, x[2]):{',:':[1, 2], b:[3, 4]}")); } @Test @@ -103,6 +113,14 @@ public class TensorParserTestCase { .cell(TensorAddress.ofLabels("a"), 1) .cell(TensorAddress.ofLabels("b"), 2).build(), Tensor.from("tensor(key{}):{a:1, b:2}")); + assertEquals(Tensor.Builder.of(TensorType.fromSpec("tensor(key{})")) + .cell(TensorAddress.ofLabels("..\",}]:.."), 1) + .cell(TensorAddress.ofLabels("b"), 2).build(), + Tensor.from("tensor(key{}):{'..\",}]:..':1, b:2}")); + assertEquals(Tensor.Builder.of(TensorType.fromSpec("tensor(key{})")) + .cell(TensorAddress.ofLabels("..'.."), 1) + .cell(TensorAddress.ofLabels("b"), 2).build(), + Tensor.from("tensor(key{}):{\"..'..\":1, b:2}")); } @Test @@ -134,11 +152,9 @@ public class TensorParserTestCase { @Test public void testIllegalStrings() { - assertIllegal("label must be an identifier or integer, not '\"l0\"'", - "{{x:\"l0\"}:1.0}"); - assertIllegal("dimension must be an identifier or integer, not ''x''", + assertIllegal("A dimension name must be an identifier or integer, not ''x''", "{{'x':\"l0\"}:1.0}"); - assertIllegal("dimension must be an identifier or integer, not '\"x\"'", + assertIllegal("A dimension name must be an identifier or integer, not '\"x\"'", "{{\"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}"); diff --git a/vespajlib/src/test/java/com/yahoo/tensor/TensorTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/TensorTestCase.java index 9f077cb7b00..7932f90d797 100644 --- a/vespajlib/src/test/java/com/yahoo/tensor/TensorTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/tensor/TensorTestCase.java @@ -36,6 +36,9 @@ public class TensorTestCase { assertTrue(Tensor.from("tensor():{5.7}") instanceof IndexedTensor); assertEquals("tensor(d1{},d2{}):{{d1:l1,d2:l1}:5.0,{d1:l1,d2:l2}:6.0}", Tensor.from("{ {d1:l1,d2:l1}: 5, {d2:l2, d1:l1}:6.0} ").toString()); assertEquals("tensor(d1{},d2{}):{{d1:l1,d2:l1}:-5.3,{d1:l1,d2:l2}:0.0}", Tensor.from("{ {d1:l1,d2:l1}:-5.3, {d2:l2, d1:l1}:0}").toString()); + assertEquals("Labels are quoted when necessary", + "tensor(d1{}):{{d1:\"'''\"}:6.0,{d1:'[[\":\"]]'}:5.0}", + Tensor.from("{ {d1:'[[\":\"]]'}: 5, {d1:\"'''\"}:6.0 }").toString()); } @Test |