aboutsummaryrefslogtreecommitdiffstats
path: root/document/src/test
diff options
context:
space:
mode:
authorLester Solbakken <lesters@oath.com>2019-02-20 16:09:16 +0100
committerLester Solbakken <lesters@oath.com>2019-02-20 16:09:16 +0100
commit5d0bff5230d3d8a304f786cbcc3c486ee9f941bb (patch)
treeebca6996f13ea1e197556abddc9119f3722c8bbd /document/src/test
parentb7dd335bdaeb889bca08daf8c79a47eb3d62c732 (diff)
Don't convert tensor add update type to sparse dimensions
Diffstat (limited to 'document/src/test')
-rw-r--r--document/src/test/java/com/yahoo/document/json/DocumentUpdateJsonSerializerTest.java8
-rw-r--r--document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java6
-rw-r--r--document/src/test/java/com/yahoo/document/update/TensorAddUpdateTest.java45
3 files changed, 33 insertions, 26 deletions
diff --git a/document/src/test/java/com/yahoo/document/json/DocumentUpdateJsonSerializerTest.java b/document/src/test/java/com/yahoo/document/json/DocumentUpdateJsonSerializerTest.java
index 0cc821680b2..454ad72f344 100644
--- a/document/src/test/java/com/yahoo/document/json/DocumentUpdateJsonSerializerTest.java
+++ b/document/src/test/java/com/yahoo/document/json/DocumentUpdateJsonSerializerTest.java
@@ -385,8 +385,12 @@ public class DocumentUpdateJsonSerializerTest {
" 'mixed_tensor': {",
" 'add': {",
" 'cells': [",
- " { 'address': { 'x': '0', 'y': '0' }, 'value': 2.0 },",
- " { 'address': { 'x': '1', 'y': '2' }, 'value': 3.0 }",
+ " { 'address': { 'x': '1', 'y': '0' }, 'value': 2.0 },",
+ " { 'address': { 'x': '1', 'y': '1' }, 'value': 0.0 },",
+ " { 'address': { 'x': '1', 'y': '2' }, 'value': 0.0 },",
+ " { 'address': { 'x': '0', 'y': '0' }, 'value': 0.0 },",
+ " { 'address': { 'x': '0', 'y': '1' }, 'value': 0.0 },",
+ " { 'address': { 'x': '0', 'y': '2' }, 'value': 3.0 }",
" ]",
" }",
" }",
diff --git a/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java b/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java
index 4bff6f44188..15d1e859f73 100644
--- a/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java
+++ b/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java
@@ -1479,7 +1479,7 @@ public class JsonReaderTestCase {
@Test
public void tensor_add_update_on_mixed_tensor() {
- assertTensorAddUpdate("{{x:a,y:0}:2.0, {x:a,y:1}:3.0}", "mixed_tensor",
+ assertTensorAddUpdate("{{x:a,y:0}:2.0, {x:a,y:1}:3.0, {x:a,y:2}:0.0}", "mixed_tensor",
inputJson("{",
" 'cells': [",
" { 'address': { 'x': 'a', 'y': '0' }, 'value': 2.0 },",
@@ -1487,9 +1487,9 @@ public class JsonReaderTestCase {
}
@Test
- public void tensor_add_update_with_out_of_bound_dense_cells_throws() {
+ public void tensor_add_update_on_mixed_with_out_of_bound_dense_cells_throws() {
exception.expect(IndexOutOfBoundsException.class);
- exception.expectMessage("Dimension 'y' has label '3' but type is tensor(x{},y[3])");
+ exception.expectMessage("Index 3 out of bounds for length 3");
createTensorAddUpdate(inputJson("{",
" 'cells': [",
" { 'address': { 'x': '0', 'y': '3' }, 'value': 2.0 } ]}"), "mixed_tensor");
diff --git a/document/src/test/java/com/yahoo/document/update/TensorAddUpdateTest.java b/document/src/test/java/com/yahoo/document/update/TensorAddUpdateTest.java
index c6b21380e4b..288bd112cd6 100644
--- a/document/src/test/java/com/yahoo/document/update/TensorAddUpdateTest.java
+++ b/document/src/test/java/com/yahoo/document/update/TensorAddUpdateTest.java
@@ -3,40 +3,43 @@ package com.yahoo.document.update;
import com.yahoo.document.datatypes.TensorFieldValue;
import com.yahoo.tensor.Tensor;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import static org.junit.Assert.assertEquals;
public class TensorAddUpdateTest {
- @Rule
- public ExpectedException exception = ExpectedException.none();
+ @Test
+ public void apply_add_update_operations_sparse() {
+ assertSparseApplyTo("{{x:0,y:0}:1, {x:0,y:1}:2}", "{{x:0,y:2}:3}", "{{x:0,y:0}:1,{x:0,y:1}:2,{x:0,y:2}:3}");
+ assertSparseApplyTo("{{x:0,y:0}:1, {x:0,y:1}:2}", "{{x:0,y:1}:3}", "{{x:0,y:0}:1,{x:0,y:1}:3}");
+ assertSparseApplyTo("{{x:0,y:0}:1, {x:0,y:1}:2}", "{{x:0,y:1}:3,{x:0,y:2}:4}", "{{x:0,y:0}:1,{x:0,y:1}:3,{x:0,y:2}:4}");
+ assertSparseApplyTo("{}", "{{x:0,y:0}:5}", "{{x:0,y:0}:5}");
+ assertSparseApplyTo("{{x:0,y:0}:1, {x:0,y:1}:2}", "{}", "{{x:0,y:0}:1, {x:0,y:1}:2}");
+ }
@Test
- public void apply_add_update_operations() {
- assertApplyTo("tensor(x{},y{})", "{{x:0,y:0}:1, {x:0,y:1}:2}", "{{x:0,y:2}:3}", "{{x:0,y:0}:1,{x:0,y:1}:2,{x:0,y:2}:3}");
- assertApplyTo("tensor(x{},y{})", "{{x:0,y:0}:1, {x:0,y:1}:2}", "{{x:0,y:1}:3}", "{{x:0,y:0}:1,{x:0,y:1}:3}");
- assertApplyTo("tensor(x{},y{})", "{{x:0,y:0}:1, {x:0,y:1}:2}", "{{x:0,y:1}:3,{x:0,y:2}:4}", "{{x:0,y:0}:1,{x:0,y:1}:3,{x:0,y:2}:4}");
- assertApplyTo("tensor(x{},y{})", "{}", "{{x:0,y:0}:5}", "{{x:0,y:0}:5}");
- assertApplyTo("tensor(x{},y{})", "{{x:0,y:0}:1, {x:0,y:1}:2}", "{}", "{{x:0,y:0}:1, {x:0,y:1}:2}");
-
- assertApplyTo("tensor(x{},y[3])", "{{x:0,y:0}:1, {x:0,y:1}:2}", "{{x:0,y:2}:3}", "{{x:0,y:0}:1,{x:0,y:1}:2,{x:0,y:2}:3}");
- assertApplyTo("tensor(x{},y[3])", "{{x:0,y:0}:1, {x:0,y:1}:2}", "{{x:0,y:1}:3}", "{{x:0,y:0}:1,{x:0,y:1}:3,{x:0,y:2}:0}");
- assertApplyTo("tensor(x{},y[3])", "{{x:0,y:0}:1, {x:0,y:1}:2}", "{{x:0,y:1}:3,{x:0,y:2}:4}", "{{x:0,y:0}:1,{x:0,y:1}:3,{x:0,y:2}:4}");
- assertApplyTo("tensor(x{},y[3])", "{}", "{{x:0,y:0}:5}", "{{x:0,y:0}:5,{x:0,y:1}:0,{x:0,y:2}:0}");
- assertApplyTo("tensor(x{},y[3])", "{{x:0,y:0}:1, {x:0,y:1}:2}", "{}", "{{x:0,y:0}:1,{x:0,y:1}:2,{x:0,y:2}:0}");
+ public void apply_add_update_operations_mixed() {
+ assertMixedApplyTo("{{x:0,y:0}:1, {x:0,y:1}:2}", "{{x:0,y:2}:3}", "{{x:0,y:0}:0,{x:0,y:1}:0,{x:0,y:2}:3}");
+ assertMixedApplyTo("{{x:0,y:0}:1, {x:0,y:1}:2}", "{{x:0,y:1}:3}", "{{x:0,y:0}:0,{x:0,y:1}:3,{x:0,y:2}:0}");
+ assertMixedApplyTo("{{x:0,y:0}:1, {x:0,y:1}:2}", "{{x:0,y:1}:3,{x:0,y:2}:4}", "{{x:0,y:0}:0,{x:0,y:1}:3,{x:0,y:2}:4}");
+ assertMixedApplyTo("{}", "{{x:0,y:0}:5}", "{{x:0,y:0}:5,{x:0,y:1}:0,{x:0,y:2}:0}");
+ assertMixedApplyTo("{{x:0,y:0}:1, {x:0,y:1}:2}", "{}", "{{x:0,y:0}:1,{x:0,y:1}:2,{x:0,y:2}:0}");
}
- private Tensor updateField(String spec, String init, String update) {
- TensorFieldValue initialFieldValue = new TensorFieldValue(Tensor.from(spec, init));
- TensorAddUpdate addUpdate = new TensorAddUpdate(new TensorFieldValue(Tensor.from("tensor(x{},y{})", update)));
- return ((TensorFieldValue) addUpdate.applyTo(initialFieldValue)).getTensor().get();
+ private void assertSparseApplyTo(String init, String update, String expected) {
+ assertApplyTo("tensor(x{},y{})", init, update, expected);
+ }
+
+ private void assertMixedApplyTo(String init, String update, String expected) {
+ assertApplyTo("tensor(x{},y[3])", init, update, expected);
}
private void assertApplyTo(String spec, String init, String update, String expected) {
- assertEquals(Tensor.from(spec, expected), updateField(spec, init, update));
+ TensorFieldValue initialFieldValue = new TensorFieldValue(Tensor.from(spec, init));
+ TensorAddUpdate addUpdate = new TensorAddUpdate(new TensorFieldValue(Tensor.from(spec, update)));
+ Tensor updated = ((TensorFieldValue) addUpdate.applyTo(initialFieldValue)).getTensor().get();
+ assertEquals(Tensor.from(spec, expected), updated);
}
}