You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@jena.apache.org by GitBox <gi...@apache.org> on 2023/01/03 11:53:59 UTC

[GitHub] [jena] afs commented on a diff in pull request #1696: GH-1634: Define a total, stable sort order.

afs commented on code in PR #1696:
URL: https://github.com/apache/jena/pull/1696#discussion_r1060515214


##########
jena-arq/src/test/java/org/apache/jena/sparql/expr/TestComparison.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.sparql.expr;
+
+import static org.apache.jena.sparql.expr.Expr.CMP_EQUAL;
+import static org.apache.jena.sparql.expr.Expr.CMP_INDETERMINATE;
+import static org.apache.jena.sparql.expr.Expr.CMP_LESS;
+import static org.apache.jena.sparql.expr.Expr.CMP_UNEQUAL;
+
+import org.apache.jena.graph.Node;
+import org.apache.jena.riot.system.PrefixMap;
+import org.apache.jena.riot.system.PrefixMapFactory;
+import org.apache.jena.shared.PrefixMapping;
+import org.apache.jena.sparql.serializer.SerializationContext;
+import org.apache.jena.sparql.sse.SSE;
+import org.junit.Test;
+
+/**
+ * Comparison tests - not sorting
+ * See also {@link TestSortOrdering} and {@link TestOrdering}.
+ */
+public class TestComparison {
+
+    @Test public void compare_01() { compare("<x:p1>", "<x:p1>", CMP_EQUAL ); }
+
+    @Test public void compare_02() { compare("<x:p1>", "<x:p2>", CMP_UNEQUAL); }
+
+    @Test(expected=ExprNotComparableException.class)
+    public void compare_03() { compare("'abc'@en", "<x:p1>", CMP_INDETERMINATE); }
+
+    @Test(expected=ExprNotComparableException.class)
+    public void compare_04() { compare("'abc'@en", "'abc'", CMP_INDETERMINATE); }
+
+    @Test public void compare_dt_01() { compare("'2022'^^xsd:gYear", "'2023'^^xsd:gYear", CMP_LESS); }
+
+    @Test(expected=ExprNotComparableException.class)
+    public void compare_dt_02() { compare("'2005-10-14Z'^^xsd:date", "'2005-10-14T14:09:43Z'^^xsd:dateTime", CMP_LESS); }
+
+    @Test public void compare_duration_01() { compare("'PT0S'^^xsd:duration", "'PT1S'^^xsd:duration", CMP_LESS); }
+    @Test public void compare_duration_02() { compare("'PT0S'^^xsd:duration", "'P0Y'^^xsd:duration", CMP_INDETERMINATE); }
+    @Test public void compare_duration_03() { compare("'PT0S'^^xsd:duration", "'P0MT0S'^^xsd:duration", CMP_EQUAL); }
+
+    private static void compare(String string1, String string2, int expected) {
+        compare(nodeValue(string1), nodeValue(string2), expected);
+    }
+
+    private static void compare(NodeValue nv1, NodeValue nv2, int expected) {
+        try {
+            //if ( true ) throw new RuntimeException("Switch to sorting branch");
+            //int cmp2 = -99;
+            int cmp2 = NodeValueCmp.compareByValue(nv1, nv2);
+

Review Comment:
   Now checks it is the expected value.
   
   All other suggestions done..



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org