コード例 #1
0
        public void Test_ExchangeAllShareIndex()
        {
            string stock         = "GIN";
            double lastDividend  = 8;
            double fixedDividend = 2;
            double parValue      = 100;
            double stockPrice    = 25;

            GBCE exchange = new GBCE();

            exchange.addPreferredStock(stock, lastDividend, fixedDividend, parValue, stockPrice);

            stock        = "TEA";
            lastDividend = 0;
            stockPrice   = 75;

            exchange.addCommonStock(stock, lastDividend, stockPrice);

            stock        = "POP";
            lastDividend = 4;
            stockPrice   = 50;

            exchange.addCommonStock(stock, lastDividend, stockPrice);

            stock        = "ALE";
            lastDividend = 23;
            stockPrice   = 67;

            exchange.addCommonStock(stock, lastDividend, stockPrice);

            stock        = "JOE";
            lastDividend = 13;
            stockPrice   = 250;

            exchange.addCommonStock(stock, lastDividend, stockPrice);

            double expectedValue = Math.Pow((25 * 75 * 50 * 67 * 250), 1.0 / 5);

            Assert.AreEqual(5, exchange.stocks.Count); //Verify there are five stocks in the exchange

            double allShareIndex = exchange.AllShareIndex();

            Assert.AreEqual(expectedValue, allShareIndex); //Verify it has the correct index value
        }
コード例 #2
0
        public void Test_ExchangeAllShareIndexException()
        {
            string stock         = "GIN";
            double lastDividend  = 8;
            double fixedDividend = 2;
            double parValue      = 100;
            double stockPrice    = 25;

            GBCE exchange = new GBCE();

            exchange.addPreferredStock(stock, lastDividend, fixedDividend, parValue, stockPrice);

            stock        = "TEA";
            lastDividend = 0;
            stockPrice   = 75;

            exchange.addCommonStock(stock, lastDividend, stockPrice);

            stock        = "POP";
            lastDividend = 4;
            stockPrice   = 50;

            exchange.addCommonStock(stock, lastDividend, stockPrice);

            stock        = "ALE";
            lastDividend = 23;
            stockPrice   = -67; //-ve share price will cause exception on all share index

            exchange.addCommonStock(stock, lastDividend, stockPrice);

            stock        = "JOE";
            lastDividend = 13;
            stockPrice   = 250;

            exchange.addCommonStock(stock, lastDividend, stockPrice);

            Assert.AreEqual(5, exchange.stocks.Count); //Verify there are five stocks in the exchange

            double allShareIndex = exchange.AllShareIndex();
        }