1 37 38 package org.jfree.data.junit; 39 40 import junit.framework.Test; 41 import junit.framework.TestCase; 42 import junit.framework.TestSuite; 43 44 import org.jfree.data.MovingAverage; 45 import org.jfree.data.time.Day; 46 import org.jfree.data.time.TimeSeries; 47 import org.jfree.date.SerialDate; 48 import org.jfree.util.NumberUtils; 49 50 55 public class MovingAverageTests extends TestCase { 56 57 62 public static Test suite() { 63 return new TestSuite(MovingAverageTests.class); 64 } 65 66 71 public MovingAverageTests(String name) { 72 super(name); 73 } 74 75 78 public void test1() { 79 TimeSeries source = createDailyTimeSeries1(); 80 TimeSeries maverage = MovingAverage.createMovingAverage(source, "Moving Average", 3, 3); 81 82 assertEquals(7, maverage.getItemCount()); 85 double value = maverage.getValue(0).doubleValue(); 86 assertTrue(NumberUtils.equal(value, 14.1)); 87 value = maverage.getValue(1).doubleValue(); 88 assertTrue(NumberUtils.equal(value, 13.4)); 89 value = maverage.getValue(2).doubleValue(); 90 assertTrue(NumberUtils.equal(value, 14.43333333333)); 91 value = maverage.getValue(3).doubleValue(); 92 assertTrue(NumberUtils.equal(value, 14.93333333333)); 93 value = maverage.getValue(4).doubleValue(); 94 assertTrue(NumberUtils.equal(value, 19.8)); 95 value = maverage.getValue(5).doubleValue(); 96 assertTrue(NumberUtils.equal(value, 15.25)); 97 value = maverage.getValue(6).doubleValue(); 98 assertTrue(NumberUtils.equal(value, 12.5)); 99 } 100 101 106 private TimeSeries createDailyTimeSeries1() { 107 108 TimeSeries series = new TimeSeries("Series 1", Day.class); 109 series.add(new Day(11, SerialDate.AUGUST, 2003), 11.2); 110 series.add(new Day(13, SerialDate.AUGUST, 2003), 13.8); 111 series.add(new Day(17, SerialDate.AUGUST, 2003), 14.1); 112 series.add(new Day(18, SerialDate.AUGUST, 2003), 12.7); 113 series.add(new Day(19, SerialDate.AUGUST, 2003), 16.5); 114 series.add(new Day(20, SerialDate.AUGUST, 2003), 15.6); 115 series.add(new Day(25, SerialDate.AUGUST, 2003), 19.8); 116 series.add(new Day(27, SerialDate.AUGUST, 2003), 10.7); 117 series.add(new Day(28, SerialDate.AUGUST, 2003), 14.3); 118 return series; 119 120 } 121 122 } 123 | Popular Tags |