public void TestPreferredShareDividendYieldCalculation(double fixedDividend, int parValue, double price,
                                                               double expectedValue)
        {
            PreferredStock preferredStock = new PreferredStock("Test", 10, parValue, fixedDividend);

            Assert.AreEqual(preferredStock.CalculateDividendYield(price), expectedValue);
        }
        public void TestInvalidPriceInYieldCalcThrowsException(double price)
        {
            CommonStock commonStock   = new CommonStock("Test", 8, 100);
            CommonStock preferedStock = new PreferredStock("Test", 8, 100, 0.02);

            Assert.Throws <ArgumentOutOfRangeException>(() => commonStock.CalculateDividendYield(price));
            Assert.Throws <ArgumentOutOfRangeException>(() => preferedStock.CalculateDividendYield(price));
        }
Ejemplo n.º 3
0
        public void AddPreferredStockTest()
        {
            var stockPreferred = new PreferredStock {
                symbol = "GIN", lastDividend = 8, fixedDividend = 0.02, parValue = 100
            };

            exchangeStock.AddStock(stockPreferred);
            Assert.AreEqual(stockPreferred, exchangeStock.GetStockBySymbol("GIN"));
        }
Ejemplo n.º 4
0
        public void CalculateDividendYieldForPreferredStockTest()
        {
            var stockPreferred = new PreferredStock {
                symbol = "GIN", lastDividend = 8, fixedDividend = 0.02, parValue = 100
            };
            var currentDividendPreffered = exchangeStock.CalculateDividendYield(stockPreferred, 100);
            var expectedDividendYield    = 0.02;

            Assert.AreEqual(expectedDividendYield, currentDividendPreffered);
        }
Ejemplo n.º 5
0
        public void CalculatPriceEarningsRatioForPreferredStockTest()
        {
            var stockPreferred = new PreferredStock {
                symbol = "GIN", lastDividend = 8, fixedDividend = 0.02, parValue = 100
            };
            var currentPeRatio  = exchangeStock.CalculatePriceEarningsRatio(stockPreferred, 100);
            var expectedPeRatio = 5000;

            Assert.AreEqual(expectedPeRatio, currentPeRatio);
        }
Ejemplo n.º 6
0
        public void Equals_IfStockSymbolIsNull_ReturnsFalse()
        {
            // Arrange
            var stock1 = new CommonStock();
            var stock2 = new PreferredStock();

            // Act
            var areEquals = stock1.Equals(stock2);

            // Assert
            Assert.False(areEquals);
        }
Ejemplo n.º 7
0
        public void Test_StocksPERatioException()
        {
            string stock         = "GIN";
            double lastDividend  = 0;
            double fixedDividend = 2;
            double parValue      = 100;
            double stockPrice    = 25;
            double price         = 200;


            PreferredStock testStock = new PreferredStock(stock, lastDividend, fixedDividend, parValue, stockPrice);


            double PEratio = testStock.PERatio(price);
        }
Ejemplo n.º 8
0
        public void Test_StocksPreferredYieldException()
        {
            string stock         = "GIN";
            double lastDividend  = 8;
            double fixedDividend = 2;
            double parValue      = 100;
            double stockPrice    = 25;
            double price         = 0;


            PreferredStock testStock = new PreferredStock(stock, lastDividend, fixedDividend, parValue, stockPrice);


            double dividendYield = testStock.DividendYield(price);
        }
        public void CalculateDividendYield_WithZeroPrice_ThrowsArgumentException()
        {
            // Arrange
            var stock = new PreferredStock
            {
                FixedDividend = 0.5M,
                ParValue      = 100
            };

            // Act
            var testDelegate = new TestDelegate(() => stock.CalculateDividendYield(0));

            // Assert
            Assert.That(testDelegate, Throws.ArgumentException);
        }
        public decimal CalculateDividendYield_WithNonZeroPriceAndPositiveDividend_CorrectlyCalculates(decimal price, decimal parValue)
        {
            // Arrange
            var stock = new PreferredStock
            {
                FixedDividend = 0.5M,
                ParValue      = parValue
            };

            // Act
            var result = stock.CalculateDividendYield(price);

            // Assert
            return(result);
        }
Ejemplo n.º 11
0
        public void Equals_WithTwoStocksWithSameSymbolOfDifferentSubtypes_ReturnsTrue()
        {
            // Arrange
            var stock1 = new CommonStock {
                StockSymbol = "TEA"
            };
            var stock2 = new PreferredStock {
                StockSymbol = "TEA"
            };

            // Act
            var areEquals = stock1.Equals(stock2);

            // Assert
            Assert.True(areEquals);
        }
Ejemplo n.º 12
0
        public void Test_StocksPreferredYield()
        {
            string stock         = "GIN";
            double lastDividend  = 8;
            double fixedDividend = 2;
            double parValue      = 100;
            double stockPrice    = 25;
            double price         = 64;
            double expected      = ((fixedDividend / 100) * parValue) / price;

            PreferredStock testStock = new PreferredStock(stock, lastDividend, fixedDividend, parValue, stockPrice);


            double dividendYield = testStock.DividendYield(price);

            Assert.AreEqual(expected, dividendYield);
        }
Ejemplo n.º 13
0
        public void Test_StocksPERatio()
        {
            string stock         = "GIN";
            double lastDividend  = 8;
            double fixedDividend = 2;
            double parValue      = 100;
            double stockPrice    = 25;
            double price         = 64;
            double expected      = price / lastDividend;

            PreferredStock testStock = new PreferredStock(stock, lastDividend, fixedDividend, parValue, stockPrice);


            double PEratio = testStock.PERatio(price);

            Assert.AreEqual(expected, PEratio);
        }
Ejemplo n.º 14
0
        public void TestPreferredStockPERatio()
        {
            // Test Preferred Stock

            PreferredStock stock;

            stock = new PreferredStock("TST", 10, 1, 100);

            float pe;

            // Test 0/10 => 0
            pe = stock.GetPERatio(0);
            Assert.AreEqual(0, pe, float.Epsilon);

            // Test 10/10 => 1
            pe = stock.GetPERatio(10);
            Assert.AreEqual(1, pe, float.Epsilon);

            // Test 10/0 => NaN
            stock.LastDividend = 0;
            pe = stock.GetPERatio(10);
            Assert.AreEqual(float.NaN, pe);

            // LastPrice
            stock = new PreferredStock("TST", 10, 1, 100);

            // Test 0/10 => 0
            stock.LastPrice = 0;
            pe = stock.GetPERatio();
            Assert.AreEqual(0, pe, float.Epsilon);

            // Test 10/10 => 1
            stock.LastPrice = 10;
            pe = stock.GetPERatio();
            Assert.AreEqual(1, pe, float.Epsilon);

            // Test 10/0 => NaN
            stock.LastPrice    = 10;
            stock.LastDividend = 0;
            pe = stock.GetPERatio();
            Assert.AreEqual(float.NaN, pe);
        }
Ejemplo n.º 15
0
        public void TestPreferredStockYield()
        {
            // Test Preferred Stock

            PreferredStock stock;

            stock = new PreferredStock("TST", 10, 0, 100);

            float yield;

            // Test 0*100/50 => 0
            yield = stock.GetDividendYield(50);
            Assert.AreEqual(0, yield, float.Epsilon);

            // Test 0.1*100/10 => 1
            stock.FixedDividend = 0.1f;
            yield = stock.GetDividendYield(10);
            Assert.AreEqual(1, yield, float.Epsilon);

            // Test 0.1*100/0 => NaN
            yield = stock.GetDividendYield(0);
            Assert.AreEqual(float.NaN, yield);

            // LastPrice
            stock = new PreferredStock("TST", 10, 0, 100);

            // Test 0*100/50 => 0
            stock.LastPrice = 50;
            yield           = stock.GetDividendYield();
            Assert.AreEqual(0, yield, float.Epsilon);

            // Test 0.1*100/10 => 1
            stock.LastPrice     = 10;
            stock.FixedDividend = 0.1f;
            yield = stock.GetDividendYield();
            Assert.AreEqual(1, yield, float.Epsilon);

            // Test 0.1*100/0 => NaN
            stock.LastPrice = 0;
            yield           = stock.GetDividendYield();
            Assert.AreEqual(float.NaN, yield);
        }
Ejemplo n.º 16
0
 public void TestCreationPreferredStock()
 {
     IStock prefStock = new PreferredStock(1, 2, "GIN", 2);
     Assert.IsNotNull(prefStock);
 }