+ }
+ catch ( final Exception e ) {
+ e.printStackTrace();
+ return false;
+ }
+ return true;
+ }
+
+ private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
+ final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
+ return p;
+ }
+
+ private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
+ return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
+ }
+
+ private static boolean testAminoAcidSequence() {
+ try {
+ final MolecularSequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
+ if ( aa1.getLength() != 13 ) {
+ return false;
+ }
+ if ( aa1.getResidueAt( 0 ) != 'A' ) {
+ return false;
+ }
+ if ( aa1.getResidueAt( 2 ) != 'K' ) {
+ return false;
+ }
+ if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
+ return false;
+ }
+ final MolecularSequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
+ if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZOXU" ) ) {
+ return false;
+ }
+ final MolecularSequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
+ if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
+ return false;
+ }
+ final MolecularSequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
+ if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
+ return false;
+ }
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace();
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testBasicDomain() {
+ try {
+ final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
+ if ( !pd.getDomainId().equals( "id" ) ) {
+ return false;
+ }
+ if ( pd.getNumber() != 1 ) {
+ return false;
+ }
+ if ( pd.getTotalCount() != 4 ) {
+ return false;
+ }
+ if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
+ return false;
+ }
+ final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
+ final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
+ final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
+ final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
+ final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
+ if ( !a1.equals( a1 ) ) {
+ return false;
+ }
+ if ( !a1.equals( a1_copy ) ) {
+ return false;
+ }
+ if ( !a1.equals( a1_equal ) ) {
+ return false;
+ }
+ if ( !a1.equals( a2 ) ) {
+ return false;
+ }
+ if ( a1.equals( a3 ) ) {
+ return false;
+ }
+ if ( a1.compareTo( a1 ) != 0 ) {
+ return false;
+ }
+ if ( a1.compareTo( a1_copy ) != 0 ) {
+ return false;
+ }
+ if ( a1.compareTo( a1_equal ) != 0 ) {
+ return false;
+ }
+ if ( a1.compareTo( a2 ) != 0 ) {
+ return false;
+ }
+ if ( a1.compareTo( a3 ) == 0 ) {
+ return false;
+ }
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace( System.out );
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testBasicNodeMethods() {
+ try {
+ if ( PhylogenyNode.getNodeCount() != 0 ) {
+ return false;
+ }
+ final PhylogenyNode n1 = new PhylogenyNode();
+ final PhylogenyNode n2 = PhylogenyNode
+ .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
+ final PhylogenyNode n3 = PhylogenyNode
+ .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
+ final PhylogenyNode n4 = PhylogenyNode
+ .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
+ if ( n1.isHasAssignedEvent() ) {
+ return false;
+ }
+ if ( PhylogenyNode.getNodeCount() != 4 ) {
+ return false;
+ }
+ if ( n3.getIndicator() != 0 ) {
+ return false;
+ }
+ if ( n3.getNumberOfExternalNodes() != 1 ) {
+ return false;
+ }
+ if ( !n3.isExternal() ) {
+ return false;
+ }
+ if ( !n3.isRoot() ) {
+ return false;
+ }
+ if ( !n4.getName().equals( "n4" ) ) {
+ return false;
+ }
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace( System.out );
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testCommonPrefix() {
+ final List<String> l0 = new ArrayList<>();
+ l0.add( "abc" );
+ if ( !ForesterUtil.greatestCommonPrefix( l0 ).equals( "abc" ) ) {
+ return false;
+ }
+ final List<String> l1 = new ArrayList<>();
+ l1.add( "abc" );
+ l1.add( "abX" );
+ if ( !ForesterUtil.greatestCommonPrefix( l1 ).equals( "ab" ) ) {
+ return false;
+ }
+ final List<String> l2 = new ArrayList<>();
+ l2.add( "abc" );
+ l2.add( "abX" );
+ l2.add( "axy" );
+ if ( !ForesterUtil.greatestCommonPrefix( l2 ).equals( "a" ) ) {
+ return false;
+ }
+ final List<String> l3 = new ArrayList<>();
+ l3.add( "abXsdfsdfsdfsdfsdfsd" );
+ l3.add( "abXsdfsdfsdfsdfsdfsd" );
+ l3.add( "abc" );
+ l3.add( "abXsdfsdfsdfsdfsdfsd" );
+ l3.add( "ab" );
+ l3.add( "abc" );
+ l3.add( "ab" );
+ if ( !ForesterUtil.greatestCommonPrefix( l3 ).equals( "ab" ) ) {
+ return false;
+ }
+ final List<String> l4 = new ArrayList<>();
+ l4.add( "abXsdfsdfsdfsdfsdfsd" );
+ l4.add( "abXsdfsdfsdfsdfsdfsd" );
+ l4.add( "abc" );
+ l4.add( "Xsdfsdfsdfsdfsdfsd" );
+ l4.add( "ab" );
+ l4.add( "abc" );
+ if ( !ForesterUtil.greatestCommonPrefix( l4 ).equals( "" ) ) {
+ return false;
+ }
+ final List<String> l5 = new ArrayList<>();
+ l5.add( "" );
+ if ( !ForesterUtil.greatestCommonPrefix( l5 ).equals( "" ) ) {
+ return false;
+ }
+ final List<String> l6 = new ArrayList<>();
+ l6.add( "abc" );
+ l6.add( "abX" );
+ l6.add( "" );
+ if ( !ForesterUtil.greatestCommonPrefix( l6 ).equals( "" ) ) {
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testCommonPrefixSep() {
+ final List<String> l0 = new ArrayList<>();
+ l0.add( "a.b.c" );
+ if ( !ForesterUtil.greatestCommonPrefix( l0, "." ).equals( "a.b.c" ) ) {
+ return false;
+ }
+ final List<String> l1 = new ArrayList<>();
+ l1.add( "a.b.c" );
+ l1.add( "a.b.X" );
+ if ( !ForesterUtil.greatestCommonPrefix( l1, "." ).equals( "a.b" ) ) {
+ return false;
+ }
+ final List<String> l2 = new ArrayList<>();
+ l2.add( "a.b.c." );
+ l2.add( "a.b.X." );
+ l2.add( "a.x.y." );
+ if ( !ForesterUtil.greatestCommonPrefix( l2, "." ).equals( "a" ) ) {
+ return false;
+ }
+ final List<String> l3 = new ArrayList<>();
+ l3.add( "a/b/X/s/d/f/s/d/f/s/d/f/s/d/f/s/d/f/s/d/" );
+ l3.add( "a/b/X/s/d/f/s/d/f/s/d/f/s/d/f/s/d/f/s/d" );
+ l3.add( "a/b/c" );
+ l3.add( "a/b/X/s/d/f/s/d/f/s/d/f/s/d/f/s/d/f/s/d/" );
+ l3.add( "a/b/" );
+ l3.add( "a/b/c/" );
+ l3.add( "a/b////////" );
+ if ( !ForesterUtil.greatestCommonPrefix( l3, "/" ).equals( "a/b" ) ) {
+ return false;
+ }
+ final List<String> l4 = new ArrayList<>();
+ l4.add( "a.b.X.s.d.f.s.d.f.s.d.f.s.d.f.s.d.f.s.d" );
+ l4.add( "a.b.X.s.d.f.s.d.f.s.d.f.s.d.f.s.d.f.s.d" );
+ l4.add( "a.b.c" );
+ l4.add( "X.s.d.f.s.d.f.s.d.f.s.d.f.s.d.f.s.d..." );
+ l4.add( "a.b" );
+ l4.add( "a.b.c" );
+ if ( !ForesterUtil.greatestCommonPrefix( l4, "." ).equals( "" ) ) {
+ return false;
+ }
+ final List<String> l5 = new ArrayList<>();
+ l5.add( "" );
+ if ( !ForesterUtil.greatestCommonPrefix( l5, "_" ).equals( "" ) ) {
+ return false;
+ }
+ final List<String> l6 = new ArrayList<>();
+ l6.add( "_" );
+ l6.add( "__" );
+ if ( !ForesterUtil.greatestCommonPrefix( l6, "_" ).equals( "" ) ) {
+ return false;
+ }
+ final List<String> l7 = new ArrayList<>();
+ l7.add( "a,b,c" );
+ l7.add( "a,b,X" );
+ l7.add( "" );
+ l7.add( ",,,,,,,,,," );
+ if ( !ForesterUtil.greatestCommonPrefix( l7, "," ).equals( "" ) ) {
+ return false;
+ }
+ final List<String> l8 = new ArrayList<>();
+ l8.add( "123.304.403.04" );
+ l8.add( "123.304.403.04.02" );
+ l8.add( "123.304.403.03.03" );
+ if ( !ForesterUtil.greatestCommonPrefix( l8, "." ).equals( "123.304.403" ) ) {
+ return false;
+ }
+ final List<String> l9 = new ArrayList<>();
+ l9.add( "123.304.403.04" );
+ l9.add( "123.304.403.04.02" );
+ l9.add( "123.304.402.03.03" );
+ if ( !ForesterUtil.greatestCommonPrefix( l9, "." ).equals( "123.304" ) ) {
+ return false;
+ }
+ final List<String> l10 = new ArrayList<>();
+ l10.add( "abcde" );
+ l10.add( "adc" );
+ if ( !ForesterUtil.greatestCommonPrefix( l10, "." ).equals( "" ) ) {
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testContainsPrefix() {
+ if ( !ForesterUtil.isContainsPrefix( "a.b", "a", "." ) ) {
+ return false;
+ }
+ if ( !ForesterUtil.isContainsPrefix( "a.b.c", "a", "." ) ) {
+ return false;
+ }
+ if ( !ForesterUtil.isContainsPrefix( "a.b.c", "a.b", "." ) ) {
+ return false;
+ }
+ if ( !ForesterUtil.isContainsPrefix( "a.b", "a.b", "." ) ) {
+ return false;
+ }
+ if ( !ForesterUtil.isContainsPrefix( "a", "a", "." ) ) {
+ return false;
+ }
+ if ( !ForesterUtil.isContainsPrefix( ".a.b", ".a", "." ) ) {
+ return false;
+ }
+ if ( !ForesterUtil.isContainsPrefix( ".a.b.", ".a", "." ) ) {
+ return false;
+ }
+ if ( !ForesterUtil.isContainsPrefix( ".a.b.", ".a.", "." ) ) {
+ return false;
+ }
+ if ( !ForesterUtil.isContainsPrefix( "a..b.", "a", "." ) ) {
+ return false;
+ }
+ if ( !ForesterUtil.isContainsPrefix( "a..b.", "a..", "." ) ) {
+ return false;
+ }
+ if ( ForesterUtil.isContainsPrefix( "a", "a.b", "." ) ) {
+ return false;
+ }
+ if ( ForesterUtil.isContainsPrefix( "a_b", "a", "." ) ) {
+ return false;
+ }
+ if ( ForesterUtil.isContainsPrefix( ".a.", ".a.b.", "." ) ) {
+ return false;
+ }
+ if ( ForesterUtil.isContainsPrefix( "a.b.c", "a.x", "." ) ) {
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testUTF8ParsingFromFile() {
+ try {
+ final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
+ final Phylogeny[] phylogenies_xml = ParserBasedPhylogenyFactory.getInstance()
+ .create( new File( Test.PATH_TO_TEST_DATA + "chars.xml" ), xml_parser );
+ if ( xml_parser.getErrorCount() > 0 ) {
+ System.out.println( xml_parser.getErrorMessages().toString() );
+ return false;
+ }
+ if ( phylogenies_xml.length != 1 ) {
+ return false;
+ }
+ final Phylogeny[] phylogenies_xml2 = ParserBasedPhylogenyFactory.getInstance()
+ .create( new StringBuffer( phylogenies_xml[ 0 ].toPhyloXML( 0 ) ), xml_parser );
+ final Phylogeny[] phylogenies_nh = ParserBasedPhylogenyFactory.getInstance()
+ .create( new File( Test.PATH_TO_TEST_DATA + "chars.nh" ), new NHXParser() );
+ if ( phylogenies_nh.length != 1 ) {
+ return false;
+ }
+ final Phylogeny[] phylogenies_nex = ParserBasedPhylogenyFactory.getInstance()
+ .create( new File( Test.PATH_TO_TEST_DATA + "chars.nex" ), new NexusPhylogeniesParser() );
+ if ( phylogenies_nex.length != 1 ) {
+ return false;
+ }
+ final String[] xml_n = phylogenies_xml[ 0 ].getAllExternalNodeNames();
+ final String[] xml_n2 = phylogenies_xml2[ 0 ].getAllExternalNodeNames();
+ final String[] nh_n = phylogenies_nh[ 0 ].getAllExternalNodeNames();
+ final String[] nex_n = phylogenies_nex[ 0 ].getAllExternalNodeNames();
+ final String n0 = "AQ~!@#$%^&*()_+-=\\{}|;:\"<>?,./";
+ final String n1 = "€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜˜˜™š›œžŸ¡¢£¤¥¦§¨©ª«¬®¯°±¹²³´µ¶·¸º»¼¿À÷þÿ";
+ final String n2 = "漢字ひらがなカタカナ";
+ final String n3 = "อักษรไทย";
+ final String n4 = "繁體字";
+ final String n5 = "한글";
+ final String n6 = "देवनागरी";
+ final String n7 = "chữ Quốc ngữ";
+ final String n8 = "ру́сский язы́к";
+ final String n9 = "អក្សរខ្មែរ";
+ if ( !xml_n[ 0 ].equals( n0 ) ) {
+ System.out.println( xml_n[ 0 ] );
+ System.out.println( n0 );
+ return false;
+ }
+ if ( !xml_n2[ 0 ].equals( n0 ) ) {
+ System.out.println( xml_n2[ 0 ] );
+ System.out.println( n0 );
+ return false;
+ }
+ if ( !nh_n[ 0 ].equals( n0 ) ) {
+ System.out.println( nh_n[ 0 ] );
+ System.out.println( n0 );
+ return false;
+ }
+ if ( !nex_n[ 0 ].equals( n0 ) ) {
+ System.out.println( nex_n[ 0 ] );
+ System.out.println( n0 );
+ return false;
+ }
+ if ( !xml_n[ 1 ].equals( n1 ) ) {
+ System.out.println( xml_n[ 1 ] );
+ System.out.println( n1 );
+ return false;
+ }
+ if ( !xml_n2[ 1 ].equals( n1 ) ) {
+ System.out.println( xml_n2[ 1 ] );
+ System.out.println( n1 );
+ return false;
+ }
+ if ( !nh_n[ 1 ].equals( n1 ) ) {
+ System.out.println( nh_n[ 1 ] );
+ System.out.println( n1 );
+ return false;
+ }
+ if ( !nex_n[ 1 ].equals( n1 ) ) {
+ System.out.println( nex_n[ 1 ] );
+ System.out.println( n1 );
+ return false;
+ }
+ if ( !xml_n[ 2 ].equals( n2 ) ) {
+ System.out.println( xml_n[ 2 ] );
+ System.out.println( n2 );