Update of /cvsroot/tail/Tail/src/test/net/sf/tail/indicator
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv27559/src/test/net/sf/tail/indicator
Added Files:
CachedIndicatorTest.java
Log Message:
transformando template method em decorator (caso CachedIndicator)
--- NEW FILE: CachedIndicatorTest.java ---
package net.sf.tail.indicator;
import java.util.Arrays;
import net.sf.tail.SampleTimeSeries;
import net.sf.tail.TimeSeries;
import net.sf.tail.indicator.simple.ClosePriceIndicator;
import net.sf.tail.indicator.tracker.CachedIndicator;
import net.sf.tail.indicator.tracker.SMAIndicator;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import junit.framework.JUnit4TestAdapter;
public class CachedIndicatorTest {
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 testCachedIndicatorShouldBeEqualsSMAIndicator() throws Exception {
SMAIndicator sma = new SMAIndicator(new ClosePriceIndicator(data), 3);
CachedIndicator cache = new CachedIndicator(sma);
for (int i = 0; i < 10; i++) {
assertEquals(sma.getValue(i) , cache.getValue(i));
}
}
@Test
public void testIfCacheWorks() {
SMAIndicator sma = new SMAIndicator(new ClosePriceIndicator(data), 3);
CachedIndicator cache = new CachedIndicator(sma);
cache.getValue(4);
assertEquals(sma.getValue(4) , cache.getValue(4));
}
@Test
public void testIncreaseArrayMethod() {
double[] d = new double[200];
Arrays.fill(d, 10);
TimeSeries dataMax = new SampleTimeSeries(d );
SMAIndicator quoteSMA = new SMAIndicator(new ClosePriceIndicator(dataMax), 100);
CachedIndicator cache = new CachedIndicator(quoteSMA);
assertEquals(10d, cache.getValue(105));
}
@Test(expected = IndexOutOfBoundsException.class)
public void testWrongIndex() {
SMAIndicator quoteSMA = new SMAIndicator(new ClosePriceIndicator(data), 3);
CachedIndicator cache = new CachedIndicator(quoteSMA);
cache.getValue(13);
}
//Método adicionado por causa da compatibilidade do Eclipse 3.1.2(Rede Linux)
//e o JUnit4
public static junit.framework.Test suite() {
return new JUnit4TestAdapter(CachedIndicatorTest.class);
}
}
|