diff options
author | Lester Solbakken <lesters@oath.com> | 2021-03-16 13:39:46 +0100 |
---|---|---|
committer | Lester Solbakken <lesters@oath.com> | 2021-03-16 13:39:46 +0100 |
commit | d7456a4c3504ad84afa9f461322bcdcc79e8b357 (patch) | |
tree | f162ff2b125d815fec82bc0df645a3cefff5a35d /vespajlib/src/test/java/com/yahoo | |
parent | 73702b1c05deaaf08bcfed78c15494d2e53684a9 (diff) |
Revert "Revert "Lesters/cell cast java""
This reverts commit d2c61030d6c62b8c4889d3471d2ee5f17bb14a5f.
Diffstat (limited to 'vespajlib/src/test/java/com/yahoo')
-rw-r--r-- | vespajlib/src/test/java/com/yahoo/tensor/functions/CellCastTestCase.java | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/vespajlib/src/test/java/com/yahoo/tensor/functions/CellCastTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/functions/CellCastTestCase.java new file mode 100644 index 00000000000..bc10ecc3abd --- /dev/null +++ b/vespajlib/src/test/java/com/yahoo/tensor/functions/CellCastTestCase.java @@ -0,0 +1,38 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.tensor.functions; + +import com.yahoo.tensor.Tensor; +import com.yahoo.tensor.TensorType; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * @author lesters + */ +public class CellCastTestCase { + + @Test + public void testCellCasting() { + Tensor tensor; + + tensor = Tensor.from("tensor(x[3]):[1.0, 2.0, 3.0]"); + assertEquals(TensorType.Value.DOUBLE, tensor.type().valueType()); + assertEquals(TensorType.Value.DOUBLE, tensor.cellCast(TensorType.Value.DOUBLE).type().valueType()); + assertEquals(TensorType.Value.FLOAT, tensor.cellCast(TensorType.Value.FLOAT).type().valueType()); + assertEquals(tensor, tensor.cellCast(TensorType.Value.FLOAT)); + + tensor = Tensor.from("tensor<double>(x{}):{{x:0}:1.0,{x:1}:2.0,{x:2}:3.0}"); + assertEquals(TensorType.Value.DOUBLE, tensor.type().valueType()); + assertEquals(TensorType.Value.DOUBLE, tensor.cellCast(TensorType.Value.DOUBLE).type().valueType()); + assertEquals(TensorType.Value.FLOAT, tensor.cellCast(TensorType.Value.FLOAT).type().valueType()); + assertEquals(tensor, tensor.cellCast(TensorType.Value.FLOAT)); + + tensor = Tensor.from("tensor<float>(x[3],y{}):{a:[1.0, 2.0, 3.0],b:[4.0,5.0,6.0]}"); + assertEquals(TensorType.Value.FLOAT, tensor.type().valueType()); + assertEquals(TensorType.Value.DOUBLE, tensor.cellCast(TensorType.Value.DOUBLE).type().valueType()); + assertEquals(TensorType.Value.FLOAT, tensor.cellCast(TensorType.Value.FLOAT).type().valueType()); + assertEquals(tensor, tensor.cellCast(TensorType.Value.DOUBLE)); + } + +} |