Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Date: Jan 30, 2002
* Time: 5:53:55 PM
* @author <a href="mailto:[email protected]">Hendrik Schreiber</a>
*
*/
public class TestDoubleData {

Expand All @@ -18,14 +19,27 @@ public void testSimpleAverage() throws Exception {
assertEquals("Simple average", 1.5, DoubleData.average(x), 0.0);
}

@Test
public void testSimpleStandardDeviation() throws Exception {
DoubleData doubleData = new DoubleData();
doubleData.add(1);
doubleData.add(1);
doubleData.add(-1);
doubleData.add(-1);

assertEquals("Simple std deviation", 1.1547005383792515, doubleData.standardDeviation(), 0.0000001);
}

@Test
public void testWeightedAverage() {
double[] n = {4.0, 5.0, 6.0};
int[] weight = {2, 3, 4};
assertEquals(5.222, DoubleData.weightedAverage(n, weight), 0.001);
}

@Test
public void testWeightedAverageNaN() {
double[] n = {Double.NaN};
int[] weight = {6, -1, 0, 0};
assertEquals(Double.NaN, DoubleData.weightedAverage(n, weight), 0.0);
}
}