# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig. # License: Apache License, Version 2.0 require File.dirname(__FILE__) + '/../../../spec_helper' module RTM::Sugar::Topic module Typed describe self do before(:each) do @tm = get_used_tm_sys_tm @type0 = @tm.get!("negative") @default_name_type = @tm.get!(RTM::PSI[:name_type]) @dummy_type = @tm.get!("dummy_type") @container = @tm.get!("container") @containee = @tm.get!("containee") @contained = @tm.get!("contained") @leipzig = @tm.get!("leipzig") @germany = @tm.get!("germany") @dummy = @tm.get!("dummy") @name1 = @leipzig.create_name(@dummy_type, "Leipzig") @name2 = @germany.create_name("Germany") @name3 = @germany.create_name("Deutschland") @name4 = @leipzig.create_name("Leipzisch") @name5 = @leipzig.create_name("Lipsk") @occ1 = @leipzig.create_occurrence("inhabitants","500000") @occ2 = @germany.create_occurrence("states","16") @occ3 = @leipzig.create_occurrence("state","Sachsen") @occ2 = @germany.create_occurrence(@dummy_type,"0") @assoc1 = @tm.create_association(@dummy_type,["assoc_dummy"]) @assoc2 = @tm.create_association(@contained) @role1 = @assoc2.create_role(@containee,@leipzig) @role2 = @assoc2.create_role(@container,@germany) @dummy_role = @assoc1.create_role(@dummy_type,@dummy) end after(:each) do @tm.close end describe "#typed" do it "should give back all constructs which have this Topic as type" do @default_name_type.typed.size.should == 4 @default_name_type.typed.should include(@name2) @default_name_type.typed.should include(@name3) @default_name_type.typed.should include(@name4) @default_name_type.typed.should include(@name5) @container.typed.size.should == 1 @container.typed.should include(@role2) @containee.typed.size.should == 1 @containee.typed.should include(@role1) @contained.typed.size.should == 1 @contained.typed.should include(@assoc2) @dummy_type.typed.size.should == 4 @dummy_type.typed.should include(@name1) @dummy_type.typed.should include(@occ2) @dummy_type.typed.should include(@assoc1) @dummy_type.typed.should include(@dummy_role) end it "should give back an empty Array if there are no Constructs which have this Topic as type" do @type0.typed.should be_empty end end describe "#typed_associations" do it "should give back all Associations which have this Topic as type" do @default_name_type.typed_associations.should be_empty @container.typed_associations.should be_empty @containee.typed_associations.should be_empty @contained.typed_associations.size.should == 1 @contained.typed_associations.should include(@assoc2) @dummy_type.typed_associations.size.should == 1 @dummy_type.typed_associations.should include(@assoc1) end it "should give back an empty Array if there are no Associations which have this Topic as type" do @type0.typed_associations.should be_empty end end describe "#typed_names" do it "should give back all Names which have this Topic as type" do @default_name_type.typed_names.size.should == 4 @default_name_type.typed_names.should include(@name2) @default_name_type.typed_names.should include(@name3) @default_name_type.typed_names.should include(@name4) @default_name_type.typed_names.should include(@name5) @container.typed_names.should be_empty @containee.typed_names.should be_empty @contained.typed_names.should be_empty @dummy_type.typed_names.size.should == 1 @dummy_type.typed_names.should include(@name1) end it "should give back an empty Array if there are no Names which have this Topic as type" do @type0.typed_names.should be_empty end end describe "#typed_occurrences" do it "should give back all Occurrences which have this Topic as type" do @default_name_type.typed_occurrences.should be_empty @container.typed_occurrences.should be_empty @containee.typed_occurrences.should be_empty @contained.typed_occurrences.should be_empty @dummy_type.typed_occurrences.size.should == 1 @dummy_type.typed_occurrences.should include(@occ2) end it "should give back an empty Array if there are no Occurrences which have this Topic as type" do @type0.typed_occurrences.should be_empty end end describe "#typed_roles" do it "should give back all Roles which have this Topic as type" do @default_name_type.typed_roles.should be_empty @container.typed_roles.size.should == 1 @container.typed_roles.should include(@role2) @containee.typed_roles.size.should == 1 @containee.typed_roles.should include(@role1) @contained.typed_roles.should be_empty @dummy_type.typed_roles.size.should == 1 @dummy_type.typed_roles.should include(@dummy_role) end it "should give back an empty Array if there are no Roles which have this Topic as type" do @type0.typed_roles.should be_empty end end describe "#topic_is_a?" do before(:each) do @t1, @t2, @t3, @t4, @t5 = @tm.get!(["t1", "t2", "t3", "t4", "t5"]) @t1.add_types(@t1, @t2) @t1.add_instance(@t3) @t2.add_supertype(@t4) @t4.add_supertype(@t5) end it "give back true, if the argument is a type of this topic" do @t1.topic_is_a?(@t1).should be_true @t1.topic_is_a?("t2").should be_true end it "should give back false, if the argument is no type of this topic" do @t1.topic_is_a?(@t3).should be_false end it "should give back false, if the argument is not a topic in the topic map" do @t1.topic_is_a?("t6").should be_false end it "should give back true, if the argument is a supertype of the type of this topic" do @t1.topic_is_a?(@t4).should be_true @t1.topic_is_a?("t5").should be_true end end describe "#used_as_type?" do it "should give back true if this topic is used as type in a scope" do @default_name_type.used_as_type?.should be_true @dummy_type.used_as_type?.should be_true @contained.used_as_type?.should be_true @tm.get("inhabitants").used_as_type?.should be_true @tm.get("states").used_as_type?.should be_true @tm.get("state").used_as_type?.should be_true @containee.used_as_type?.should be_true @container.used_as_type?.should be_true end it "should give back false if this topic is not used as type in a scope" do @type0.used_as_type?.should be_false end end describe "#used_as_association_type?" do it "should give back true if this topic is used as type in a scope of an association" do @dummy_type.used_as_association_type?.should be_true @contained.used_as_association_type?.should be_true end it "should give back false if this topic is not used as type in a scope of an association" do @default_name_type.used_as_association_type?.should be_false @type0.used_as_association_type?.should be_false end end describe "#used_as_name_type?" do it "should give back true if this topic is used as type in a scope of a name" do @default_name_type.used_as_name_type?.should be_true @dummy_type.used_as_name_type?.should be_true end it "should give back false if this topic is not used as type in a scope of a name" do @type0.used_as_name_type?.should be_false end end describe "#used_as_occurrence_type?" do it "should give back true if this topic is used as type in a scope of an occurrence" do @dummy_type.used_as_occurrence_type?.should be_true @tm.get("inhabitants").used_as_occurrence_type?.should be_true @tm.get("states").used_as_occurrence_type?.should be_true @tm.get("state").used_as_occurrence_type?.should be_true end it "should give back false if this topic is not used as type in a scope of an occurrence" do @default_name_type.used_as_occurrence_type?.should be_false @type0.used_as_occurrence_type?.should be_false end end describe "#used_as_role_type?" do it "should give back true if this topic is used as type in a scope of a role" do @dummy_type.used_as_role_type?.should be_true @containee.used_as_role_type?.should be_true @container.used_as_role_type?.should be_true end it "should give back false if this topic is not used as type in a scope of a role" do @default_name_type.used_as_role_type?.should be_false @type0.used_as_role_type?.should be_false end end end #of describe self end end