diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2017-01-18 10:38:08 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2017-01-18 10:38:08 +0100 |
commit | 5bd40b8cdb0c025e439483bd7f246b68fee0e478 (patch) | |
tree | ca8ea288b55dd801aed7b95bc6e061ca6b8eee8f /vespajlib/src/test/java | |
parent | bad625e3565d83a72436224ed5ccbc2649ab89db (diff) |
Simplify and test type check
Diffstat (limited to 'vespajlib/src/test/java')
-rw-r--r-- | vespajlib/src/test/java/com/yahoo/tensor/serialization/DenseBinaryFormatTestCase.java | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/vespajlib/src/test/java/com/yahoo/tensor/serialization/DenseBinaryFormatTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/serialization/DenseBinaryFormatTestCase.java index 8a3d2879201..1ff8b3315b7 100644 --- a/vespajlib/src/test/java/com/yahoo/tensor/serialization/DenseBinaryFormatTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/tensor/serialization/DenseBinaryFormatTestCase.java @@ -4,6 +4,7 @@ package com.yahoo.tensor.serialization; import com.google.common.collect.Sets; import com.yahoo.io.GrowableByteBuffer; import com.yahoo.tensor.Tensor; +import com.yahoo.tensor.TensorType; import org.junit.Ignore; import org.junit.Test; @@ -12,6 +13,7 @@ import java.util.Optional; import java.util.Set; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; /** * Tests for the dense binary format. @@ -28,6 +30,19 @@ public class DenseBinaryFormatTestCase { assertSerialization("tensor(x[],y[]):{{x:0,y:0}:2.0, {x:0,y:1}:3.0, {x:1,y:0}:4.0, {x:1,y:1}:5.0}"); assertSerialization("tensor(x[1],y[2],z[3]):{{y:0,x:0,z:0}:2.0}"); } + + @Test + public void testSerializationToSeparateType() { + assertSerialization(Tensor.from("tensor(x[1],y[1]):{{x:0,y:0}:2.0}"), TensorType.fromSpec("tensor(x[],y[])")); + assertSerialization(Tensor.from("tensor(x[1],y[1]):{{x:0,y:0}:2.0}"), TensorType.fromSpec("tensor(x[2],y[2])")); + try { + assertSerialization(Tensor.from("tensor(x[2],y[2]):{{x:0,y:0}:2.0}"), TensorType.fromSpec("tensor(x[1],y[1])")); + fail("Expected exception"); + } + catch (IllegalArgumentException expected) { + assertEquals("Type/instance mismatch: Instance has size 2 in x[1] in type tensor(x[1],y[1])", expected.getMessage()); + } + } @Test public void requireThatSerializationFormatDoNotChange() { @@ -47,8 +62,12 @@ public class DenseBinaryFormatTestCase { } private void assertSerialization(Tensor tensor) { + assertSerialization(tensor, tensor.type()); + } + + private void assertSerialization(Tensor tensor, TensorType expectedType) { byte[] encodedTensor = TypedBinaryFormat.encode(tensor); - Tensor decodedTensor = TypedBinaryFormat.decode(Optional.of(tensor.type()), GrowableByteBuffer.wrap(encodedTensor)); + Tensor decodedTensor = TypedBinaryFormat.decode(Optional.of(expectedType), GrowableByteBuffer.wrap(encodedTensor)); assertEquals(tensor, decodedTensor); } |