File: SymbolSerializationTest.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 (70 lines) | stat: -rw-r--r-- 1,723 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package org.biojava.bio.symbol;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Arrays;
import java.util.List;

import junit.framework.TestCase;

import org.biojava.bio.seq.DNATools;

/**
 * Tests that serilization works as advertised.
 *
 * @author Thomas Down
 * @author Mark Schreiber
 * @since 1.3
 */

public class SymbolSerializationTest extends TestCase {
    public SymbolSerializationTest(String name){
        super(name);
    }

    private void doSymbolTest(Symbol s)
        throws Exception
    {
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream((os));
        oos.writeObject(s);
        oos.flush();
        oos.close();

        ObjectInputStream ois = new ObjectInputStream(
                new ByteArrayInputStream(os.toByteArray()));
        Symbol s2 = (Symbol) ois.readObject();
        ois.close();

        assertTrue(s == s2);
    }

    public void testAtomic()
        throws Exception
    {
        doSymbolTest(DNATools.t());
    }

    public void testAmbiguous()
        throws Exception
    {
        doSymbolTest(DNATools.n());
    }
    
    
    public void testSpecialGap() throws Exception{
        doSymbolTest(AlphabetManager.getGapSymbol());
    }
    
    public void testCompoundGap() throws Exception{
        List alphas = Arrays.asList(new Alphabet[]{DNATools.getDNA(), DNATools.getDNA()});
        doSymbolTest(AlphabetManager.getGapSymbol(alphas));
    }
    
    public void testNormalGap() throws Exception{
        doSymbolTest(
                DNATools.getDNA().getGapSymbol());
    }
}