Guest User

Untitled

a guest
Feb 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.83 KB | None | 0 0
  1. import static org.junit.Assert.*;
  2. import java.util.Scanner;
  3. import org.junit.*;
  4.  
  5.  
  6. /**
  7.  * Class for running JUNit tests with different implementations of IDnaStrand. To use
  8.  * a different implementation alter the method <code>getNewStrand</code> since that method
  9.  * is called by all JUnit tests to create the IDnaStrand objects being tested.
  10.  *
  11.  * @author ola
  12.  * @date January 2008, modifed and commented in September 2008
  13.  * @version 2.0, January 2009, added splice testing
  14.  */
  15.  
  16. public class TestStrand {
  17.  
  18.     private static String[] strs = { "aggtccg",
  19.                                          "aaagggtttcccaaagggtttccc",
  20.                                      "a", "g", "",
  21.                                      "aggtccgttccggttaaggagagagagagagttt" };
  22.  
  23.    
  24.     /**
  25.      * Return a strand to test by other JUnit tests
  26.      * @param s is the string modeled by an IDnaStrand implementation
  27.      * @return an IDnaStrand object for testing in this JUnit testing class.
  28.      */
  29.     public IDnaStrand getNewStrand(String s) {
  30.     //return new LinkStrand(s);
  31.         return new SimpleStrand(s);
  32.     }
  33.  
  34.     @Test
  35.     public void testReverse(){
  36.         for(String s : strs){
  37.             IDnaStrand strand = getNewStrand(s);
  38.             IDnaStrand rev = strand.reverse();
  39.             String rs = new StringBuilder(s).reverse().toString();
  40.             assertEquals("reverse fail for "+s,rev.toString(),rs);
  41.         }
  42.     }
  43.    
  44.     @Test
  45.     public void testSplice(){
  46.           String r = "gat";
  47.           String sp = "xxyyzz";
  48.           String[] strands = { "ttgatcc", "tcgatgatgattc",
  49.                                "tcgatctgatttccgatcc", "gat",
  50.                                    "gatctgatctgat", "gtacc","gatgatgat" };
  51.           String[] recombs = { "ttxxyyzzcc", "tcxxyyzzxxyyzzxxyyzztc",
  52.                                "tcxxyyzzctxxyyzzttccxxyyzzcc", "xxyyzz",
  53.                                "xxyyzzctxxyyzzctxxyyzz","","xxyyzzxxyyzzxxyyzz" };
  54.        
  55.           for (int k = 0; k < strands.length; k++) {
  56.               IDnaStrand str = getNewStrand(strands[k]);
  57.               String bef = str.toString();
  58.               IDnaStrand rec = str.cutAndSplice(r,sp);
  59.               assertEquals("splice return fail at " + k, recombs[k], rec.toString());
  60.               assertEquals("self alter fail " + k, str.toString(), bef);
  61.           }
  62.     }
  63.  
  64.  
  65.     @Test
  66.     public void testInitialize() {
  67.  
  68.         for (String s : strs) {
  69.             IDnaStrand str = getNewStrand("");
  70.             str.initializeFrom(s);
  71.             assertEquals("init lengths differ for " + s + " : ", s.length(),
  72.                     str.size());
  73.             assertEquals("init strings differ ", s, str.toString());
  74.         }
  75.     }
  76.  
  77.     @Test
  78.     public void testSize() {
  79.         for (String s : strs) {
  80.             IDnaStrand str = getNewStrand(s);
  81.             assertEquals("construct lengths differ: ", s.length(), str.size());
  82.         }
  83.     }
  84.  
  85.     @Test
  86.     public void testToString() {
  87.         for (String s : strs) {
  88.             IDnaStrand str = getNewStrand(s);
  89.             assertEquals("toString differs: ", s, str.toString());
  90.             assertEquals("toString size fail "+s,s.length(), str.size());
  91.         }
  92.     }
  93.  
  94.     @Test
  95.     public void testAppend() {
  96.         String app = "gggcccaaatttgggcccaaattt";
  97.         for (String s : strs) {
  98.             IDnaStrand str = getNewStrand(s);
  99.             str.append(app);
  100.             assertEquals("append fail: ", s + app, str.toString());
  101.             assertEquals("append size fail,"+str,s.length()+app.length(),str.size());
  102.         }
  103.     }
  104.    
  105.     @Test
  106.     public void testDoubleAppend() {
  107.         String a = "agct";
  108.         IDnaStrand str = getNewStrand(a);
  109.         str.append(a);
  110.         str.append(a);
  111.         String trip = a+a+a;
  112.         assertEquals("double append fail",trip,str.toString());
  113.     }
  114.  
  115. }
Add Comment
Please, Sign In to add comment