1
2
3
4
5
6 package org.weda.store.functions;
7
8 import junit.framework.TestCase;
9
10 /**
11 *
12 * @author Mikhail Titov
13 */
14 public class SumTest extends TestCase{
15
16 public SumTest(String name) {
17 super(name);
18 }
19
20 public void test_sum_of_integers() throws Exception {
21 Sum sum = new Sum();
22 sum.startCalculation(Integer.class);
23 for (int i=0; i<5; ++i)
24 sum.nextCalculation(1);
25 sum.nextCalculation(null);
26 sum.finishCalculation();
27 assertEquals(5l, sum.getResultValue());
28
29 sum.startCalculation(Long.class);
30 for (int i=0; i<5; ++i)
31 sum.nextCalculation(1);
32 sum.nextCalculation(null);
33 sum.finishCalculation();
34 assertEquals(5l, sum.getResultValue());
35
36 sum.startCalculation(Short.class);
37 sum.nextCalculation(null);
38 sum.nextCalculation(null);
39 assertNull(sum.getResultValue());
40 }
41
42 public void test_sum_of_real_numbers() throws Exception {
43 Sum sum = new Sum();
44 sum.startCalculation(Float.class);
45 for (int i=0; i<5; ++i)
46 sum.nextCalculation(1.1);
47 assertEquals(new Double(5.5), sum.getResultValue());
48
49 }
50
51 }