Ejemplo n.º 1
0
        public void CalculateAllShareIndexTest()
        {
            exchangeStock.AddStock(new CommonStock {
                symbol = "TEA", lastDividend = 10, parValue = 100
            });
            exchangeStock.RecordTrade(new Trade {
                stockSymbol = "TEA", direction = TradeDirection.BUY, price = 100, quantity = 50, timestamp = DateTime.Now.AddMinutes(-5)
            });
            exchangeStock.RecordTrade(new Trade {
                stockSymbol = "TEA", direction = TradeDirection.BUY, price = 200, quantity = 50, timestamp = DateTime.Now
            });

            exchangeStock.AddStock(new CommonStock {
                symbol = "POP", lastDividend = 10, parValue = 100
            });
            exchangeStock.RecordTrade(new Trade {
                stockSymbol = "POP", direction = TradeDirection.BUY, price = 450, quantity = 50, timestamp = DateTime.Now.AddMinutes(-5)
            });
            exchangeStock.RecordTrade(new Trade {
                stockSymbol = "POP", direction = TradeDirection.BUY, price = 180, quantity = 50, timestamp = DateTime.Now
            });

            exchangeStock.AddStock(new CommonStock {
                symbol = "ALE", lastDividend = 10, parValue = 100
            });
            exchangeStock.RecordTrade(new Trade {
                stockSymbol = "ALE", direction = TradeDirection.BUY, price = 130, quantity = 50, timestamp = DateTime.Now.AddMinutes(-5)
            });
            exchangeStock.RecordTrade(new Trade {
                stockSymbol = "ALE", direction = TradeDirection.BUY, price = 120, quantity = 50, timestamp = DateTime.Now
            });

            double currentResult  = exchangeStock.CalculateAllShareIndex();
            double expectedResult = Math.Pow(200 * 180 * 120, 1.0d / 3);

            Assert.AreEqual(currentResult, expectedResult);
        }