|
From: Márcio V. d. S. <mv...@us...> - 2007-08-23 12:51:16
|
Update of /cvsroot/tail/Tail/src/test/net/sf/tail/strategy In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv13475/src/test/net/sf/tail/strategy Modified Files: JustBuyOnceStrategyTest.java IndicatorOverIndicatorStrategyTest.java IndicatorCrossedIndicatorStrategyTest.java FakeStrategy.java MinValueStopperStrategyTest.java MinValueStarterStrategyTest.java DistanceBetweenIndicatorsStrategyTest.java Log Message: Index: FakeStrategy.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/strategy/FakeStrategy.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** FakeStrategy.java 21 Aug 2007 20:58:34 -0000 1.4 --- FakeStrategy.java 23 Aug 2007 12:51:09 -0000 1.5 *************** *** 8,12 **** private Operation[] exit; ! public FakeStrategy(Operation[] enter, Operation[] exit) { this.enter = enter; --- 8,12 ---- private Operation[] exit; ! public FakeStrategy(Operation[] enter, Operation[] exit) { this.enter = enter; *************** *** 14,18 **** } ! public String getName(){ return "Fake Strategy"; } --- 14,18 ---- } ! public String getName() { return "Fake Strategy"; } *************** *** 25,29 **** public boolean shouldExit(int index) { ! if (exit[index] != null) return true; return false; --- 25,29 ---- public boolean shouldExit(int index) { ! if (exit[index] != null) return true; return false; Index: JustBuyOnceStrategyTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/strategy/JustBuyOnceStrategyTest.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** JustBuyOnceStrategyTest.java 21 Aug 2007 20:58:34 -0000 1.7 --- JustBuyOnceStrategyTest.java 23 Aug 2007 12:51:09 -0000 1.8 *************** *** 1,5 **** package net.sf.tail.strategy; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; --- 1,4 ---- *************** *** 16,19 **** --- 15,19 ---- private Strategy strategy; + private Trade trade; *************** *** 24,31 **** } ! @Test public void ! shouldBuyTradeOnce() { ! Operation buy = new Operation(0,OperationType.BUY); ! assertTrue(strategy.shouldOperate(trade, 0)); trade.operate(0); --- 24,31 ---- } ! @Test ! public void shouldBuyTradeOnce() { ! Operation buy = new Operation(0, OperationType.BUY); ! assertTrue(strategy.shouldOperate(trade, 0)); trade.operate(0); *************** *** 33,42 **** assertFalse(strategy.shouldOperate(trade, 1)); assertFalse(strategy.shouldOperate(trade, 6)); ! } ! ! @Test public void ! sameIndexShouldResultSameAnswer() { ! Operation buy = new Operation(0,OperationType.BUY); assertTrue(strategy.shouldOperate(trade, 0)); --- 33,42 ---- assertFalse(strategy.shouldOperate(trade, 1)); assertFalse(strategy.shouldOperate(trade, 6)); ! } ! ! @Test ! public void sameIndexShouldResultSameAnswer() { ! Operation buy = new Operation(0, OperationType.BUY); assertTrue(strategy.shouldOperate(trade, 0)); *************** *** 48,52 **** assertEquals(buy, trade2.getEntry()); } ! ! } --- 48,51 ---- assertEquals(buy, trade2.getEntry()); } ! } Index: MinValueStopperStrategyTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/strategy/MinValueStopperStrategyTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** MinValueStopperStrategyTest.java 21 Aug 2007 20:58:34 -0000 1.5 --- MinValueStopperStrategyTest.java 23 Aug 2007 12:51:09 -0000 1.6 *************** *** 19,34 **** @Before public void setUp() throws Exception { ! indicator = new SampleIndicator(new double[] {100,100,96,95,94}); } @Test public void testStopperShouldSell() { ! Strategy justBuy = new JustBuyOnceStrategy(); ! Strategy stopper = new MinValueStopperStrategy(indicator,justBuy,5); ! ! Operation buy = new Operation(0,OperationType.BUY); ! Operation sell = new Operation(4,OperationType.SELL); ! Trade trade = new Trade(); assertTrue(stopper.shouldOperate(trade, 0)); --- 19,34 ---- @Before public void setUp() throws Exception { ! indicator = new SampleIndicator(new double[] { 100, 100, 96, 95, 94 }); } @Test public void testStopperShouldSell() { ! Strategy justBuy = new JustBuyOnceStrategy(); ! Strategy stopper = new MinValueStopperStrategy(indicator, justBuy, 5); ! ! Operation buy = new Operation(0, OperationType.BUY); ! Operation sell = new Operation(4, OperationType.SELL); ! Trade trade = new Trade(); assertTrue(stopper.shouldOperate(trade, 0)); *************** *** 37,41 **** assertFalse(stopper.shouldOperate(trade, 1)); assertFalse(stopper.shouldOperate(trade, 2)); - assertTrue(stopper.shouldOperate(trade, 4)); --- 37,40 ---- *************** *** 43,73 **** assertEquals(sell, trade.getExit()); } ! @Test public void testStopperShouldSellIfStrategySays() { ! ! Operation[] enter = new Operation[] { new Operation(0, OperationType.BUY), null, null, null, null}; ! Operation[] exit = new Operation[] { null,new Operation(1, OperationType.SELL) , null, null, null }; ! Strategy sell1 = new FakeStrategy(enter, exit); ! ! Strategy stopper = new MinValueStopperStrategy(indicator,sell1,500); ! ! Operation buy = new Operation(0,OperationType.BUY); ! Operation sell = new Operation(1,OperationType.SELL); ! Trade trade = new Trade(); assertTrue(stopper.shouldOperate(trade, 0)); trade.operate(0); ! assertEquals(buy, trade.getEntry()); ! assertTrue(stopper.shouldOperate(trade, 1)); trade.operate(1); ! assertEquals(sell, trade.getExit()); } ! ! ! } --- 42,70 ---- assertEquals(sell, trade.getExit()); } ! @Test public void testStopperShouldSellIfStrategySays() { ! ! Operation[] enter = new Operation[] { new Operation(0, OperationType.BUY), null, null, null, null }; ! Operation[] exit = new Operation[] { null, new Operation(1, OperationType.SELL), null, null, null }; ! Strategy sell1 = new FakeStrategy(enter, exit); ! ! Strategy stopper = new MinValueStopperStrategy(indicator, sell1, 500); ! ! Operation buy = new Operation(0, OperationType.BUY); ! Operation sell = new Operation(1, OperationType.SELL); ! Trade trade = new Trade(); assertTrue(stopper.shouldOperate(trade, 0)); trade.operate(0); ! assertEquals(buy, trade.getEntry()); ! assertTrue(stopper.shouldOperate(trade, 1)); trade.operate(1); ! assertEquals(sell, trade.getExit()); } ! } Index: DistanceBetweenIndicatorsStrategyTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/strategy/DistanceBetweenIndicatorsStrategyTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** DistanceBetweenIndicatorsStrategyTest.java 21 Aug 2007 20:58:34 -0000 1.4 --- DistanceBetweenIndicatorsStrategyTest.java 23 Aug 2007 12:51:09 -0000 1.5 *************** *** 20,24 **** upper = new SampleIndicator(new double[] { 30, 32, 33, 32, 35, 33, 32 }); lower = new SampleIndicator(new double[] { 10, 10, 10, 12, 14, 15, 15 }); ! distanceEnter = new DistanceBetweenIndicatorsStrategy(upper, lower, 20, 0.1); } --- 20,24 ---- upper = new SampleIndicator(new double[] { 30, 32, 33, 32, 35, 33, 32 }); lower = new SampleIndicator(new double[] { 10, 10, 10, 12, 14, 15, 15 }); ! distanceEnter = new DistanceBetweenIndicatorsStrategy(upper, lower, 20, 0.1); } *************** *** 26,30 **** public void testStrategyIsBuyingCorreclty() { Trade trade = new Trade(); ! assertFalse(distanceEnter.shouldOperate(trade, 0)); assertTrue(distanceEnter.shouldOperate(trade, 1)); --- 26,30 ---- public void testStrategyIsBuyingCorreclty() { Trade trade = new Trade(); ! assertFalse(distanceEnter.shouldOperate(trade, 0)); assertTrue(distanceEnter.shouldOperate(trade, 1)); *************** *** 34,53 **** assertFalse(distanceEnter.shouldOperate(trade, 4)); } ! @Test public void testStrategyIsSellingCorrectly() { Trade trade = new Trade(); trade.operate(2); ! assertFalse(distanceEnter.shouldOperate(trade, 0)); assertTrue(distanceEnter.shouldOperate(trade, 5)); ! trade = new Trade(); trade.operate(2); ! assertTrue(distanceEnter.shouldOperate(trade, 6)); assertFalse(distanceEnter.shouldOperate(trade, 3)); assertFalse(distanceEnter.shouldOperate(trade, 4)); ! } } --- 34,53 ---- assertFalse(distanceEnter.shouldOperate(trade, 4)); } ! @Test public void testStrategyIsSellingCorrectly() { Trade trade = new Trade(); trade.operate(2); ! assertFalse(distanceEnter.shouldOperate(trade, 0)); assertTrue(distanceEnter.shouldOperate(trade, 5)); ! trade = new Trade(); trade.operate(2); ! assertTrue(distanceEnter.shouldOperate(trade, 6)); assertFalse(distanceEnter.shouldOperate(trade, 3)); assertFalse(distanceEnter.shouldOperate(trade, 4)); ! } } Index: IndicatorCrossedIndicatorStrategyTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/strategy/IndicatorCrossedIndicatorStrategyTest.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** IndicatorCrossedIndicatorStrategyTest.java 21 Aug 2007 20:58:34 -0000 1.7 --- IndicatorCrossedIndicatorStrategyTest.java 23 Aug 2007 12:51:09 -0000 1.8 *************** *** 20,41 **** Indicator<Double> first = new SampleIndicator(new double[] { 4, 7, 9, 6, 3, 2 }); Indicator<Double> second = new SampleIndicator(new double[] { 3, 6, 10, 8, 2, 1 }); ! Strategy s = new IndicatorCrossedIndicatorStrategy(first, second); Trade trade = new Trade(); assertFalse(s.shouldOperate(trade, 0)); assertFalse(s.shouldOperate(trade, 1)); ! assertTrue(s.shouldOperate(trade, 2)); trade.operate(2); Operation enter = new Operation(2, OperationType.BUY); assertEquals(enter, trade.getEntry()); ! assertFalse(s.shouldOperate(trade, 3)); assertTrue(s.shouldOperate(trade, 4)); trade.operate(4); ! Operation exit = new Operation(4,OperationType.SELL); assertEquals(exit, trade.getExit()); ! assertFalse(s.shouldOperate(trade, 5)); } --- 20,41 ---- Indicator<Double> first = new SampleIndicator(new double[] { 4, 7, 9, 6, 3, 2 }); Indicator<Double> second = new SampleIndicator(new double[] { 3, 6, 10, 8, 2, 1 }); ! Strategy s = new IndicatorCrossedIndicatorStrategy(first, second); Trade trade = new Trade(); assertFalse(s.shouldOperate(trade, 0)); assertFalse(s.shouldOperate(trade, 1)); ! assertTrue(s.shouldOperate(trade, 2)); trade.operate(2); Operation enter = new Operation(2, OperationType.BUY); assertEquals(enter, trade.getEntry()); ! assertFalse(s.shouldOperate(trade, 3)); assertTrue(s.shouldOperate(trade, 4)); trade.operate(4); ! Operation exit = new Operation(4, OperationType.SELL); assertEquals(exit, trade.getExit()); ! assertFalse(s.shouldOperate(trade, 5)); } *************** *** 60,74 **** Strategy s = new IndicatorCrossedIndicatorStrategy(first, second); ! ! Operation enter = new Operation(2,OperationType.BUY); assertTrue(s.shouldOperate(trade, 2)); trade.operate(2); ! assertEquals(enter,trade.getEntry()); for (int i = 3; i < 6; i++) { ! assertFalse(s.shouldOperate(trade,i)); } } ! @Test public void testEqualIndicatorsShouldNotExitWhenIndicatorsBecameEquals() { --- 60,74 ---- Strategy s = new IndicatorCrossedIndicatorStrategy(first, second); ! ! Operation enter = new Operation(2, OperationType.BUY); assertTrue(s.shouldOperate(trade, 2)); trade.operate(2); ! assertEquals(enter, trade.getEntry()); for (int i = 3; i < 6; i++) { ! assertFalse(s.shouldOperate(trade, i)); } } ! @Test public void testEqualIndicatorsShouldNotExitWhenIndicatorsBecameEquals() { *************** *** 78,87 **** Trade trade = new Trade(); ! assertTrue(s.shouldOperate(trade,1)); trade.operate(1); Operation enter = trade.getEntry(); assertNotNull(enter); ! assertEquals(enter.getType(), OperationType.BUY); --- 78,87 ---- Trade trade = new Trade(); ! assertTrue(s.shouldOperate(trade, 1)); trade.operate(1); Operation enter = trade.getEntry(); assertNotNull(enter); ! assertEquals(enter.getType(), OperationType.BUY); *************** *** 98,113 **** Trade trade = new Trade(); ! Operation enter = new Operation(1,OperationType.BUY); ! assertTrue(s.shouldOperate(trade,1)); trade.operate(1); ! assertEquals(enter,trade.getEntry()); for (int i = 2; i < 6; i++) { assertFalse(s.shouldOperate(trade, i)); } ! ! Operation exit = new Operation(6,OperationType.SELL); ! assertTrue(s.shouldOperate(trade,6)); trade.operate(6); assertEquals(exit, trade.getExit()); --- 98,113 ---- Trade trade = new Trade(); ! Operation enter = new Operation(1, OperationType.BUY); ! assertTrue(s.shouldOperate(trade, 1)); trade.operate(1); ! assertEquals(enter, trade.getEntry()); for (int i = 2; i < 6; i++) { assertFalse(s.shouldOperate(trade, i)); } ! ! Operation exit = new Operation(6, OperationType.SELL); ! assertTrue(s.shouldOperate(trade, 6)); trade.operate(6); assertEquals(exit, trade.getExit()); *************** *** 120,126 **** Strategy s = new IndicatorCrossedIndicatorStrategy(firstEqual, secondEqual); Trade trade = new Trade(); ! for (int i = 0; i < 7; i++) { ! assertFalse(s.shouldOperate(trade,i)); } } --- 120,126 ---- Strategy s = new IndicatorCrossedIndicatorStrategy(firstEqual, secondEqual); Trade trade = new Trade(); ! for (int i = 0; i < 7; i++) { ! assertFalse(s.shouldOperate(trade, i)); } } Index: IndicatorOverIndicatorStrategyTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/strategy/IndicatorOverIndicatorStrategyTest.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** IndicatorOverIndicatorStrategyTest.java 21 Aug 2007 20:58:34 -0000 1.9 --- IndicatorOverIndicatorStrategyTest.java 23 Aug 2007 12:51:09 -0000 1.10 *************** *** 23,29 **** 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}); ! } --- 23,29 ---- 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 }); ! } *************** *** 31,56 **** public void testOverIndicators() { Trade trade = new Trade(); ! Strategy s = new IndicatorOverIndicatorStrategy(first, second); assertFalse(s.shouldOperate(trade, 0)); assertFalse(s.shouldOperate(trade, 1)); assertEquals(null, trade.getEntry()); ! Operation buy = new Operation(2,OperationType.BUY); assertTrue(s.shouldOperate(trade, 2)); trade.operate(2); assertEquals(buy, trade.getEntry()); trade = new Trade(); ! buy = new Operation(3,OperationType.BUY); assertTrue(s.shouldOperate(trade, 3)); trade.operate(3); assertEquals(buy, trade.getEntry()); ! assertFalse(s.shouldOperate(trade, 3)); ! ! Operation sell = new Operation(4,OperationType.SELL); assertTrue(s.shouldOperate(trade, 4)); trade.operate(4); assertEquals(sell, trade.getExit()); ! } } --- 31,56 ---- public void testOverIndicators() { Trade trade = new Trade(); ! Strategy s = new IndicatorOverIndicatorStrategy(first, second); assertFalse(s.shouldOperate(trade, 0)); assertFalse(s.shouldOperate(trade, 1)); assertEquals(null, trade.getEntry()); ! Operation buy = new Operation(2, OperationType.BUY); assertTrue(s.shouldOperate(trade, 2)); trade.operate(2); assertEquals(buy, trade.getEntry()); trade = new Trade(); ! buy = new Operation(3, OperationType.BUY); assertTrue(s.shouldOperate(trade, 3)); trade.operate(3); assertEquals(buy, trade.getEntry()); ! assertFalse(s.shouldOperate(trade, 3)); ! ! Operation sell = new Operation(4, OperationType.SELL); assertTrue(s.shouldOperate(trade, 4)); trade.operate(4); assertEquals(sell, trade.getExit()); ! } } Index: MinValueStarterStrategyTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/strategy/MinValueStarterStrategyTest.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** MinValueStarterStrategyTest.java 21 Aug 2007 20:58:34 -0000 1.6 --- MinValueStarterStrategyTest.java 23 Aug 2007 12:51:09 -0000 1.7 *************** *** 53,57 **** assertTrue(starter.shouldOperate(trade, 3)); trade.operate(3); ! assertFalse(starter.shouldOperate(trade, 3)); assertEquals(buy, trade.getEntry()); --- 53,57 ---- assertTrue(starter.shouldOperate(trade, 3)); trade.operate(3); ! assertFalse(starter.shouldOperate(trade, 3)); assertEquals(buy, trade.getEntry()); |