View Javadoc

1   /*
2    * Created by smenor on Jan 6, 2005
3    *
4    * Copyright (C) 2005
5    * Arizona State University - Cancer Research Institute
6    * All rights Reserved.
7    */
8   package edu.asu.cri.MirkE.dataStructures;
9   
10  import junit.framework.TestCase;
11  
12  /***
13   * @author smenor
14   *
15   */
16  public class MeasuredValueTest extends TestCase {
17      MeasuredValue firstMeasuredValueWithUnitA;
18      MeasuredValue secondMeasuredValueWithUnitA;
19      MeasuredValue firstMeasuredValueWithUnitB;
20      MeasuredValue secondMeasuredValueWithUnitB;
21      MeasuredValue zeroMeasuredValueWithUnitA;
22      
23      /***
24       * @param args
25       */
26      public static void main(String[] args) {
27      }
28      
29      /*
30       * @see TestCase#setUp()
31       */
32      protected void setUp() throws Exception {
33          super.setUp();
34          firstMeasuredValueWithUnitA = new MeasuredValue(
35                  1, 
36                  .1, 
37                  Unit.createUnit("A"));
38          
39  
40          firstMeasuredValueWithUnitB = new MeasuredValue(
41                  1, 
42                  .1, 
43                  Unit.createUnit("B"));
44          
45          secondMeasuredValueWithUnitA = new MeasuredValue(
46                  2.2, 
47                  .3, 
48                  Unit.createUnit("A"));
49          
50  
51          secondMeasuredValueWithUnitB = new MeasuredValue(
52                  2.2, 
53                  .3, 
54                  Unit.createUnit("B"));
55          
56          zeroMeasuredValueWithUnitA = new MeasuredValue(
57                  0, 
58                  0, 
59                  Unit.createUnit("A"));
60      }
61      
62      /*
63       * @see TestCase#tearDown()
64       */
65      protected void tearDown() throws Exception {
66          super.tearDown();
67      }
68      
69      /***
70       * 
71       */
72      public void testAdd() {
73          assertTrue(firstMeasuredValueWithUnitA.add(firstMeasuredValueWithUnitA).equals(firstMeasuredValueWithUnitA.multiply(2)));
74          assertTrue(firstMeasuredValueWithUnitA.add(secondMeasuredValueWithUnitA).equals(secondMeasuredValueWithUnitA.add(firstMeasuredValueWithUnitA)));
75      }
76  
77      /***
78       * 
79       */
80      public void testSubtract() {
81          assertTrue(firstMeasuredValueWithUnitA.subtract(secondMeasuredValueWithUnitA).equals(
82                  firstMeasuredValueWithUnitA.add(secondMeasuredValueWithUnitA.multiply(-1))));
83          
84      }
85  
86      /***
87       * Class under test for MeasuredValue multiply(MeasuredValue)
88       */
89      public void testMultiplyMeasuredValue() {
90          assertTrue(zeroMeasuredValueWithUnitA.multiply(0).equals(zeroMeasuredValueWithUnitA));
91          assertTrue(firstMeasuredValueWithUnitA.multiply(0).equals(zeroMeasuredValueWithUnitA));
92          assertTrue(secondMeasuredValueWithUnitA.multiply(firstMeasuredValueWithUnitA).equals(firstMeasuredValueWithUnitA.multiply(secondMeasuredValueWithUnitA)));
93          assertTrue(firstMeasuredValueWithUnitB.multiply(firstMeasuredValueWithUnitA).equals(firstMeasuredValueWithUnitA.multiply(firstMeasuredValueWithUnitB))); // TODO - this fails because MeasuredUnit doesn't understand A * (A^-1) == (A^-1) * A==1
94          
95      }
96  
97      /***
98       * 
99       */
100     public void testDivide() {
101         assertTrue(firstMeasuredValueWithUnitA.divide(secondMeasuredValueWithUnitA).equals(
102                 firstMeasuredValueWithUnitA.multiply(secondMeasuredValueWithUnitA.raiseToPower(-1)))); // TODO - this fails because MeasuredUnit doesn't understand A * (A^-1) == (A^-1) * A==1
103         
104     }
105 
106     /***
107      * 
108      */
109     public void testRaiseToPower() {
110         assertTrue(firstMeasuredValueWithUnitA.raiseToPower(2).raiseToPower(1/2).equals(firstMeasuredValueWithUnitA));
111         assertTrue(firstMeasuredValueWithUnitA.raiseToPower(1/2).raiseToPower(2).equals(firstMeasuredValueWithUnitA));
112         
113     }
114 
115 }