diff options
author | Jon Bratseth <bratseth@verizonmedia.com> | 2019-10-08 12:44:24 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@verizonmedia.com> | 2019-10-08 12:44:24 +0200 |
commit | 75570e061520dcfeedfcd70de8a392df644bbc19 (patch) | |
tree | 5af98986f63becb328541e1bf86f95376537034e /vespajlib/src/test/java/com | |
parent | f47861f1f38e644ad17d6acfd2872af8bcb7d090 (diff) |
Support mixed tensor short form JSON
Diffstat (limited to 'vespajlib/src/test/java/com')
-rw-r--r-- | vespajlib/src/test/java/com/yahoo/tensor/serialization/JsonFormatTestCase.java | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/vespajlib/src/test/java/com/yahoo/tensor/serialization/JsonFormatTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/serialization/JsonFormatTestCase.java index 32d62903af5..2878c82b7db 100644 --- a/vespajlib/src/test/java/com/yahoo/tensor/serialization/JsonFormatTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/tensor/serialization/JsonFormatTestCase.java @@ -52,24 +52,6 @@ public class JsonFormatTestCase { } @Test - public void testMixedTensor() { - Tensor.Builder builder = Tensor.Builder.of(TensorType.fromSpec("tensor(x{},y[2])")); - builder.cell().label("x", "a").label("y", "0").value(1.0); - builder.cell().label("x", "a").label("y", "1").value(2.0); - builder.cell().label("x", "b").label("y", "0").value(3.0); - builder.cell().label("x", "b").label("y", "1").value(4.0); - Tensor tensor = builder.build(); - byte[] json = JsonFormat.encode(tensor); - assertEquals("{\"cells\":[" + - "{\"address\":{\"x\":\"a\"},\"values\":[1.0,2.0]}," + - "{\"address\":{\"x\":\"b\"},\"values\":[3.0,4.0]}" + - "]}", - new String(json, StandardCharsets.UTF_8)); - Tensor decoded = JsonFormat.decode(tensor.type(), json); - assertEquals(tensor, decoded); - } - - @Test public void testDenseTensorInDenseForm() { Tensor.Builder builder = Tensor.Builder.of(TensorType.fromSpec("tensor(x[2],y[3])")); builder.cell().label("x", 0).label("y", 0).value(2.0); @@ -85,6 +67,24 @@ public class JsonFormatTestCase { } @Test + public void testMixedTensorInMixedForm() { + Tensor.Builder builder = Tensor.Builder.of(TensorType.fromSpec("tensor(x{},y[3])")); + builder.cell().label("x", 0).label("y", 0).value(2.0); + builder.cell().label("x", 0).label("y", 1).value(3.0); + builder.cell().label("x", 0).label("y", 2).value(4.0); + builder.cell().label("x", 1).label("y", 0).value(5.0); + builder.cell().label("x", 1).label("y", 1).value(6.0); + builder.cell().label("x", 1).label("y", 2).value(7.0); + Tensor expected = builder.build(); + String mixedJson = "{\"cells\":[" + + "{\"address\":{\"x\":\"0\"},\"values\":[2.0,3.0,4.0]}," + + "{\"address\":{\"x\":\"1\"},\"values\":[5.0,6.0,7.0]}" + + "]}"; + Tensor decoded = JsonFormat.decode(expected.type(), mixedJson.getBytes(StandardCharsets.UTF_8)); + assertEquals(expected, decoded); + } + + @Test public void testTooManyCells() { TensorType x2 = TensorType.fromSpec("tensor(x[2])"); String json = "{\"cells\":[" + |