aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib/src/test/java/com/yahoo
diff options
context:
space:
mode:
Diffstat (limited to 'vespajlib/src/test/java/com/yahoo')
-rw-r--r--vespajlib/src/test/java/com/yahoo/slime/JsonBenchmark.java2
-rw-r--r--vespajlib/src/test/java/com/yahoo/tensor/MixedTensorTestCase.java26
-rw-r--r--vespajlib/src/test/java/com/yahoo/tensor/TensorParserTestCase.java2
-rw-r--r--vespajlib/src/test/java/com/yahoo/text/XMLTestCase.java27
4 files changed, 49 insertions, 8 deletions
diff --git a/vespajlib/src/test/java/com/yahoo/slime/JsonBenchmark.java b/vespajlib/src/test/java/com/yahoo/slime/JsonBenchmark.java
index ee755a44010..cccc9667e11 100644
--- a/vespajlib/src/test/java/com/yahoo/slime/JsonBenchmark.java
+++ b/vespajlib/src/test/java/com/yahoo/slime/JsonBenchmark.java
@@ -43,7 +43,7 @@ public class JsonBenchmark {
try (JsonParser jsonParser = jsonFactory.createParser(json)) {
JsonToken array = jsonParser.nextToken();
for (JsonToken token = jsonParser.nextToken(); !JsonToken.END_ARRAY.equals(token); token = jsonParser.nextToken()) {
- if (JsonToken.FIELD_NAME.equals(token) && "weight".equals(jsonParser.getCurrentName())) {
+ if (JsonToken.FIELD_NAME.equals(token) && "weight".equals(jsonParser.currentName())) {
token = jsonParser.nextToken();
count += jsonParser.getLongValue();
}
diff --git a/vespajlib/src/test/java/com/yahoo/tensor/MixedTensorTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/MixedTensorTestCase.java
index 3ed8a7237ec..4ab60ecb9b9 100644
--- a/vespajlib/src/test/java/com/yahoo/tensor/MixedTensorTestCase.java
+++ b/vespajlib/src/test/java/com/yahoo/tensor/MixedTensorTestCase.java
@@ -2,9 +2,14 @@
package com.yahoo.tensor;
+import com.yahoo.tensor.functions.Reduce;
import org.junit.Test;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -159,4 +164,25 @@ public class MixedTensorTestCase {
tensor.toString());
}
+ @Test
+ public void testSplitIntoDense() {
+ TensorType type = new TensorType.Builder().mapped("key").indexed("x", 3).build();
+ Tensor tensor = MixedTensor.Builder.of(type).
+ cell().label("key", "key1").label("x", 0).value(1).
+ cell().label("key", "key1").label("x", 1).value(2).
+ cell().label("key", "key1").label("x", 2).value(3).
+ cell().label("key", "key2").label("x", 0).value(4).
+ cell().label("key", "key2").label("x", 1).value(5).
+ cell().label("key", "key2").label("x", 2).value(6).
+ build();
+
+ Map<String, Tensor> indexedTensors = new HashMap<>();
+ tensor.sum("x").cellIterator()
+ .forEachRemaining(cell -> indexedTensors.put(cell.getKey().label(0),
+ tensor.multiply(Tensor.Builder.of(type.mappedSubtype()).cell(cell.getKey(), 1.0).build()).sum("key")));
+
+ assertEquals("tensor(x[3]):[1.0, 2.0, 3.0]", indexedTensors.get("key1").toString());
+ assertEquals("tensor(x[3]):[4.0, 5.0, 6.0]", indexedTensors.get("key2").toString());
+ }
+
}
diff --git a/vespajlib/src/test/java/com/yahoo/tensor/TensorParserTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/TensorParserTestCase.java
index 5a049eeca04..7bc0556987b 100644
--- a/vespajlib/src/test/java/com/yahoo/tensor/TensorParserTestCase.java
+++ b/vespajlib/src/test/java/com/yahoo/tensor/TensorParserTestCase.java
@@ -261,6 +261,8 @@ public class TensorParserTestCase {
"tensor(x[3]):[1, 2]");
assertIllegal("At value position 8: Expected a ']' but got ','",
"tensor(x[3]):[1, 2, 3, 4]");
+ assertIllegal("No suitable dimension in tensor(x[3]) for parsing a tensor on the mixed form: Should have one mapped dimension",
+ "tensor(x[3]):{1:[1,2,3], 2:[2,3,4], 3:[3,4,5]}");
}
private void assertIllegal(String message, String tensor) {
diff --git a/vespajlib/src/test/java/com/yahoo/text/XMLTestCase.java b/vespajlib/src/test/java/com/yahoo/text/XMLTestCase.java
index 1565d067a09..11b873968a7 100644
--- a/vespajlib/src/test/java/com/yahoo/text/XMLTestCase.java
+++ b/vespajlib/src/test/java/com/yahoo/text/XMLTestCase.java
@@ -2,6 +2,7 @@
package com.yahoo.text;
import org.junit.Test;
+import org.w3c.dom.Document;
import java.io.StringReader;
@@ -11,10 +12,9 @@ import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-
/**
- * @author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a>
- * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
+ * @author Bjorn Borud
+ * @author Steinar Knutsen
*/
public class XMLTestCase {
@@ -30,13 +30,10 @@ public class XMLTestCase {
assertEquals("this is a &amp; test", XML.xmlEscape(s2, true));
// quotes are only escaped in attributes
- //
assertEquals("this is a &quot; test", XML.xmlEscape(s3, true));
assertEquals("this is a \" test", XML.xmlEscape(s3, false));
- // quotes are only escaped in attributes. prevent bug
- // no. 187006 from happening again!
- //
+ // quotes are only escaped in attributes
assertEquals("this is a &lt;&quot; test", XML.xmlEscape(s4, true));
assertEquals("this is a &lt;\" test", XML.xmlEscape(s4, false));
@@ -112,4 +109,20 @@ public class XMLTestCase {
assertTrue(e.getMessage().contains("error at line 2, column 5"));
}
}
+
+ @Test
+ public void testParseAndWrite() {
+ String xml = """
+ <foo>
+ <bar baz="quux"/>
+ <moo baah="boo">mux</moo>
+ <!-- zoink -->
+ </foo>""";
+ Document document = XML.getDocument(xml);
+ assertEquals(xml, XML.toString(document));
+ assertEquals(xml, XML.toString(document.getDocumentElement()));
+ assertEquals("<bar baz=\"quux\"/>", XML.toString(XML.getChild(document.getDocumentElement(), "bar")));
+ assertEquals("mux", XML.toString(XML.getChild(document.getDocumentElement(), "moo").getFirstChild()));
+ }
+
}