File: DPSerializationTest.java

package info (click to toggle)
biojava-live 1%3A1.7.1-8
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 55,160 kB
  • sloc: java: 180,820; xml: 6,908; sql: 510; makefile: 50
file content (51 lines) | stat: -rw-r--r-- 1,590 bytes parent folder | download | duplicates (7)
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
/*
 * DPSerializationTest.java
 * JUnit based test
 *
 * Created on September 27, 2007, 10:17 AM
 */

package org.biojava.bio.dp;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import junit.framework.*;
import org.biojava.bio.dist.DistributionFactory;
import org.biojava.bio.dp.onehead.SingleDP;
import org.biojava.bio.seq.DNATools;

/**
 * Test of fix for bug #2359
 * @author Mark Schreiber
 */
public class DPSerializationTest extends TestCase {
    
    public DPSerializationTest(String testName) {
        super(testName);
    }
    
    public void testDPSerialization() throws Exception{
        MarkovModel model = new ProfileHMM(DNATools.getDNA(),5,DistributionFactory.DEFAULT, DistributionFactory.DEFAULT, "test");
        DP singleDP = new SingleDP(model);
        
        MarkovModel model2 = new SimpleMarkovModel(2, DNATools.getDNA(), "pair");
        DP pairDP = DPFactory.DEFAULT.createDP(model2);
        
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        oos.writeObject(singleDP);
        oos.writeObject(pairDP);
        oos.flush();
        oos.close();
        
        
        ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
        DP dp = (DP)ois.readObject();
        assertEquals(singleDP.getClass(), dp.getClass());
        
        DP dp2 = (DP)ois.readObject();
        assertEquals(pairDP.getClass(), dp2.getClass());
    }
}