~ubuntu-branches/ubuntu/quantal/commons-math/quantal

« back to all changes in this revision

Viewing changes to src/test/java/org/apache/commons/math/stat/descriptive/summary/SumTest.java

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan
  • Date: 2010-04-05 23:33:02 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100405233302-gpqlceked76nw28a
Tags: 2.1-1
* New upstream release.
* Bump Standards-Version to 3.8.4: no changes needed
* Bump debhelper to >= 7
* Switch to 3.0 (quilt) source format:
  - Remove B-D on quilt
  - Add d/source/format
  - Remove d/README.source

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
6
 * (the "License"); you may not use this file except in compliance with
7
7
 * the License.  You may obtain a copy of the License at
8
 
 * 
 
8
 *
9
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 
 * 
 
10
 *
11
11
 * Unless required by applicable law or agreed to in writing, software
12
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
16
 */
17
17
package org.apache.commons.math.stat.descriptive.summary;
18
18
 
19
 
import junit.framework.Test;
20
 
import junit.framework.TestSuite;
21
 
 
22
19
import org.apache.commons.math.stat.descriptive.StorelessUnivariateStatisticAbstractTest;
23
20
import org.apache.commons.math.stat.descriptive.UnivariateStatistic;
24
21
 
25
22
/**
26
23
 * Test cases for the {@link Sum} class.
27
 
 * @version $Revision: 762087 $ $Date: 2009-04-05 10:20:18 -0400 (Sun, 05 Apr 2009) $
 
24
 * @version $Revision: 902201 $ $Date: 2010-01-22 13:18:16 -0500 (Fri, 22 Jan 2010) $
28
25
 */
29
26
public class SumTest extends StorelessUnivariateStatisticAbstractTest{
30
27
 
31
28
    protected Sum stat;
32
 
    
 
29
 
33
30
    /**
34
31
     * @param name
35
32
     */
37
34
        super(name);
38
35
    }
39
36
 
40
 
    public static Test suite() {
41
 
        TestSuite suite = new TestSuite(SumTest.class);
42
 
        suite.setName("Sum Tests");
43
 
        return suite;
44
 
    }
45
 
    
46
37
    /**
47
38
     * {@inheritDoc}
48
39
     */
49
40
    @Override
50
41
    public UnivariateStatistic getUnivariateStatistic() {
51
 
        return new Sum();      
 
42
        return new Sum();
52
43
    }
53
44
 
54
45
    /**
58
49
    public double expectedValue() {
59
50
        return this.sum;
60
51
    }
61
 
    
 
52
 
 
53
    /**Expected value for  the testArray defined in UnivariateStatisticAbstractTest */
 
54
    public double expectedWeightedValue() {
 
55
        return this.weightedSum;
 
56
    }
 
57
 
62
58
    public void testSpecialValues() {
63
59
        Sum sum = new Sum();
64
60
        assertTrue(Double.isNaN(sum.getResult()));
69
65
        sum.increment(Double.NEGATIVE_INFINITY);
70
66
        assertTrue(Double.isNaN(sum.getResult()));
71
67
        sum.increment(1);
72
 
        assertTrue(Double.isNaN(sum.getResult())); 
 
68
        assertTrue(Double.isNaN(sum.getResult()));
 
69
    }
 
70
 
 
71
    public void testWeightedSum() {
 
72
        Sum sum = new Sum();
 
73
        assertEquals(expectedWeightedValue(), sum.evaluate(testArray, testWeightsArray, 0, testArray.length), getTolerance());
 
74
        assertEquals(expectedValue(), sum.evaluate(testArray, unitWeightsArray, 0, testArray.length), getTolerance());
73
75
    }
74
76
 
75
77
}