1 43 44 package org.jfree.data.time.junit; 45 46 import junit.framework.Test; 47 import junit.framework.TestCase; 48 import junit.framework.TestSuite; 49 50 import org.jfree.data.time.Day; 51 import org.jfree.data.time.MovingAverage; 52 import org.jfree.data.time.TimeSeries; 53 import org.jfree.date.MonthConstants; 54 55 58 public class MovingAverageTests extends TestCase { 59 60 private static final double EPSILON = 0.0000000001; 61 62 67 public static Test suite() { 68 return new TestSuite(MovingAverageTests.class); 69 } 70 71 76 public MovingAverageTests(String name) { 77 super(name); 78 } 79 80 83 public void test1() { 84 TimeSeries source = createDailyTimeSeries1(); 85 TimeSeries maverage = MovingAverage.createMovingAverage( 86 source, "Moving Average", 3, 3 87 ); 88 89 assertEquals(7, maverage.getItemCount()); 92 double value = maverage.getValue(0).doubleValue(); 93 assertEquals(14.1, value, EPSILON); 94 value = maverage.getValue(1).doubleValue(); 95 assertEquals(13.4, value, EPSILON); 96 value = maverage.getValue(2).doubleValue(); 97 assertEquals(14.433333333333, value, EPSILON); 98 value = maverage.getValue(3).doubleValue(); 99 assertEquals(14.933333333333, value, EPSILON); 100 value = maverage.getValue(4).doubleValue(); 101 assertEquals(19.8, value, EPSILON); 102 value = maverage.getValue(5).doubleValue(); 103 assertEquals(15.25, value, EPSILON); 104 value = maverage.getValue(6).doubleValue(); 105 assertEquals(12.5, value, EPSILON); 106 } 107 108 113 private TimeSeries createDailyTimeSeries1() { 114 115 TimeSeries series = new TimeSeries("Series 1", Day.class); 116 series.add(new Day(11, MonthConstants.AUGUST, 2003), 11.2); 117 series.add(new Day(13, MonthConstants.AUGUST, 2003), 13.8); 118 series.add(new Day(17, MonthConstants.AUGUST, 2003), 14.1); 119 series.add(new Day(18, MonthConstants.AUGUST, 2003), 12.7); 120 series.add(new Day(19, MonthConstants.AUGUST, 2003), 16.5); 121 series.add(new Day(20, MonthConstants.AUGUST, 2003), 15.6); 122 series.add(new Day(25, MonthConstants.AUGUST, 2003), 19.8); 123 series.add(new Day(27, MonthConstants.AUGUST, 2003), 10.7); 124 series.add(new Day(28, MonthConstants.AUGUST, 2003), 14.3); 125 return series; 126 127 } 128 129 } 130 | Popular Tags |