1 19 20 package com.hp.hpl.jena.ontology.daml.impl.test; 23 24 25 import com.hp.hpl.jena.ontology.daml.*; 28 import com.hp.hpl.jena.rdf.model.*; 29 30 import junit.framework.*; 31 32 33 42 public class TestDAMLList 43 extends DAMLTestBase 44 { 45 48 51 54 57 static public TestSuite suite() { 58 return new TestDAMLList( "TestDAMLList" ); 59 } 60 61 public TestDAMLList( String name ) { 62 super( name ); 63 } 64 65 66 69 public OntTestCase[] getTests() { 70 return new OntTestCase[] { 71 new OntTestCase( "DAMLList.getAll" ) { 72 public void doTest( DAMLModel m ) throws Exception { 73 DAMLClass A = m.createDAMLClass( NS + "A" ); 74 DAMLClass B = m.createDAMLClass( NS + "B" ); 75 DAMLClass C = m.createDAMLClass( NS + "C" ); 76 77 DAMLList l = m.createDAMLList( new RDFNode[] {A,B,C} ); 78 79 iteratorTest( l.getAll(), new Object [] {A,B,C} ); 80 } 81 }, 82 new OntTestCase( "DAMLList.getFirst" ) { 83 public void doTest( DAMLModel m ) throws Exception { 84 DAMLClass A = m.createDAMLClass( NS + "A" ); 85 DAMLClass B = m.createDAMLClass( NS + "B" ); 86 DAMLClass C = m.createDAMLClass( NS + "C" ); 87 88 DAMLList l = m.createDAMLList( new RDFNode[] {A,B,C} ); 89 90 assertEquals( "DAMLList.getFirst()", A, l.getFirst() ); 91 } 92 }, 93 new OntTestCase( "DAMLList.cons" ) { 94 public void doTest( DAMLModel m ) throws Exception { 95 DAMLClass A = m.createDAMLClass( NS + "A" ); 96 DAMLClass B = m.createDAMLClass( NS + "B" ); 97 DAMLClass C = m.createDAMLClass( NS + "C" ); 98 99 DAMLList l = m.createDAMLList( new RDFNode[] {B,C} ); 100 DAMLList l2 = l.cons( A ); 101 102 iteratorTest( l2.getAll(), new Object [] {A,B,C} ); 103 } 104 }, 105 new OntTestCase( "DAMLList.getRest" ) { 106 public void doTest( DAMLModel m ) throws Exception { 107 DAMLClass A = m.createDAMLClass( NS + "A" ); 108 DAMLClass B = m.createDAMLClass( NS + "B" ); 109 DAMLClass C = m.createDAMLClass( NS + "C" ); 110 111 DAMLList l = m.createDAMLList( new RDFNode[] {A,B,C} ); 112 113 iteratorTest( l.getRest().getAll(), new Object [] {B,C} ); 114 } 115 }, 116 new OntTestCase( "DAMLList.getCount" ) { 117 public void doTest( DAMLModel m ) throws Exception { 118 DAMLClass A = m.createDAMLClass( NS + "A" ); 119 DAMLClass B = m.createDAMLClass( NS + "B" ); 120 DAMLClass C = m.createDAMLClass( NS + "C" ); 121 122 DAMLList l = m.createDAMLList( new RDFNode[] {A,B,C} ); 123 124 assertEquals( "count", 3, l.getCount() ); 125 } 126 }, 127 new OntTestCase( "DAMLList.setFirst" ) { 128 public void doTest( DAMLModel m ) throws Exception { 129 DAMLClass A = m.createDAMLClass( NS + "A" ); 130 DAMLClass B = m.createDAMLClass( NS + "B" ); 131 DAMLClass C = m.createDAMLClass( NS + "C" ); 132 133 DAMLList l = m.createDAMLList( new RDFNode[] {B,B,C} ); 134 l.setFirst( A ); 135 136 iteratorTest( l.getAll(), new Object [] {A,B,C} ); 137 } 138 }, 139 new OntTestCase( "DAMLList.setRest" ) { 140 public void doTest( DAMLModel m ) throws Exception { 141 DAMLClass A = m.createDAMLClass( NS + "A" ); 142 DAMLClass B = m.createDAMLClass( NS + "B" ); 143 DAMLClass C = m.createDAMLClass( NS + "C" ); 144 145 DAMLList l = m.createDAMLList( new RDFNode[] {A} ); 146 DAMLList l2 = m.createDAMLList( new RDFNode[] {B,C} ); 147 l.setRest( l2 ); 148 149 iteratorTest( l.getAll(), new Object [] {A,B,C} ); 150 } 151 }, 152 new OntTestCase( "DAMLList.setRestNil" ) { 153 public void doTest( DAMLModel m ) throws Exception { 154 DAMLClass A = m.createDAMLClass( NS + "A" ); 155 DAMLClass B = m.createDAMLClass( NS + "B" ); 156 DAMLClass C = m.createDAMLClass( NS + "C" ); 157 158 DAMLList l = m.createDAMLList( new RDFNode[] {A,B,C} ); 159 l.getRest().setRestNil(); 160 161 iteratorTest( l.getAll(), new Object [] {A,B} ); 162 } 163 }, 164 new OntTestCase( "DAMLList.nil" ) { 165 public void doTest( DAMLModel m ) throws Exception { 166 DAMLClass A = m.createDAMLClass( NS + "A" ); 167 DAMLList l = m.createDAMLList(); 168 169 assertTrue( "nil is nil", l.isNil( l.getNil() ) ); 170 assertFalse( "A is not nil", l.isNil( A ) ); 171 } 172 }, 173 new OntTestCase( "DAMLList.findLast" ) { 174 public void doTest( DAMLModel m ) throws Exception { 175 DAMLClass A = m.createDAMLClass( NS + "A" ); 176 DAMLClass B = m.createDAMLClass( NS + "B" ); 177 DAMLClass C = m.createDAMLClass( NS + "C" ); 178 179 DAMLList l = m.createDAMLList( new RDFNode[] {A,B,C} ); 180 181 iteratorTest( l.findLast().getAll(), new Object [] {C} ); 182 } 183 }, 184 new OntTestCase( "DAMLList.getItem" ) { 185 public void doTest( DAMLModel m ) throws Exception { 186 DAMLClass A = m.createDAMLClass( NS + "A" ); 187 DAMLClass B = m.createDAMLClass( NS + "B" ); 188 DAMLClass C = m.createDAMLClass( NS + "C" ); 189 190 DAMLList l = m.createDAMLList( new RDFNode[] {A,B,C} ); 191 192 assertEquals( "A", A, l.getItem( 0 ) ); 193 assertEquals( "B", B, l.getItem( 1 ) ); 194 assertEquals( "C", C, l.getItem( 2 ) ); 195 } 196 }, 197 }; 198 } 199 200 201 204 208 } 209 210 211 240 241 | Popular Tags |