diff options
Diffstat (limited to 'vespajlib/src/test/java/com/yahoo/tensor/serialization')
-rw-r--r-- | vespajlib/src/test/java/com/yahoo/tensor/serialization/JsonFormatTestCase.java | 18 |
1 files changed, 18 insertions, 0 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 4c44cbbf5c7..32d62903af5 100644 --- a/vespajlib/src/test/java/com/yahoo/tensor/serialization/JsonFormatTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/tensor/serialization/JsonFormatTestCase.java @@ -52,6 +52,24 @@ 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); |