# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig. # License: Apache License, Version 2.0 require File.dirname(__FILE__) + '/../../../spec_helper' module RTM::Sugar::Role module 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) end after(:each) do @tm.close end describe "#counterparts" do it "should give back all counterparts (roles) if no otype is given" do @r1.should have(2).counterparts @r1.counterparts.should include @r2, @r3 @r8.should have(1).counterparts @r8.counterparts.should include @r9 end it "should give back some counterparts (roles) if otype is given" do @r1.counterparts(:otype=>@t_r1).size.should == 1 @r1.counterparts(:otype=>@t_r1).should include @r3 @r6.counterparts(:otype=>@t_r1).should be_empty end end describe "#counterplayers" do it "should give back all counterplayers (topics) if no otype is given" do @r1.should have(2).counterplayers @r1.counterplayers.should include @t2, @t4 @r8.should have(1).counterplayers @r8.counterplayers.should include @t4 end it "should give back some counterplayers (topics) if otype is given " do @r1.counterplayers(:otype=>@t_r1).size.should == 1 @r1.counterplayers(:otype=>@t_r1).should include @t4 @r4.counterplayers(:otype=>@t_r2).size.should == 0 end end describe "#counterpart" do it "should give back the counterpart Role if the parent association is binary" do @r4.counterpart.should == @r5 @r5.counterpart.should == @r4 end it "should raise an error if the üparent association includes more than 2 roles" do lambda {@r2.counterpart}.should raise_error end it "should give back nil if the parent association is unary" do @r10.counterpart.should be_nil end end describe "#counterplayer" do it "should give back the counterplayer Topic if the parent association is binary" do @r6.counterplayer.should == @t5 @r5.counterplayer.should == @t1 end it "should raise an error if the parent association includes more than 2 roles" do lambda {@r2.counterplayer}.should raise_error end it "should give back nil if the parent association is unary" do @r10.counterplayer.should be_nil end end end describe self do before(:each) 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(:each) do @tm.close end describe "#peers" do it "should give back roles of other associations (with same size and atype) that have the same rtype and otype" do @r5.peers.size.should == 1 @r5.peers.should include @r2 @r5.peers(:arity => :stuff, :otype => :stuff, :atype => :stuff, :rtyoe => :stuff).should == @r5.peers end it "should give back roles of other associations (with any size but same atype) that have the same rtype and otype" do @r5.peers(:arity => :loose).size.should == 2 @r5.peers(:arity => :loose).should include @r2 @r5.peers(:arity => :loose).should include @r8 end it "should give back roles of other associations (with same size and atype) that have the same otype but not rtype" do @r5.peers(:rtype => :loose).size.should == 2 @r5.peers(:rtype => :loose).should include @r2,@r7 end it "should give back roles of other associations (with any size but same atype) that have the same otype but not rtype" do @r5.peers(:arity => :loose, :rtype => :loose).size.should == 4 @r5.peers(:arity => :loose, :rtype => :loose).should include @r2,@r7,@r8,@r9 end it "should give back roles of other associations (with same size and atype) that have any otype but same rtype" do @r5.peers(:otype => :loose).size.should == 2 @r5.peers(:otype => :loose).should include @r2,@r11 end it "should give back roles of other associations (with same size but any atype) that have any otype and rtype" do @r5.peers(:atype => :loose, :otype => :loose, :rtype => :loose).size == 4 @r5.peers(:atype => :loose, :otype => :loose, :rtype => :loose).should include @r7,@r13,@r2,@r11 end it "should raise an error if argument is not a Hash" do lambda{@r5.peers("something")}.should raise_error end end end describe self do before(:each) do @tm = get_used_tm_sys_tm @dad1 = @tm.get!("dad1") @dad2 = @tm.get!("dad2") @mom1 = @tm.get!("mom1") @mom2 = @tm.fet!("mom2") @kid1 = @tm.get!("kid1") @kid2 = @tm.get!("kid2") @kid3 = @tm.get!("kid3") @kid4 = @tm.get!("kid4") @pk = @tm.get!("parent_kid") @mr = @tm.get!("mom_role") @dr = @tm.get!("dad_role") @kr = @tm.get!("kid_role") @assoc1 = @tm.create_association(@pk) @r_a1_k1 = @assoc1.create_role(@kr,@kid1) @r_a1_m1 = @assoc1.create_role(@mr,@mom1) @r_a1_d1 = @assoc1.create_role(@dr,@dad1) @assoc2 = @tm.create_association(@pk) @r_a2_k2 = @assoc2.create_role(@kr,@kid2) @r_a2_m1 = @assoc2.create_role(@mr,@mom1) @r_a2_d1 = @assoc2.create_role(@dr,@dad1) @assoc3 = @tm.create_association(@pk) @r_a3_k3 = @assoc3.create_role(@kr,@kid3) @r_a3_m2 = @assoc3.create_role(@mr,@mom2) @r_a3_d1 = @assoc3.create_role(@dr,@dad1) @assoc4 = @tm.create_association(@pk) @r_a4_k4 = @assoc4.create_role(@kr,@kid4) @r_a4_m1 = @assoc4.create_role(@mr,@mom1) @r_a4_d2 = @assoc4.create_role(@dr,@dad2) end after(:each) do @tm.close end describe "#peers the second time" do end end end end