|
From: Márcio V. d. S. <mv...@us...> - 2007-05-31 16:45:40
|
Update of /cvsroot/tail/Tail/src/test/net/sf/tail/indicator/helper In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv2946/src/test/net/sf/tail/indicator/helper Added Files: StandardDeviationIndicatorTest.java AverageLossIndicatorTest.java AverageGainIndicatorTest.java HighestValueIndicatorTest.java LowestValueIndicatorTest.java Log Message: Refatoração de testes --- NEW FILE: StandardDeviationIndicatorTest.java --- package net.sf.tail.indicator.helper; import static org.junit.Assert.assertEquals; import junit.framework.JUnit4TestAdapter; import net.sf.tail.TimeSeries; import net.sf.tail.indicator.helper.StandardDeviationIndicator; import net.sf.tail.indicator.simple.ClosePriceIndicator; import net.sf.tail.sample.SampleTimeSeries; import org.junit.Before; import org.junit.Test; public class StandardDeviationIndicatorTest { private TimeSeries data; @Before public void setUp() throws Exception { data = new SampleTimeSeries(new double[] { 1, 2, 3, 4, 3, 4, 5, 4, 3, 0, 9 }); } @Test public void testStandardDeviationUsingTimeFrame4UsingClosePrice() throws Exception { StandardDeviationIndicator sdv = new StandardDeviationIndicator(new ClosePriceIndicator(data), 4); assertEquals(0d, sdv.getValue(0), 0.1); assertEquals(Math.sqrt(0.5), sdv.getValue(1), 0.1); assertEquals(Math.sqrt(2.0), sdv.getValue(2), 0.1); assertEquals(Math.sqrt(5.0), sdv.getValue(3), 0.1); assertEquals(Math.sqrt(2.0), sdv.getValue(4), 0.1); assertEquals(1, sdv.getValue(5), 0.1); assertEquals(Math.sqrt(2.0), sdv.getValue(6), 0.1); assertEquals(Math.sqrt(2.0), sdv.getValue(7), 0.1); assertEquals(Math.sqrt(2.0), sdv.getValue(8), 0.1); assertEquals(Math.sqrt(14.0), sdv.getValue(9), 0.1); assertEquals(Math.sqrt(42.0), sdv.getValue(10), 0.1); } @Test public void testFirstValueShouldBeZero() throws Exception { StandardDeviationIndicator sdv = new StandardDeviationIndicator(new ClosePriceIndicator(data), 4); assertEquals(0, sdv.getValue(0), 0.1); } @Test public void testStandardDeviationValueIndicatorValueWhenTimeFraseIs1ShouldBeZero() { StandardDeviationIndicator sdv = new StandardDeviationIndicator(new ClosePriceIndicator(data), 1); assertEquals(0d, sdv.getValue(3), 0.1); assertEquals(0d, sdv.getValue(8), 0.1); } @Test public void testStandardDeviationUsingTimeFrame2UsingClosePrice() throws Exception { StandardDeviationIndicator sdv = new StandardDeviationIndicator(new ClosePriceIndicator(data), 2); assertEquals(0d, sdv.getValue(0), 0.1); assertEquals(Math.sqrt(0.5), sdv.getValue(1), 0.1); assertEquals(Math.sqrt(0.5), sdv.getValue(2), 0.1); assertEquals(Math.sqrt(0.5), sdv.getValue(3), 0.1); assertEquals(Math.sqrt(4.5), sdv.getValue(9), 0.1); assertEquals(Math.sqrt(40.5), sdv.getValue(10), 0.1); } @Test(expected = IndexOutOfBoundsException.class) public void testIndexGreatterThanTheIndicatorLenghtShouldThrowException() { StandardDeviationIndicator quoteSDV = new StandardDeviationIndicator(new ClosePriceIndicator(data), 3); quoteSDV.getValue(13); } public static junit.framework.Test suite() { return new JUnit4TestAdapter(StandardDeviationIndicatorTest.class); } } --- NEW FILE: AverageLossIndicatorTest.java --- package net.sf.tail.indicator.helper; import static org.junit.Assert.assertEquals; import junit.framework.JUnit4TestAdapter; import net.sf.tail.TimeSeries; import net.sf.tail.indicator.RSIIndicatorTest; import net.sf.tail.indicator.helper.AverageLossIndicator; import net.sf.tail.indicator.simple.ClosePriceIndicator; import net.sf.tail.sample.SampleTimeSeries; import org.junit.Before; import org.junit.Test; public class AverageLossIndicatorTest { private TimeSeries data; @Before public void setUp() throws Exception { data = new SampleTimeSeries(new double[] { 1, 2, 3, 4, 3, 4, 5, 4, 3, 3, 4, 3, 2 }); } @Test public void testAverageLossUsingTimeFrame5UsingClosePrice() throws Exception { AverageLossIndicator averageLoss = new AverageLossIndicator(new ClosePriceIndicator(data), 5); assertEquals(1d / 5d, averageLoss.getValue(5), 0.01); assertEquals(1d / 5d, averageLoss.getValue(6), 0.01); assertEquals(2d / 5d, averageLoss.getValue(7), 0.01); assertEquals(3d / 5d, averageLoss.getValue(8), 0.01); assertEquals(2d / 5d, averageLoss.getValue(9), 0.01); assertEquals(2d / 5d, averageLoss.getValue(10), 0.01); assertEquals(3d / 5d, averageLoss.getValue(11), 0.01); assertEquals(3d / 5d, averageLoss.getValue(12), 0.01); } @Test public void testAverageLossShouldWorkJumpingIndexes() { AverageLossIndicator averageLoss = new AverageLossIndicator(new ClosePriceIndicator(data), 5); assertEquals(2d / 5d, averageLoss.getValue(10), 0.01); assertEquals(3d / 5d, averageLoss.getValue(12), 0.01); } @Test public void testAverageLossMustReturnZeroWhenTheDataDoesntGain() { AverageLossIndicator averageLoss = new AverageLossIndicator(new ClosePriceIndicator(data), 4); assertEquals(0, averageLoss.getValue(3), 0.01); } @Test public void testAverageLossWhenTimeFrameIsGreaterThanIndex() { AverageLossIndicator averageLoss = new AverageLossIndicator(new ClosePriceIndicator(data), 1000); assertEquals(5d/data.getSize(), averageLoss.getValue(12), 0.01); } @Test public void testAverageGainWhenIndexIsZeroMustBeZero() { AverageLossIndicator averageLoss = new AverageLossIndicator(new ClosePriceIndicator(data), 10); assertEquals(0, averageLoss.getValue(0), 0.01); } @Test(expected = IndexOutOfBoundsException.class) public void testIndexGreatterThanTheIndicatorLenghtShouldThrowException() { AverageLossIndicator averageLoss = new AverageLossIndicator(new ClosePriceIndicator(data), 5); assertEquals(3d, averageLoss.getValue(300)); } public static junit.framework.Test suite() { return new JUnit4TestAdapter(RSIIndicatorTest.class); } } --- NEW FILE: AverageGainIndicatorTest.java --- package net.sf.tail.indicator.helper; import net.sf.tail.TimeSeries; import net.sf.tail.indicator.RSIIndicatorTest; import net.sf.tail.indicator.helper.AverageGainIndicator; import net.sf.tail.indicator.simple.ClosePriceIndicator; import net.sf.tail.sample.SampleTimeSeries; import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; import junit.framework.JUnit4TestAdapter; public class AverageGainIndicatorTest { private TimeSeries data; @Before public void prepare() throws Exception { data = new SampleTimeSeries(new double[] { 1, 2, 3, 4, 3, 4, 5, 4, 3, 3, 4, 3, 2 }); } @Test public void testAverageGainUsingTimeFrame5UsingClosePrice() throws Exception { AverageGainIndicator averageGain = new AverageGainIndicator(new ClosePriceIndicator(data), 5); assertEquals(4d / 5d, averageGain.getValue(5), 0.01); assertEquals(4d / 5d, averageGain.getValue(6), 0.01); assertEquals(3d / 5d, averageGain.getValue(7), 0.01); assertEquals(2d / 5d, averageGain.getValue(8), 0.01); assertEquals(2d / 5d, averageGain.getValue(9), 0.01); assertEquals(2d / 5d, averageGain.getValue(10), 0.01); assertEquals(1d / 5d, averageGain.getValue(11), 0.01); assertEquals(1d / 5d, averageGain.getValue(12), 0.01); } @Test public void testAverageGainShouldWorkJumpingIndexes() { AverageGainIndicator averageGain = new AverageGainIndicator(new ClosePriceIndicator(data), 5); assertEquals(2d / 5d, averageGain.getValue(10), 0.01); assertEquals(1d / 5d, averageGain.getValue(12), 0.01); } @Test public void testAverageGainMustReturnZeroWhenTheDataDoesntGain() { AverageGainIndicator averageGain = new AverageGainIndicator(new ClosePriceIndicator(data), 3); assertEquals(0, averageGain.getValue(9), 0.01); } @Test public void testAverageGainWhenTimeFrameIsGreaterThanIndicatorDataShouldBeCalculatedWithDataSize() { AverageGainIndicator averageGain = new AverageGainIndicator(new ClosePriceIndicator(data), 1000); assertEquals(6d/data.getSize(), averageGain.getValue(12), 0.01); } @Test public void testAverageGainWhenIndexIsZeroMustBeZero() { AverageGainIndicator averageGain = new AverageGainIndicator(new ClosePriceIndicator(data), 10); assertEquals(0, averageGain.getValue(0), 0.01); } @Test(expected = IndexOutOfBoundsException.class) public void testIndexGreatterThanTheIndicatorLenghtShouldThrowException() { AverageGainIndicator averageGain = new AverageGainIndicator(new ClosePriceIndicator(data), 5); assertEquals(3d, averageGain.getValue(300)); } public static junit.framework.Test suite() { return new JUnit4TestAdapter(RSIIndicatorTest.class); } } --- NEW FILE: HighestValueIndicatorTest.java --- package net.sf.tail.indicator.helper; import static org.junit.Assert.assertEquals; import junit.framework.JUnit4TestAdapter; import net.sf.tail.TimeSeries; import net.sf.tail.indicator.RSIIndicatorTest; import net.sf.tail.indicator.helper.HighestValueIndicator; import net.sf.tail.indicator.simple.ClosePriceIndicator; import net.sf.tail.sample.SampleTimeSeries; import org.junit.Before; import org.junit.Test; public class HighestValueIndicatorTest { private TimeSeries data; @Before public void setUp() throws Exception { data = new SampleTimeSeries(new double[] { 1, 2, 3, 4, 3, 4, 5, 6, 4, 3, 3, 4, 3, 2 }); } @Test public void testHighestValueUsingTimeFrame5UsingClosePrice() throws Exception { HighestValueIndicator highestValue = new HighestValueIndicator(new ClosePriceIndicator(data), 5); assertEquals(4d, highestValue.getValue(4), 0.01); assertEquals(4d, highestValue.getValue(5), 0.01); assertEquals(5d, highestValue.getValue(6), 0.01); assertEquals(6d, highestValue.getValue(7), 0.01); assertEquals(6d, highestValue.getValue(8), 0.01); assertEquals(6d, highestValue.getValue(9), 0.01); assertEquals(6d, highestValue.getValue(10), 0.01); assertEquals(6d, highestValue.getValue(11), 0.01); assertEquals(4d, highestValue.getValue(12), 0.01); } @Test public void testFirstHighestValueIndicatorValueShouldBeEqualsToFirstDataValue() { HighestValueIndicator highestValue = new HighestValueIndicator(new ClosePriceIndicator(data), 5); assertEquals(1d, highestValue.getValue(0), 0.01); } @Test public void testHighestValueIndicatorWhenTimeFrameIsGreaterThanIndex() { HighestValueIndicator highestValue = new HighestValueIndicator(new ClosePriceIndicator(data), 500); assertEquals(6d, highestValue.getValue(12), 0.01); } @Test public void testHighestValueShouldWorkJumpingIndexes() { HighestValueIndicator highestValue = new HighestValueIndicator(new ClosePriceIndicator(data), 5); assertEquals(5d, highestValue.getValue(6), 0.01); assertEquals(4, highestValue.getValue(12), 0.01); } @Test(expected = IndexOutOfBoundsException.class) public void testIndexGreatterThanTheIndicatorLenghtShouldThrowException() { HighestValueIndicator highestValue = new HighestValueIndicator(new ClosePriceIndicator(data), 5); assertEquals(3d, highestValue.getValue(300)); } public static junit.framework.Test suite() { return new JUnit4TestAdapter(RSIIndicatorTest.class); } } --- NEW FILE: LowestValueIndicatorTest.java --- package net.sf.tail.indicator.helper; import static org.junit.Assert.assertEquals; import junit.framework.JUnit4TestAdapter; import net.sf.tail.TimeSeries; import net.sf.tail.indicator.RSIIndicatorTest; import net.sf.tail.indicator.helper.LowestValueIndicator; import net.sf.tail.indicator.simple.ClosePriceIndicator; import net.sf.tail.sample.SampleTimeSeries; import org.junit.Before; import org.junit.Test; public class LowestValueIndicatorTest { private TimeSeries data; @Before public void setUp() throws Exception { data = new SampleTimeSeries(new double[] { 1, 2, 3, 4, 3, 4, 5, 6, 4, 3, 2, 4, 3, 1 }); } @Test public void testLowestValueIndicatorUsingTimeFrame5UsingClosePrice() throws Exception { LowestValueIndicator lowestValue = new LowestValueIndicator(new ClosePriceIndicator(data), 5); assertEquals(1d, lowestValue.getValue(4), 0.01); assertEquals(2d, lowestValue.getValue(5), 0.01); assertEquals(3d, lowestValue.getValue(6), 0.01); assertEquals(3d, lowestValue.getValue(7), 0.01); assertEquals(3d, lowestValue.getValue(8), 0.01); assertEquals(3d, lowestValue.getValue(9), 0.01); assertEquals(2d, lowestValue.getValue(10), 0.01); assertEquals(2d, lowestValue.getValue(11), 0.01); assertEquals(2d, lowestValue.getValue(12), 0.01); } @Test public void testLowestValueShouldWorkJumpingIndexes() { LowestValueIndicator lowestValue = new LowestValueIndicator(new ClosePriceIndicator(data), 5); assertEquals(2d, lowestValue.getValue(10), 0.01); assertEquals(3d, lowestValue.getValue(6), 0.01); } @Test public void testLowestValueIndicatorValueShouldBeEqualsToFirstDataValue() { LowestValueIndicator lowestValue = new LowestValueIndicator(new ClosePriceIndicator(data), 5); assertEquals(1d, lowestValue.getValue(0), 0.01); } @Test public void testLowestValueIndicatorWhenTimeFrameIsGreaterThanIndex() { LowestValueIndicator lowestValue = new LowestValueIndicator(new ClosePriceIndicator(data), 500); assertEquals(1d, lowestValue.getValue(12), 0.01); } @Test(expected = IndexOutOfBoundsException.class) public void testIndexGreatterThanTheIndicatorLenghtShouldThrowException() { LowestValueIndicator lowestValue = new LowestValueIndicator(new ClosePriceIndicator(data), 5); assertEquals(3d, lowestValue.getValue(300)); } public static junit.framework.Test suite() { return new JUnit4TestAdapter(RSIIndicatorTest.class); } } |