1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
/*
* BioJava development code
*
* This code may be freely distributed and modified under the
* terms of the GNU Lesser General Public Licence. This should
* be distributed with the code. If you do not have a copy,
* see:
*
* http://www.gnu.org/copyleft/lesser.html
*
* Copyright for this code is held jointly by the individual
* authors. These should be listed in @author doc comments.
*
* For more information on the BioJava project and its aims,
* or to join the biojava-l mailing list, visit the home page
* at:
*
* http://www.biojava.org/
*
*/
/*
* SimpleSymbolPropertyTableDBTest.java
*/
package org.biojava.bio.proteomics.aaindex;
import java.util.ArrayList;
import java.util.Set;
import junit.framework.TestCase;
import org.biojava.bio.BioException;
import org.biojava.bio.seq.DNATools;
import org.biojava.bio.seq.ProteinTools;
import org.biojava.bio.seq.db.IllegalIDException;
import org.biojava.bio.symbol.SimpleSymbolPropertyTable;
import org.biojava.bio.symbol.SymbolPropertyTable;
/**
* Test class for {@link org.biojava.bio.proteomics.aaindex.SimpleSymbolPropertyTableDB}.
* @author <a href="mailto:Martin.Szugat@GMX.net">Martin Szugat</a>
* @version $Revision: 4023 $
*/
public class SimpleSymbolPropertyTableDBTest extends TestCase {
/**
* Main entry point.
* @param args command line arguments
*/
public static void main(String[] args) {
junit.textui.TestRunner.run(SimpleSymbolPropertyTableDBTest.class);
}
/**
* Test constructor to create an empty database.
*/
public void testEmptyConstructor() {
SymbolPropertyTableDB db = new SimpleSymbolPropertyTableDB();
assertEquals("Database is not empty.", 0, db.numTables());
assertFalse("Database does not return an empty iterator.",
db.tableIterator().hasNext());
}
/**
* Test constructor to create a non-empty database.
* @throws BioException if iterator fails.
*/
public void testNonEmptyConstructor() throws BioException {
SimpleSymbolPropertyTableDB dbInit = new SimpleSymbolPropertyTableDB();
SymbolPropertyTable t1 = new SimpleSymbolPropertyTable(
ProteinTools.getAlphabet(), "protein");
SymbolPropertyTable t2 = new SimpleSymbolPropertyTable(
DNATools.getDNA(), "dna");
dbInit.addTable(t1);
dbInit.addTable(t2);
SymbolPropertyTableDB db = new SimpleSymbolPropertyTableDB(
dbInit.tableIterator());
assertEquals("Database has wrong number of tables.", 2, db.numTables());
SymbolPropertyTableIterator iterator = db.tableIterator();
ArrayList tables = new ArrayList(2);
while (iterator.hasNext()) {
tables.add(iterator.nextTable());
}
assertEquals("Iterator returned wrong number of tables.",
2, tables.size());
assertEquals("Iterator returned wrong table.", t1, tables.get(0));
assertEquals("Iterator returned wrong table.", t2, tables.get(1));
}
/**
* Test for {@link SimpleSymbolPropertyTableDB#addTable(SymbolPropertyTable)}.
* @throws IllegalIDException if {@link SymbolPropertyTableDB#table(String)}
* fails.
*/
public void testAddTable() throws IllegalIDException {
SimpleSymbolPropertyTableDB db = new SimpleSymbolPropertyTableDB();
SymbolPropertyTable t1 = new SimpleSymbolPropertyTable(
ProteinTools.getAlphabet(), "protein");
SymbolPropertyTable t2 = new SimpleSymbolPropertyTable(
DNATools.getDNA(), "dna");
db.addTable(t1);
assertEquals("Database has wrong number of tables.", 1, db.numTables());
db.addTable(t2);
assertEquals("Database has wrong number of tables.", 2, db.numTables());
assertEquals("Database returned wrong table.", t1, db.table("protein"));
assertEquals("Database returned wrong table.", t2, db.table("dna"));
Set names = db.names();
assertTrue("Table is missing.", names.contains("protein"));
assertTrue("Table is missing.", names.contains("dna"));
assertEquals("Database has wrong number of tables.", 2, names.size());
try {
db.addTable(null);
fail("addTable must throw NullPointerException.");
} catch (NullPointerException e) {
e.printStackTrace();
}
}
/**
* Test for {@link SimpleSymbolPropertyTableDB#table(String)}.
*/
public void testTable() {
SimpleSymbolPropertyTableDB db = new SimpleSymbolPropertyTableDB();
try {
db.table(null);
fail("table must throw NullPointerException.");
} catch (NullPointerException e) {
e.printStackTrace();
} catch (IllegalIDException e) {
fail("table throwed IllegalIDException instead of NullPointerException.");
}
try {
db.table("test");
fail("table must throw IllegalIDException.");
} catch (IllegalIDException e) {
e.printStackTrace();
}
}
}
|