diff options
author | Jon Bratseth <bratseth@verizonmedia.com> | 2019-06-04 15:37:21 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@verizonmedia.com> | 2019-06-04 15:37:21 +0200 |
commit | 86435140ef6f7e2c6c18fac883f19507e093f95d (patch) | |
tree | f73f08d07c239d01fe961bd23fa5910699e3659c /vespajlib/src/test | |
parent | 6766d55234475d2e56e03872db33fe95068e2457 (diff) |
Validate more
Diffstat (limited to 'vespajlib/src/test')
-rw-r--r-- | vespajlib/src/test/java/com/yahoo/tensor/serialization/JsonFormatTestCase.java | 22 |
1 files changed, 20 insertions, 2 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 5a025b6eb96..8c652f5aa27 100644 --- a/vespajlib/src/test/java/com/yahoo/tensor/serialization/JsonFormatTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/tensor/serialization/JsonFormatTestCase.java @@ -8,6 +8,7 @@ import org.junit.Test; import java.nio.charset.StandardCharsets; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; /** * @author bratseth @@ -15,7 +16,7 @@ import static org.junit.Assert.assertEquals; public class JsonFormatTestCase { @Test - public void testJsonEncodingOfSparseTensor() { + public void testSparseTensor() { Tensor.Builder builder = Tensor.Builder.of(TensorType.fromSpec("tensor(x{},y{})")); builder.cell().label("x", "a").label("y", "b").value(2.0); builder.cell().label("x", "c").label("y", "d").value(3.0); @@ -31,7 +32,7 @@ public class JsonFormatTestCase { } @Test - public void testJsonEncodingOfDenseTensor() { + public void testDenseTensor() { Tensor.Builder builder = Tensor.Builder.of(TensorType.fromSpec("tensor(x{},y{})")); builder.cell().label("x", 0).label("y", 0).value(2.0); builder.cell().label("x", 0).label("y", 1).value(3.0); @@ -50,4 +51,21 @@ public class JsonFormatTestCase { assertEquals(tensor, decoded); } + @Test + public void testTooManyCells() { + TensorType x2 = TensorType.fromSpec("tensor(x[2])"); + String json = "{\"cells\":[" + + "{\"address\":{\"x\":\"0\"},\"value\":2.0}," + + "{\"address\":{\"x\":\"1\"},\"value\":3.0}," + + "{\"address\":{\"x\":\"2\"},\"value\":5.0}" + + "]}"; + try { + JsonFormat.decode(x2, json.getBytes(StandardCharsets.UTF_8)); + fail("Excpected exception"); + } + catch (IllegalArgumentException e) { + assertEquals("cell address (2) is not within bounds of tensor(x[2])", e.getMessage()); + } + } + } |