1 6 7 package com.hp.hpl.jena.graph.query.test; 8 9 import com.hp.hpl.jena.graph.test.*; 10 import com.hp.hpl.jena.graph.query.*; 11 import com.hp.hpl.jena.graph.*; 12 13 import java.util.*; 14 import junit.framework.*; 15 16 19 public class TestSimpleTripleSorter extends GraphTestBase 20 { 21 public TestSimpleTripleSorter(String name) 22 {super(name); } 23 24 public static TestSuite suite() 25 { return new TestSuite( TestSimpleTripleSorter.class ); } 26 27 private TripleSorter sorter = new SimpleTripleSorter(); 28 29 32 public void testEmpty() 33 { 34 Triple [] triples = new Triple [] {}; 35 assertEquals( 0, sorter.sort( triples ).length ); 36 } 37 38 42 public void testSingle() 43 { 44 testSingle( "S P O" ); 45 testSingle( "S ?P O" ); 46 testSingle( "S P ?O" ); 47 testSingle( "?S ?P O" ); 48 testSingle( "?S P ?O" ); 49 testSingle( "S ?P ?O" ); 50 testSingle( "?S ?P ?O" ); 51 testSingle( "?? P O" ); 52 testSingle( "S ?? O" ); 53 testSingle( "S P ??O" ); 54 testSingle( "?? ?? O" ); 55 testSingle( "?? P ??" ); 56 testSingle( "S ?? ??" ); 57 testSingle( "?? ?? ??" ); 58 } 59 60 public void testSingle(String ts ) 61 { 62 Triple t = Triple.create( ts ); 63 assertEquals( Arrays.asList( new Triple[] {t} ), Arrays.asList( sorter.sort( new Triple[] {t} ) ) ); 64 } 65 66 69 public void testConcreteFirst() 70 { 71 testReordersTo( "S P O; ?s ?p ?o", "S P O; ?s ?p ?o" ); 72 testReordersTo( "S P O; ?s ?p ?o", "?s ?p ?o; S P O" ); 73 testReordersTo( "S P O; ?s ?p ?o; ?a ?b ?c", "?s ?p ?o; ?a ?b ?c; S P O" ); 74 testReordersTo( "S P O; ?s ?p ?o; ?a ?b ?c", "?s ?p ?o; S P O; ?a ?b ?c" ); 75 } 76 77 80 public void testBoundFirst() 81 { 82 testReordersTo( "?s R a; ?s ?p ?o", "?s ?p ?o; ?s R a" ); 83 testReordersTo( "?s R a; ?s ?p b;", "?s ?p b; ?s R a" ); 84 testReordersTo( "?a P b; ?c Q d; ?a P ?c", "?a P b; ?a P ?c; ?c Q d" ); 85 } 86 87 90 public void testANY() 91 { 92 testReordersTo( "?? C d; ?a X ?b", "?a X ?b; ?? C d" ); 93 testReordersTo( "?a B c; ?? D e", "?? D e; ?a B c" ); 94 } 95 96 99 public void testInteraction() 100 { 101 testReordersTo( "?a P b; ?a Q ?b; ?b R ?c", "?b R ?c; ?a Q ?b; ?a P b" ); 102 } 103 104 108 public void testSortByMass() 109 { 110 testReordersTo( "?b c d; ?a b c; ?b ?c d; ?a ?b ?d", "?a b c; ?b c d; ?b ?c d; ?a ?b ?d" ); 111 } 112 113 117 public void testReordersTo( String desired, String original ) 118 { 119 Triple [] o = tripleArray( original ), d = tripleArray( desired ); 120 assertEquals( Arrays.asList( d ), Arrays.asList( sorter.sort( o ) ) ); 121 } 122 } 123 124 125 | Popular Tags |