File: EmissionStateEventTest.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 (83 lines) | stat: -rw-r--r-- 4,144 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
71
72
73
74
75
76
77
78
79
80
81
82
83
package org.biojava.bio.dp;

import junit.framework.TestCase;

import org.biojava.bio.Annotation;
import org.biojava.bio.dist.Distribution;
import org.biojava.bio.dist.DistributionFactory;
import org.biojava.bio.seq.DNATools;
import org.biojava.bio.symbol.IllegalAlphabetException;
import org.biojava.bio.symbol.IllegalSymbolException;
import org.biojava.utils.ChangeType;
import org.biojava.utils.ChangeVetoException;

/**
 * Test emission state events.
 *
 * @author Matthew Pocock
 */
public class EmissionStateEventTest
extends TestCase {
  public void testDistribution_setWeight() {
    try {
      Distribution dist = DistributionFactory.DEFAULT.createDistribution(
              DNATools.getDNA());
      EmissionState es = new SimpleEmissionState("test",
                                                 Annotation.EMPTY_ANNOTATION,
                                                 new int[] { 1 },
                                                 dist);
      EventCounter everything = new EventCounter("Everything");
      EventCounter distC = new EventCounter("Distribution counter");
      EventCounter advC = new EventCounter("Advance counter");

      es.addChangeListener(everything, ChangeType.UNKNOWN);
      es.addChangeListener(distC, EmissionState.DISTRIBUTION);
      es.addChangeListener(advC, EmissionState.ADVANCE);

      // test setWeight - should cause a DISTRIBUTION event, and no Advance event
      dist.setWeight(DNATools.a(), 0.3);
      dist.setWeight(DNATools.a(), 0.7);
      assertEquals("No distribution events vetoed: " + distC + "\n\t" + everything, distC.getPreCounts(), distC.getPostCounts());
      assertEquals("No advance events vetoed: " + advC + "\n\t" + everything, advC.getPreCounts(), advC.getPostCounts());
      assertEquals("Two distribution events: " + distC + "\n\t" + everything, 2, distC.getPostCounts());
      assertEquals("No advance events: " + advC + "\n\t" + everything, 0, advC.getPostCounts());
    } catch (IllegalAlphabetException iae) {
      throw (AssertionError) new AssertionError("Can not create distribution.").initCause(iae);
    } catch (IllegalSymbolException ise) {
      throw (AssertionError) new AssertionError("Can not set weight.").initCause(ise);
    } catch (ChangeVetoException cve) {
      throw (AssertionError) new AssertionError("Prevented from setting weight.").initCause(cve);
    }
  }

  public void testSetDistribution() {
    try {
      Distribution dist = DistributionFactory.DEFAULT.createDistribution(
              DNATools.getDNA());
      Distribution dist2 = DistributionFactory.DEFAULT.createDistribution(
              DNATools.getDNA());
      EmissionState es = new SimpleEmissionState("test",
                                                 Annotation.EMPTY_ANNOTATION,
                                                 new int[] { 1 },
                                                 dist);
      EventCounter everything = new EventCounter("Everything");
      EventCounter distC = new EventCounter("Distribution counter");
      EventCounter advC = new EventCounter("Advance counter");

      es.addChangeListener(everything, ChangeType.UNKNOWN);
      es.addChangeListener(distC, EmissionState.DISTRIBUTION);
      es.addChangeListener(advC, EmissionState.ADVANCE);

      // test setDistribution - should cause a DISTRIBUTION event, and no Advance event
      es.setDistribution(dist2);
      assertEquals("No distribution events vetoed: " + distC + "\n\t" + everything, distC.getPreCounts(), distC.getPostCounts());
      assertEquals("No advance events vetoed: " + advC + "\n\t" + everything, advC.getPreCounts(), advC.getPostCounts());
      assertEquals("One distribution event: " + distC + "\n\t" + everything, 1, distC.getPostCounts());
      assertEquals("No advance events: " + advC + "\n\t" + everything, 0, advC.getPostCounts());
    } catch (IllegalAlphabetException iae) {
      throw (AssertionError) new AssertionError("Can not create distribution.").initCause(iae);
    } catch (ChangeVetoException cve) {
      throw (AssertionError) new AssertionError("Prevented from setting weight.").initCause(cve);
    }
  }
}