public void TestCommonShareDividendYieldCalculation(double lastdividend, int parValue, double price,
                                                            double expectedValue)
        {
            CommonStock commonStock = new CommonStock("Test", lastdividend, parValue);

            Assert.AreEqual(commonStock.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));
        }
Exemple #3
0
        public void CalculateDividendYield_WithZeroPrice_ThrowsArgumentException()
        {
            // Arrange
            var stock = new CommonStock
            {
                LastDividend = 20
            };

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

            // Assert
            Assert.That(testDelegate, Throws.ArgumentException);
        }
Exemple #4
0
        public decimal CalculateDividendYield_WithNonZeroPriceAndPositiveDividend_CorrectlyCalculates(decimal price)
        {
            // Arrange
            var stock = new CommonStock
            {
                LastDividend = 10
            };

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

            // Assert
            return(result);
        }