|
From: Márcio V. d. S. <mv...@us...> - 2007-05-24 21:11:12
|
Update of /cvsroot/tail/Tail/src/test/net/sf/tail/strategy In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv32499/src/test/net/sf/tail/strategy Modified Files: IndicatorCrossedIndicatorStrategyTest.java Added Files: PipeEnterStrategyTest.java Log Message: Refatoração de código e Criação da nova estratégia PipeEnterStrategy Index: IndicatorCrossedIndicatorStrategyTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/strategy/IndicatorCrossedIndicatorStrategyTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** IndicatorCrossedIndicatorStrategyTest.java 19 May 2007 15:59:51 -0000 1.1 --- IndicatorCrossedIndicatorStrategyTest.java 24 May 2007 21:11:11 -0000 1.2 *************** *** 16,32 **** public class IndicatorCrossedIndicatorStrategyTest { private Indicator<Double> first; private Indicator<Double> second; ! @Before public void setUp() throws Exception { ! ! first = new SampleIndicator(new double[] {4,7,9,6,3,2}); ! second = new SampleIndicator(new double[] {3,6,10,8,2,1}); ! ! } @Test ! public void testCrossedIndicator() ! { Strategy s = new IndicatorCrossedIndicatorStrategy(first, second); assertNull(s.shouldEnter(0)); --- 16,32 ---- public class IndicatorCrossedIndicatorStrategyTest { private Indicator<Double> first; + private Indicator<Double> second; ! @Before public void setUp() throws Exception { ! ! first = new SampleIndicator(new double[] { 4, 7, 9, 6, 3, 2 }); ! second = new SampleIndicator(new double[] { 3, 6, 10, 8, 2, 1 }); ! } + @Test ! public void testCrossedIndicator() { Strategy s = new IndicatorCrossedIndicatorStrategy(first, second); assertNull(s.shouldEnter(0)); *************** *** 42,94 **** assertEquals(exit.getType(), OperationType.SELL); assertNull(s.shouldEnter(5)); ! ! } @Test ! public void testEqualIndicatorsShouldEnter() ! { ! Indicator<Double> firstEqual = new SampleIndicator(new double[] {2,3,4,5,6,7}); ! Indicator<Double> secondEqual = new SampleIndicator(new double[] {2,3,4,5,6,7}); ! Strategy s = new IndicatorCrossedIndicatorStrategy(firstEqual, secondEqual); ! ! for(int i = 0; i < 6; i++) ! { assertNull(s.shouldEnter(i)); } } ! @Test ! public void testEqualIndicatorsShouldExit() ! { ! Indicator<Double> firstEqual = new SampleIndicator(new double[] {2,1,4,5,6,7}); ! Indicator<Double> secondEqual = new SampleIndicator(new double[] {1,3,4,5,6,7}); Strategy s = new IndicatorCrossedIndicatorStrategy(firstEqual, secondEqual); ! Operation enter = s.shouldEnter(1); ! assertNotNull(enter); assertEquals(enter.getType(), OperationType.BUY); ! ! for(int i = 2; i < 6; i++) ! { assertNull(s.shouldExit(enter, i)); } } ! @Test ! public void testEqualIndicatorsShouldEnterEqualsShouldExit() ! { ! Indicator<Double> firstEqual = new SampleIndicator(new double[] {2,1,4,5,6,7,10}); ! Indicator<Double> secondEqual = new SampleIndicator(new double[] {1,3,4,5,6,7,9}); Strategy s = new IndicatorCrossedIndicatorStrategy(firstEqual, secondEqual); ! Operation enter = s.shouldEnter(1); ! assertNotNull(enter); assertEquals(enter.getType(), OperationType.BUY); ! ! for(int i = 2; i < 6; i++) ! { assertNull(s.shouldExit(enter, i)); } --- 42,88 ---- assertEquals(exit.getType(), OperationType.SELL); assertNull(s.shouldEnter(5)); ! } + @Test ! public void testEqualIndicatorsShouldEnter() { ! Indicator<Double> firstEqual = new SampleIndicator(new double[] { 2, 3, 4, 5, 6, 7 }); ! Indicator<Double> secondEqual = new SampleIndicator(new double[] { 2, 3, 4, 5, 6, 7 }); ! Strategy s = new IndicatorCrossedIndicatorStrategy(firstEqual, secondEqual); ! ! for (int i = 0; i < 6; i++) { assertNull(s.shouldEnter(i)); } } ! @Test ! public void testEqualIndicatorsShouldExit() { ! Indicator<Double> firstEqual = new SampleIndicator(new double[] { 2, 1, 4, 5, 6, 7 }); ! Indicator<Double> secondEqual = new SampleIndicator(new double[] { 1, 3, 4, 5, 6, 7 }); Strategy s = new IndicatorCrossedIndicatorStrategy(firstEqual, secondEqual); ! Operation enter = s.shouldEnter(1); ! assertNotNull(enter); assertEquals(enter.getType(), OperationType.BUY); ! ! for (int i = 2; i < 6; i++) { assertNull(s.shouldExit(enter, i)); } } ! @Test ! public void testEqualIndicatorsShouldEnterEqualsShouldExit() { ! Indicator<Double> firstEqual = new SampleIndicator(new double[] { 2, 1, 4, 5, 6, 7, 10 }); ! Indicator<Double> secondEqual = new SampleIndicator(new double[] { 1, 3, 4, 5, 6, 7, 9 }); Strategy s = new IndicatorCrossedIndicatorStrategy(firstEqual, secondEqual); ! Operation enter = s.shouldEnter(1); ! assertNotNull(enter); assertEquals(enter.getType(), OperationType.BUY); ! ! for (int i = 2; i < 6; i++) { assertNull(s.shouldExit(enter, i)); } *************** *** 97,126 **** assertEquals(exit.getType(), OperationType.SELL); } ! @Test ! public void testEqualIndicatorsShouldNotBuy() ! { ! Indicator<Double> firstEqual = new SampleIndicator(new double[] {2,3,4,5,6,7,10}); ! Indicator<Double> secondEqual = new SampleIndicator(new double[] {1,3,4,5,6,7,9}); Strategy s = new IndicatorCrossedIndicatorStrategy(firstEqual, secondEqual); ! ! for(int i = 0; i < 7; i++) ! { assertNull(s.shouldEnter(i)); } ! ! firstEqual = new SampleIndicator(new double[] {2, 3, 4, 5, 6, 8}); ! secondEqual = new SampleIndicator(new double[] {2, 3, 4, 5, 6, 7}); ! ! for(int i = 0; i < 6; i++) ! { assertNull(s.shouldEnter(i)); } } ! public static junit.framework.Test suite() { return new JUnit4TestAdapter(IndicatorCrossedIndicatorStrategyTest.class); } ! ! } --- 91,116 ---- assertEquals(exit.getType(), OperationType.SELL); } ! @Test ! public void testEqualIndicatorsShouldNotBuy() { ! Indicator<Double> firstEqual = new SampleIndicator(new double[] { 2, 3, 4, 5, 6, 7, 10 }); ! Indicator<Double> secondEqual = new SampleIndicator(new double[] { 1, 3, 4, 5, 6, 7, 9 }); Strategy s = new IndicatorCrossedIndicatorStrategy(firstEqual, secondEqual); ! ! for (int i = 0; i < 7; i++) { assertNull(s.shouldEnter(i)); } ! ! firstEqual = new SampleIndicator(new double[] { 2, 3, 4, 5, 6, 8 }); ! secondEqual = new SampleIndicator(new double[] { 2, 3, 4, 5, 6, 7 }); ! ! for (int i = 0; i < 6; i++) { assertNull(s.shouldEnter(i)); } } ! public static junit.framework.Test suite() { return new JUnit4TestAdapter(IndicatorCrossedIndicatorStrategyTest.class); } ! } --- NEW FILE: PipeEnterStrategyTest.java --- package net.sf.tail.strategy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import net.sf.tail.Operation; import net.sf.tail.OperationType; import net.sf.tail.sample.SampleIndicator; import org.junit.Before; import org.junit.Test; public class PipeEnterStrategyTest { private SampleIndicator upper; private SampleIndicator lower; @Before public void setUp() { upper = new SampleIndicator(new double[] { 30, 32, 33, 32, 35, 33, 32, 33, 31, 30, 31, 32, 32, 34, 35 }); lower = new SampleIndicator(new double[] { 10, 12, 13, 12, 15, 13, 12, 13, 11, 10, 11, 12, 12, 14, 15 }); } @Test public void testFirstSellLastBuy() { SampleIndicator value = new SampleIndicator(new double[] { 25, 27, 28, 27, 30, 33, 35, 37, 35, 29, 11, 10, 15, 30, 31 }); PipeEnterStrategy pipeEnter = new PipeEnterStrategy(upper, lower, value); assertNull(pipeEnter.shouldEnter(1)); assertNull(pipeEnter.shouldEnter(8)); assertNull(pipeEnter.shouldEnter(10)); Operation entry = new Operation(9, OperationType.SELL); assertEquals(entry, pipeEnter.shouldEnter(9)); assertNull(pipeEnter.shouldExit(entry, 11)); assertEquals(new Operation(12, OperationType.BUY), pipeEnter.shouldExit(entry, 12)); } @Test public void testFirstBuyLastSell() { SampleIndicator value = new SampleIndicator(new double[] { 8, 15, 16, 33, 40, 45, 47, 40, 32, 25, 15, 16, 11, 10, 12 }); PipeEnterStrategy pipeEnter = new PipeEnterStrategy(upper, lower, value); assertNull(pipeEnter.shouldEnter(0)); Operation entry = new Operation(1, OperationType.BUY); assertEquals(entry, pipeEnter.shouldEnter(1)); assertNull(pipeEnter.shouldEnter(8)); assertNull(pipeEnter.shouldEnter(10)); assertNull(pipeEnter.shouldExit(entry, 8)); assertEquals(new Operation(9, OperationType.SELL), pipeEnter.shouldExit(entry, 9)); } } |