1
//Licensed to the Apache Software Foundation (ASF) under one
2
//or more contributor license agreements. See the NOTICE file
3
//distributed with this work for additional information
4
//regarding copyright ownership. The ASF licenses this file
5
//to you under the Apache License, Version 2.0 (the
6
//"License"); you may not use this file except in compliance
7
//with the License. You may obtain a copy of the License at
9
//http://www.apache.org/licenses/LICENSE-2.0
11
//Unless required by applicable law or agreed to in writing,
12
//software distributed under the License is distributed on an
13
//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
//KIND, either express or implied. See the License for the
15
//specific language governing permissions and limitations
18
package org.apache.commons.math.stat.descriptive.moment;
20
import org.apache.commons.math.DimensionMismatchException;
21
import org.apache.commons.math.TestUtils;
23
import junit.framework.Test;
24
import junit.framework.TestCase;
25
import junit.framework.TestSuite;
27
public class VectorialMeanTest
30
public VectorialMeanTest(String name) {
35
public void testMismatch() {
37
new VectorialMean(8).increment(new double[5]);
38
fail("an exception should have been thrown");
39
} catch (DimensionMismatchException dme) {
40
assertEquals(5, dme.getDimension1());
41
assertEquals(8, dme.getDimension2());
42
} catch (Exception e) {
43
fail("wrong exception type caught: " + e.getClass().getName());
47
public void testSimplistic() throws DimensionMismatchException {
48
VectorialMean stat = new VectorialMean(2);
49
stat.increment(new double[] {-1.0, 1.0});
50
stat.increment(new double[] { 1.0, -1.0});
51
double[] mean = stat.getResult();
52
assertEquals(0.0, mean[0], 1.0e-12);
53
assertEquals(0.0, mean[1], 1.0e-12);
56
public void testBasicStats() throws DimensionMismatchException {
58
VectorialMean stat = new VectorialMean(points[0].length);
59
for (int i = 0; i < points.length; ++i) {
60
stat.increment(points[i]);
63
assertEquals(points.length, stat.getN());
65
double[] mean = stat.getResult();
66
double[] refMean = new double[] { 1.78, 1.62, 3.12};
68
for (int i = 0; i < mean.length; ++i) {
69
assertEquals(refMean[i], mean[i], 1.0e-12);
74
public void testSerial() throws DimensionMismatchException {
75
VectorialMean stat = new VectorialMean(points[0].length);
76
for (int i = 0; i < points.length; ++i) {
77
stat.increment(points[i]);
79
assertEquals(stat, TestUtils.serializeAndRecover(stat));
83
points = new double[][] {
93
public void tearDown() {
97
public static Test suite() {
98
return new TestSuite(VectorialMeanTest.class);
101
private double [][] points;