+ if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
+ return false;
+ }
+ br = iter.next();
+ if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
+ return false;
+ }
+ if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
+ return false;
+ }
+ br = iter.next();
+ if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
+ return false;
+ }
+ if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
+ return false;
+ }
+ br = iter.next();
+ if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
+ return false;
+ }
+ if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
+ return false;
+ }
+ br = iter.next();
+ if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
+ return false;
+ }
+ if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
+ return false;
+ }
+ br = iter.next();
+ if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
+ return false;
+ }
+ if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
+ return false;
+ }
+ br = iter.next();
+ if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
+ return false;
+ }
+ if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
+ return false;
+ }
+ br = iter.next();
+ if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
+ return false;
+ }
+ if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
+ return false;
+ }
+ br = iter.next();
+ if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
+ return false;
+ }
+ if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
+ return false;
+ }
+ br = iter.next();
+ if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
+ return false;
+ }
+ if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
+ return false;
+ }
+ br = iter.next();
+ if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
+ return false;
+ }
+ if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
+ return false;
+ }
+ br = iter.next();
+ if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
+ return false;
+ }
+ if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
+ return false;
+ }
+ if ( iter.hasNext() ) {
+ return false;
+ }
+ final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
+ final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
+ final Iterator<PhylogenyBranch> iter1 = l1.iterator();
+ br = iter1.next();
+ if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
+ return false;
+ }
+ if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
+ return false;
+ }
+ br = iter1.next();
+ if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
+ return false;
+ }
+ if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
+ return false;
+ }
+ br = iter1.next();
+ if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
+ return false;
+ }
+ if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
+ return false;
+ }
+ if ( iter1.hasNext() ) {
+ return false;
+ }
+ final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
+ final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
+ final Iterator<PhylogenyBranch> iter2 = l2.iterator();
+ br = iter2.next();
+ if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
+ return false;
+ }
+ if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
+ return false;
+ }
+ br = iter2.next();
+ if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
+ return false;
+ }
+ if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
+ return false;
+ }
+ br = iter2.next();
+ if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
+ return false;
+ }
+ if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
+ return false;
+ }
+ if ( iter2.hasNext() ) {
+ return false;
+ }
+ final Phylogeny species0 = factory
+ .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
+ new NHXParser() )[ 0 ];
+ final Phylogeny gene1 = factory
+ .create( "(((((A:0.6[&&NHX:S=A],B:0.1[&&NHX:S=B])ab:0.1,C:0.1[&&NHX:S=C])abc:0.3,D:1.0[&&NHX:S=D])abcd:0.2,E:0.1[&&NHX:S=E])abcde:0.2,F:0.2[&&NHX:S=F])",
+ new NHXParser() )[ 0 ];
+ species0.setRooted( true );
+ gene1.setRooted( true );
+ final SDIR sdi_unrooted = new SDIR();
+ sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
+ if ( sdi_unrooted.getCount() != 1 ) {
+ return false;
+ }
+ if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
+ return false;
+ }
+ if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
+ return false;
+ }
+ if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
+ return false;
+ }
+ if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
+ return false;
+ }
+ final Phylogeny gene2 = factory
+ .create( "(((((A:2.6[&&NHX:S=A],B:0.1[&&NHX:S=B])ab:0.1,C:0.1[&&NHX:S=C])abc:0.3,D:1.0[&&NHX:S=D])abcd:0.2,E:0.1[&&NHX:S=E])abcde:0.2,F:0.2[&&NHX:S=F])",
+ new NHXParser() )[ 0 ];
+ gene2.setRooted( true );
+ sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
+ if ( sdi_unrooted.getCount() != 1 ) {
+ return false;
+ }
+ if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
+ return false;
+ }
+ if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
+ return false;
+ }
+ if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
+ return false;
+ }
+ if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
+ return false;
+ }
+ final Phylogeny species6 = factory
+ .create( "(((1:[&&NHX:S=1],5:[&&NHX:S=5])1-5,((4:[&&NHX:S=4],6:[&&NHX:S=6])4-6,2:[&&NHX:S=2])4-6-2)1-5-4-6-2,"
+ + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
+ new NHXParser() )[ 0 ];
+ final Phylogeny gene6 = factory
+ .create( "((5:0.1[&&NHX:S=5],6:0.1[&&NHX:S=6])5-6:0.05[&&NHX:S=6],(4:0.1[&&NHX:S=4],"
+ + "(((1:0.1[&&NHX:S=1],2:0.1[&&NHX:S=2])1-2:0.1[&&NHX:S=2],3:0.25[&&NHX:S=3])1-2-3:0.2[&&NHX:S=2],"
+ + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
+ + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
+ + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
+ new NHXParser() )[ 0 ];
+ species6.setRooted( true );
+ gene6.setRooted( true );
+ Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
+ if ( sdi_unrooted.getCount() != 1 ) {
+ return false;
+ }
+ if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
+ return false;
+ }
+ if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
+ return false;
+ }
+ if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
+ return false;
+ }
+ if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
+ return false;
+ }
+ if ( !p6[ 0 ].getRoot().isDuplication() ) {
+ return false;
+ }
+ if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
+ return false;
+ }
+ if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
+ return false;
+ }
+ if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
+ return false;
+ }
+ if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
+ return false;
+ }
+ if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
+ return false;
+ }
+ if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
+ return false;
+ }
+ if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
+ return false;
+ }
+ p6 = null;
+ final Phylogeny species7 = factory
+ .create( "(((1:[&&NHX:S=1],5:[&&NHX:S=5])1-5,((4:[&&NHX:S=4],6:[&&NHX:S=6])4-6,2:[&&NHX:S=2])4-6-2)1-5-4-6-2,"
+ + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
+ new NHXParser() )[ 0 ];
+ final Phylogeny gene7 = factory
+ .create( "((5:0.1[&&NHX:S=5],6:0.1[&&NHX:S=6])5-6:0.05[&&NHX:S=6],(4:0.1[&&NHX:S=4],"
+ + "(((1:0.1[&&NHX:S=1],2:0.1[&&NHX:S=2])1-2:0.1[&&NHX:S=2],3:0.25[&&NHX:S=3])1-2-3:0.2[&&NHX:S=2],"
+ + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
+ + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
+ + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
+ new NHXParser() )[ 0 ];
+ species7.setRooted( true );
+ gene7.setRooted( true );
+ Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
+ if ( sdi_unrooted.getCount() != 1 ) {
+ return false;
+ }
+ if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
+ return false;
+ }
+ if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
+ return false;
+ }
+ if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
+ return false;
+ }
+ if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
+ return false;
+ }
+ if ( !p7[ 0 ].getRoot().isDuplication() ) {
+ return false;
+ }
+ if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
+ return false;
+ }
+ if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
+ return false;
+ }
+ if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
+ return false;
+ }
+ if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
+ return false;
+ }
+ if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
+ return false;
+ }
+ if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
+ return false;
+ }
+ if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
+ return false;
+ }
+ p7 = null;
+ final Phylogeny species8 = factory
+ .create( "(((1:[&&NHX:S=1],5:[&&NHX:S=5])1-5,((4:[&&NHX:S=4],6:[&&NHX:S=6])4-6,2:[&&NHX:S=2])4-6-2)1-5-4-6-2,"
+ + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
+ new NHXParser() )[ 0 ];
+ final Phylogeny gene8 = factory
+ .create( "((5:0.1[&&NHX:S=5],6:0.1[&&NHX:S=6])5-6:0.05[&&NHX:S=6],(4:0.1[&&NHX:S=4],"
+ + "(((1:0.1[&&NHX:S=1],2:0.1[&&NHX:S=2])1-2:0.1[&&NHX:S=2],3:0.25[&&NHX:S=3])1-2-3:0.2[&&NHX:S=2],"
+ + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
+ + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
+ + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
+ new NHXParser() )[ 0 ];
+ species8.setRooted( true );
+ gene8.setRooted( true );
+ Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
+ if ( sdi_unrooted.getCount() != 1 ) {
+ return false;
+ }
+ if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
+ return false;
+ }
+ if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
+ return false;
+ }
+ if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
+ return false;
+ }
+ if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
+ return false;
+ }
+ if ( !p8[ 0 ].getRoot().isDuplication() ) {
+ return false;
+ }
+ if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
+ return false;
+ }
+ if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
+ return false;
+ }
+ if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
+ return false;
+ }
+ if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
+ return false;
+ }
+ if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
+ return false;
+ }
+ if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
+ return false;
+ }
+ if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
+ return false;
+ }
+ p8 = null;