public static int compareNodesRaw(NodeValue nv1, NodeValue nv2) { // Absent nodes sort to the start if ( nv1 == null ) return nv2 == null ? Expr.CMP_EQUAL : Expr.CMP_LESS ; if ( nv2 == null ) return Expr.CMP_GREATER ; // Compare - always getting a result. return NodeValue.compareAlways(nv1, nv2) ; }
@Test public void testComp_int_posint_1() { int x = NodeValue.compareAlways(nvInt9, nvPosInt9) ; assertTrue("Int 9 should be not equals to positive integer 9", Expr.CMP_EQUAL != x ) ; }
@Test public void testComp_int_posint_2() { int x = NodeValue.compareAlways(nvInt10, nvPosInt9) ; assertTrue("Int 10 not greater than positive integer 9", Expr.CMP_GREATER == x ) ; }
@Test public void testCompareGeneral1() { NodeValue nv1 = NodeValue.makeNode(NodeFactory.createBlankNode()) ; NodeValue nv2 = NodeValue.makeString("5") ; // bNodes before strings int x = NodeValue.compareAlways(nv1, nv2) ; assertEquals("Does not compare "+nv1+" & "+nv2, NodeValue.CMP_LESS, NodeValue.compareAlways(nv1, nv2) ) ; }
@Test public void testCompare21() { NodeValue nv5 = NodeValue.makeInteger(5) ; NodeValue nv7 = NodeValue.makeString("5") ; try { NodeValue.compare(nv5, nv7) ; fail("Should not compare (but did) "+nv5+" & "+nv7) ; } catch (ExprEvalException ex) { /* expected */} int x = NodeValue.compareAlways(nv5, nv7) ; assertEquals("Does not compare "+nv5+" & "+nv7, NodeValue.CMP_GREATER, NodeValue.compareAlways(nv5, nv7) ) ; }
@Test public void testCompareGeneral3() { NodeValue nv1 = NodeValue.makeNode(NodeFactory.createLiteral("test:abc")) ; NodeValue nv2 = NodeValue.makeNode(NodeFactory.createURI("test:abc")) ; // URIs before literals int x = NodeValue.compareAlways(nv1, nv2) ; assertEquals("Does not compare "+nv1+" & "+nv2, NodeValue.CMP_GREATER, NodeValue.compareAlways(nv1, nv2) ) ; }
@Test public void testCompareGeneral4() { NodeValue nv1 = NodeValue.makeNode(NodeFactory.createURI("test:abc")) ; NodeValue nv2 = NodeValue.makeNode(NodeFactory.createURI("test:xyz")) ; int x = NodeValue.compareAlways(nv1, nv2) ; assertEquals("Does not compare "+nv1+" & "+nv2, NodeValue.CMP_LESS, NodeValue.compareAlways(nv1, nv2) ) ; }
@Test public void testCompareGeneral2() { NodeValue nv1 = NodeValue.makeNode(NodeFactory.createBlankNode()) ; NodeValue nv2 = NodeValue.makeNode(NodeFactory.createURI("test:abc")) ; // bNodes before URIs int x = NodeValue.compareAlways(nv1, nv2) ; assertEquals("Does not compare "+nv1+" & "+nv2, NodeValue.CMP_LESS, NodeValue.compareAlways(nv1, nv2) ) ; }
@Test public void testComp_03_str3() { int x = NodeValue.compareAlways(nvInt03, nvStr3) ; int y = NodeUtils.compareRDFTerms(nInt03, nStr3) ; assertTrue("03 (typed) should be compareAlways 'less than' than \"3\"", Expr.CMP_LESS == x ) ; assertTrue("03 should be syntactic-less than to \"3\"", Expr.CMP_LESS == y ) ; }
@Test public void testComp_byte_double_1() { int x = NodeValue.compareAlways(nvByte10, nvDouble9) ; int y = NodeUtils.compareRDFTerms(nByte10, nDouble9) ; assertTrue("Byte 10 less than double 9", Expr.CMP_GREATER == x ) ; assertTrue("Byte 10 greater than double 9 in non-value compare (dataype URIs compare)", Expr.CMP_LESS == y ) ; }
@Test public void testComp_int_float_1() { int x = NodeValue.compareAlways(nvInt10, nvFloat8) ; int y = NodeUtils.compareRDFTerms(nInt10, nFloat8) ; assertTrue("Int 10 less than float 8", Expr.CMP_GREATER == x ) ; assertTrue("Int 10 less than float 8 in syntatic compare", Expr.CMP_LESS == y) ; }
@Test public void testComp_3_str3() { int x = NodeValue.compareAlways(nvInt3, nvStr3) ; int y = NodeUtils.compareRDFTerms(nInt3, nStr3) ; assertTrue("3 should be compareAlways greater than \"3\"", Expr.CMP_GREATER == x) ; assertTrue("3 should be syntactic-greater than to \"3\"", Expr.CMP_GREATER == y ) ; }
@Test public void testComp_int_double_1() { int x = NodeValue.compareAlways(nvInt10, nvDouble9) ; int y = NodeUtils.compareRDFTerms(nInt10, nDouble9) ; assertTrue("Int 10 less than double 9", Expr.CMP_GREATER == x ) ; assertTrue("Int 10 less than double 9 in syntactic compare", Expr.CMP_LESS == y ) ; }
@Test public void testComp_2_3() { int x = NodeValue.compareAlways(nvInt2, nvInt3) ; assertTrue("2 should be value-less than 3", Expr.CMP_LESS == x ) ; int y = NodeUtils.compareRDFTerms(nInt2, nInt3) ; assertTrue("2 should be strict-less than 3", Expr.CMP_LESS == y ) ; }
@Test public void test_lang3() { NodeValue nv1 = NodeValue.makeNode(NodeFactory.createLiteral("ABC", "en")) ; NodeValue nv2 = NodeValue.makeNode(NodeFactory.createLiteral("abc", "EN")) ; int x = NodeValue.compareAlways(nv1, nv2) ; assertTrue("Lang nodes should sort by lexical if tags value-same", Expr.CMP_LESS == x ) ; int y = NodeUtils.compareRDFTerms(nv1.asNode() , nv2.asNode()) ; assertTrue("Lang nodes should sort by case (syntactically)", Expr.CMP_LESS == y ) ; }
@Test public void test_lang4() { NodeValue nv1 = NodeValue.makeNode(NodeFactory.createLiteral("ABC", "en")) ; NodeValue nv2 = NodeValue.makeNode(NodeFactory.createLiteral("abc", "en")) ; int x = NodeValue.compareAlways(nv1, nv2) ; assertTrue("Lang nodes should sort by lexical if tags the same", Expr.CMP_LESS == x ) ; int y = NodeUtils.compareRDFTerms(nv1.asNode() , nv2.asNode()) ; assertTrue("Lang nodes should sort by lexical form if lang tags the same", Expr.CMP_LESS == x ) ; }
@Test public void test_lang6() { NodeValue nv1 = NodeValue.makeNode(NodeFactory.createLiteral("xyz")) ; NodeValue nv2 = NodeValue.makeNode(NodeFactory.createLiteral("abc", "en")) ; int x = NodeValue.compareAlways(nv1, nv2) ; assertTrue("Lang nodes should sort by lexical form if one is plain", Expr.CMP_GREATER == x ) ; int y = NodeUtils.compareRDFTerms(nv1.asNode() , nv2.asNode()) ; assertTrue(Expr.CMP_GREATER == x ) ; }
@Test public void test_lang8() { NodeValue nv1 = NodeValue.makeNode(NodeFactory.createLiteral("xyz", XSDDatatype.XSDstring)) ; NodeValue nv2 = NodeValue.makeNode(NodeFactory.createLiteral("abc", "en")) ; int x = NodeValue.compareAlways(nv1, nv2) ; assertTrue("Lang nodes should sort by lexical form if other is XSD string", Expr.CMP_GREATER == x ) ; int y = NodeUtils.compareRDFTerms(nv1.asNode() , nv2.asNode()) ; assertTrue(Expr.CMP_GREATER == x ) ; }
@Test public void test_lang5() { NodeValue nv1 = NodeValue.makeNode(NodeFactory.createLiteral("abc")) ; NodeValue nv2 = NodeValue.makeNode(NodeFactory.createLiteral("xyz", "en")) ; int x = NodeValue.compareAlways(nv1, nv2) ; assertTrue("Lang nodes should sort by lexical form if one is plain", Expr.CMP_LESS == x ) ; int y = NodeUtils.compareRDFTerms(nv1.asNode() , nv2.asNode()) ; assertTrue(Expr.CMP_LESS == x ) ; }
@Test public void test_lang7() { NodeValue nv1 = NodeValue.makeNode(NodeFactory.createLiteral("abc", XSDDatatype.XSDstring)) ; NodeValue nv2 = NodeValue.makeNode(NodeFactory.createLiteral("xyz", "en")) ; int x = NodeValue.compareAlways(nv1, nv2) ; assertTrue("Lang nodes should sort by lexical form if other is XSD string", Expr.CMP_LESS == x ) ; int y = NodeUtils.compareRDFTerms(nv1.asNode() , nv2.asNode()) ; assertTrue(Expr.CMP_LESS == x ) ; }