# 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::Counterparts describe self do before(:each) do @tm = get_used_tm_sys_tm @t1,@t2,@t3,@t4,@t5 = @tm.get!(["t1","t2","t3","t4","t5"]) @t_a1,@t_a2,@t_a3 = @tm.get!(["t_a1","t_a2","t_a3"]) @t_r1,@t_r2,@t_r3,@t_r4,@t_r5 = @tm.get!(["t_r1","t_r2","t_r3","t_r4","t_r5"]) @a1 = @tm.create_association(@t_a1) @a2 = @tm.create_association(@t_a2) @a3 = @tm.create_association(@t_a1) @a4 = @tm.create_association(@t_a3) @a5 = @tm.create_association(@t_a1) @r1 = @a1.create_role(@t_r1, @t1) @r2 = @a1.create_role(@t_r2, @t2) @r3 = @a1.create_role(@t_r1, @t4) @r4 = @a2.create_role(@t_r1, @t1) @r5 = @a2.create_role(@t_r3, @t3) @r6 = @a3.create_role(@t_r4, @t1) @r7 = @a3.create_role(@t_r5, @t5) @r8 = @a4.create_role(@t_r4, @t4) @r9 = @a4.create_role(@t_r5, @t4) @r10= @a5.create_role(@t_r2, @t5) @lonely_topic = @tm.get!("lonely") end after(:each) do @tm.close end describe "#counterparts" do it "should return an empty Array if this Topic playes no Roles" do @lonely_topic.counterparts.should be_empty end it "should return all counterparts if no filter is given" do @t1.counterparts.size.should == 4 @t1.counterparts.should include @r2, @r3, @r5, @r7 @t3.counterparts.first.should == @r4 end it "should return some counterparts if the roletype is filtered" do @t1.counterparts({:rtype => @t_r1}).size.should == 3 @t1.counterparts({:rtype => @t_r1}).should include @r2, @r3, @r5 @t3.counterparts({:rtype => @t_r1}).should be_empty @t3.counterparts({:rtype => "test"}).should be_empty end it "should return some counterparts if the associationtype is filtered" do @t1.counterparts({:atype => @t_a1}).size.should == 3 @t1.counterparts({:atype => @t_a1}).should include @r2, @r3, @r7 @t1.counterparts({:atype => @t_a3}).should be_empty end it "should return some counterparts if the other-roletype is filtered" do @t1.counterparts({:otype => @t_r5}).size.should == 1 @t1.counterparts({:otype => @t_r5}).should include @r7 end it "should return some counterparts if roletype, associationstype and other-roletype is filtered" do @t1.counterparts({:rtype => @t_r1, :atype => @t_a1, :otype => @t_r2}).size.should == 1 @t1.counterparts({:rtype => @t_r1, :atype => @t_a1, :otype => @t_r1}).should include @r3 end it "should handle circular associations" do @t4.counterparts(:atype => @t_a3).size.should == 2 @t4.counterparts(:atype => @t_a3).should include @r8 end end describe "#counterplayers" do it "should return an empty Array if this Topic playes no Roles" do @lonely_topic.counterplayers.should be_empty end it "should return all counterplayers if no filter is given" do @t1.counterplayers.size.should == 4 @t1.counterplayers.should include @t2, @t3, @t4, @t5 @t3.counterplayers.first.should == @t1 end it "should return some counterplayers if the roletype is filtered" do @t1.counterplayers({:rtype => @t_r1}).size.should == 3 @t1.counterplayers({:rtype => @t_r1}).should include @t2, @t3, @t4 @t3.counterplayers({:rtype => @t_r1}).should be_empty @t3.counterplayers({:rtype => "test"}).should be_empty end it "should return some counterplayers if the associationtype is filtered" do @t1.counterplayers(:atype => @t_a1).size.should == 3 @t1.counterplayers(:atype => @t_a1).should include @t2, @t4, @t5 @t1.counterplayers(:atype => @t_a3).should be_empty end it "should return some counterplayers if the other-roletype is filtered" do @t1.counterplayers(:otype => @t_r5).size.should == 1 @t1.counterplayers(:otype => @t_r5).should include @t5 end it "should return some counterplayers if roletype, associationstype and other-roletype is filtered" do @t1.counterplayers(:rtype => @t_r1, :atype => @t_a1, :otype => @t_r2).size.should == 1 @t1.counterplayers(:rtype => @t_r1, :atype => @t_a1, :otype => @t_r1).should include @t4 end it "should handle circular associations" do @t4.counterplayers(:atype => @t_a3).size.should == 1 @t4.counterplayers(:atype => @t_a3).should include @t4 end it "should return a unique Array" do result = @t4.counterplayers result.size.should == 3 result.should include @t1,@t2,@t4 end end end #of describe self describe self do before(:all) do @tm = get_used_tm_sys_tm @t1,@t2,@t3,@t4,@t5,@t6,@t7,@t8 = @tm.get!(["t1","t2","t3","t4","t5","t6","t7","t8"]) @t_a1,@t_a2 = @tm.get!(["t_a1","t_a2"]) t_r1,t_r2,t_r3,t_r4,t_r5,t_r6 = @tm.get!(["t_r1","t_r2","t_r3","t_r4","t_r5","t_r6"]) a1 = @tm.create_association(@t_a1) a2 = @tm.create_association(@t_a1) a3 = @tm.create_association(@t_a1) a4 = @tm.create_association(@t_a1) a5 = @tm.create_association(@t_a1) a6 = @tm.create_association(@t_a2) r1 = a1.create_role(t_r1, @t1) r2 = a1.create_role(t_r3, @t2) r4 = a2.create_role(t_r1, @t1) r5 = a2.create_role(t_r3, @t3) r6 = a3.create_role(t_r1, @t1) r7 = a3.create_role(t_r5, @t5) r3 = a4.create_role(t_r1, @t1) r8 = a4.create_role(t_r3, @t4) r9 = a4.create_role(t_r6, @t6) r10 = a5.create_role(t_r4, @t1) r11 = a5.create_role(t_r3, @t7) r12 = a6.create_role(t_r4, @t1) r13 = a6.create_role(t_r2, @t8) end after(:all) do @tm.close end describe "#peers" do it "should give back all peers if argument = :any" do @t3.peers(:any).should == @t3.peers end it "should give back an empty Array if argument is not a Topic or Topic-Reference" do @t3.peers("noTopic").should respond_to(:each) @t3.peers("noTopic").should be_empty end it "should give back all peers" do @t3.peers.size.should == 6 #loose @t3.should have(6).peers @t3.peers.should include @t2,@t4,@t5,@t6,@t7,@t8 end it "should give back some peers if rtype is given" do @t3.peers("t_r3").size.should == 3 @t3.peers("t_r3").should include @t2,@t4,@t7 end it "should give back no peers if rtype is given but does not match" do @t3.peers("t_r6").should respond_to(:each) @t3.peers("t_r6").should be_empty end it "should give back some peers if atype is given" do @t3.peers(@t_a1).size.should == 3 @t3.peers(@t_a1).should include @t2, @t4, @t7 end it "should give back no peers if atype is given but does not match" do @t3.peers(@t_a2).should respond_to(:each) @t3.peers(@t_a2).should be_empty end end end #of describe self describe self do describe "#associations_played" do before(:each) do @tm = get_used_tm_sys_tm @topic = @tm.get!("topic") end after(:each) do @tm.close end it "should give back an empty Array if the topic plays in no association" do @topic.associations_played.should be_empty end it "should be tested" end end describe self do describe "unary associations" do before(:each) do @tm = get_used_tm_sys_tm @player = @tm.get!("player") end after(:each) do @tm.close end describe "#counterparts" do it "should handle unary associations" do @tm.create_association("assoc_type", "roletype" => "player") @player.counterparts.should be_empty @player.counterparts(:atype => "1", :rtype => "2", :otype => "3").should be_empty end end describe "#counterplayers" do it "should handle unary associations" do @tm.create_association("assoc_type", "roletype" => "player") @player.counterplayers.should be_empty @player.counterplayers(:atype => "1", :rtype => "2", :otype => "3").should be_empty end end describe "#peers" do it "should handle unary associations" do @tm.create_association("assoc_type", "roletype" => "player") @player.peers.should be_empty @player.peers("1").should be_empty end end describe "#associations_played" do it "should handle unary associations" do assoc = @tm.create_association("assoc_type", "roletype" => "player") @player.associations_played.size.should == 1 @player.associations_played.should include(assoc) end end end end end