1 19 20 package com.hp.hpl.jena.ontology.impl.test; 23 24 25 26 import com.hp.hpl.jena.ontology.*; 29 import com.hp.hpl.jena.rdf.model.RDFNode; 30 31 import junit.framework.*; 32 33 34 43 public class TestAllDifferent 44 extends OntTestBase 45 { 46 49 52 55 58 static public TestSuite suite() { 59 return new TestAllDifferent( "TestAllDifferent" ); 60 } 61 62 public TestAllDifferent( String name ) { 63 super( name ); 64 } 65 66 67 70 public OntTestCase[] getTests() { 71 return new OntTestCase[] { 72 new OntTestCase( "AllDifferent.distinctMembers", true, true, false, false ) { 73 public void ontTest( OntModel m ) throws Exception { 74 Profile prof = m.getProfile(); 75 AllDifferent a = m.createAllDifferent(); 76 OntResource b = (OntResource) m.getResource( NS + "b" ).as( OntResource.class ); 77 OntResource c = (OntResource) m.getResource( NS + "c" ).as( OntResource.class ); 78 79 a.addDistinctMember( b ); 80 assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.DISTINCT_MEMBERS() ) ); 81 assertEquals( "List size should be 1", 1, a.getDistinctMembers().size() ); 82 assertTrue( "a should have b as distinct", a.hasDistinctMember( b ) ); 83 84 a.addDistinctMember( c ); 85 assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.DISTINCT_MEMBERS() ) ); 86 assertEquals( "List size should be 2", 2, a.getDistinctMembers().size() ); 87 iteratorTest( a.listDistinctMembers(), new Object [] {b, c} ); 88 89 assertTrue( "a should have b as distinct", a.hasDistinctMember( b ) ); 90 assertTrue( "a should have c as distinct", a.hasDistinctMember( c ) ); 91 92 a.setDistinctMembers( m.createList( new RDFNode[] {b} ) ); 93 assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.DISTINCT_MEMBERS() ) ); 94 assertEquals( "List size should be 1", 1, a.getDistinctMembers().size() ); 95 assertTrue( "a should have b as distinct", a.hasDistinctMember( b ) ); 96 assertTrue( "a should not have c as distinct", !a.hasDistinctMember( c ) ); 97 98 a.removeDistinctMember( b ); 99 assertTrue( "a should have not b as distinct", !a.hasDistinctMember( b ) ); 100 } 101 }, 102 }; 103 } 104 105 108 112 } 113 114 115 144 | Popular Tags |