# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig. # License: Apache License, Version 2.0 require File.dirname(__FILE__) + '/../../../spec_helper' module RTM::Navigation::Topic describe self do before(:each) do @tm = get_used_tm_sys_tm @t1,@t2,@t3,@t4,@t5 = @tm.get!(["t1","t2","t3","t4","t5"]) @t1.add_type(@t3) @t2.add_type(@t3) @t2.add_type(@t4) end after(:each) do @tm.close end describe "#types" do it "should give back the types this Topic is an instance of" do @t1.types.size.should == 1 @t1.types.should include(@t3) @t2.types.size.should == 2 @t2.types.should include(@t3) @t2.types.should include(@t4) end it "should give back an empty Set if Topic has no type" do @t5.types.should be_empty end it "should never raise the error because type calls the TMAPI function" do lambda{@t1.types}.should_not raise_error end end describe "#type" do it "should raise an error if this Topic has more than one type" do @t2.types.size.should > 1 lambda{@t2.type}.should raise_error end it "should give back the type if this Topic is instance of exactly one type" do @t1.type.should == @t3 end it "should give back nil if this Topic has no type, aka is no instance" do @t5.type.should be_nil end end describe "#instances" do it "schould give back the Instances of this Topic" do @t3.instances.size.should == 2 @t3.instances.should include(@t1) @t3.instances.should include(@t2) @t4.instances.size.should == 1 @t4.instances.should include(@t2) end it "should give back an empty Set if this Topic has no instances" do @t1.instances.should be_empty end end describe "#instance" do it "should raise an error if this Topic has more than one instance" do @t3.instances.size.should > 1 lambda{@t3.instance}.should raise_error end it "should give back the instance if this Topic is type of exactly one instance" do @t4.instance.should == @t2 end it "should give back nil if this Topic has no instance, aka is no type" do @t5.instance.should be_nil end end describe "#reverse_instances" do it "reverse_instances should call types" do # proof through example, not nice @t1.reverse_instances.should == @t1.types end end describe "#reverse_types" do it "reverse_types should call instances" do @t2.method(:reverse_types).should == @t2.method(:instances) end end describe "#transitive_types" do before(:each) do @st1, @st2, @st3, @st4, @st5 = @tm.get!(["st1","st2","st3", "st4", "st5"]) end it "should give back the types only if the topic has no supertypes" do @t1.types.should respond_to(:each) @t1.types.size.should == 1 @t1.transitive_types.size.should == 1 ### @t2.types.should respond_to(:each) @t2.types.size.should == 2 @t2.transitive_types.size.should == 2 end it "should give back the types and supertypes of the topic if supertypes exist" do @t3.add_supertype(@st1) @t3.add_supertype(@st2) @t4.add_supertype(@st3) ### @t1.transitive_types.size.should == 3 @t1.transitive_types.should include(@t3, @st1, @st2) ### @t2.transitive_types.size.should == 5 @t2.transitive_types.should include(@t3, @st1, @st2, @t4, @st3) end it "should give back the supertypes of the supertypes also" do @t3.add_supertype(@st1) @t3.add_supertype(@st2) @t4.add_supertype(@st3) @st1.add_supertype(@st4) @st3.add_supertype(@st5) ### @t1.transitive_types.size.should == 4 @t1.transitive_types.should include(@t3, @st1, @st2, @st4) ### @t2.transitive_types.size.should == 7 @t2.transitive_types.should include(@t3, @st1, @st2, @st4, @t4, @st3, @st5) end it "should not give back supertypes" do @t3.add_supertype(@st1) @t3.transitive_types.should be_empty end it "should give back supertypes of types without duplicates" do @t3.add_supertype(@st1) @t3.add_supertype(@st2) @t4.add_supertype(@st3) @t4.add_supertype(@st2) @st1.add_supertype(@st4) @st2.add_supertype(@st4) @st3.add_supertype(@st5) ### @t1.transitive_types.size.should == 4 @t1.transitive_types.should include(@t3, @st1, @st2, @st4) ### @t2.transitive_types.size.should == 7 @t2.transitive_types.should include(@t3, @st1, @st2, @st4, @t4, @st3, @st5) end it "should give back an empty Array if no types exist" do @t3.transitive_types.should be_empty end end describe "#transitive_instances" do before(:each) do @st1, @st2, @st3, @st4, @st5 = @tm.get!(["st1","st2","st3", "st4", "st5"]) end it "should give back the instances if existing (and no subtypes exist)" do @t3.transitive_instances.size.should == 2 @t3.transitive_instances.should include(@t1, @t2) end it "should give back the instances and instances of subtypes" do @t3.add_subtype(@st1) @t3.add_subtype(@st2) @t3.add_subtype(@st3) @st1.add_instance(@t4) @st2.add_instance(@t5) ### @t3.transitive_instances.size.should == 4 @t3.transitive_instances.should include(@t1, @t2, @t4, @t5) end it "should give back the instances and but no subtypes" do @t3.add_subtype(@st1) @t3.add_subtype(@st2) @t3.add_subtype(@st3) @t3.transitive_instances.size.should == 2 @t3.transitive_instances.should include(@t1, @t2) end it "should give back the instances and instances of transitive subtypes" do @t3.add_subtype(@st1) @t3.add_subtype(@st2) @t3.add_subtype(@st3) @st3.add_subtype(@st4) @st1.add_instance(@t4) @st2.add_instance(@t5) @st4.add_instance(@t3) #bad user ### @t3.transitive_instances.size.should == 5 @t3.transitive_instances.should include(@t1, @t2, @t3, @t4, @t5) end it "should give back no duplicates" do @t3.add_subtype(@st1) @t3.add_subtype(@t3) #bad user @st1.add_instance(@t2) #duplicate also ### @t3.transitive_instances.size.should == 2 @t3.transitive_instances.should include(@t1, @t2) end end end end