Beispiel #1
0
        public void calculate_accrued_amount()
        {
            var calculator = new CompoundInterestCalculator();
            var fv         = calculator.AccruedAmount(1000, 0.07, 12, 3);

            Assert.AreEqual(fv, 1232.92, 0.009);
        }
Beispiel #2
0
        public void calculate_rate()
        {
            var calculator = new CompoundInterestCalculator();
            var r          = calculator.Rate(1000, 1233.07, 12, 3);

            Assert.AreEqual(r, 7.0, 0.01);
        }
        public void ShouldReturnCorrectValueAfterOneYear()
        {
            // Arrange
            double principal    = 100000;
            double interestRate = .06d;
            int    timesPerYear = 1;
            double years        = 1;
            var    expeted      = 106000;

            // Act
            var actual = CompoundInterestCalculator.Calculate(principal, interestRate, timesPerYear, years);

            // Assert
            Assert.AreEqual(expeted, actual);
        }
        public decimal YearToDateInterestEarned()
        {
            decimal startingBalance = 0;
            decimal interestRate    = InterestRate;
            var     intTrans        = new List <InterestTransaction>();

            foreach (var t in Transactions)
            {
                var intTx = new InterestTransaction(t.TransactionDate, t.Amount);
                intTrans.Add(intTx);
            }
            decimal interest = CompoundInterestCalculator.CalculateYearToDateInterest(startingBalance, interestRate, intTrans.ToArray());

            return(Math.Round(interest, 2));
        }
        public void CalculateAmountSavedTest()
        {
            //Arrange
            CompoundInterestCalculator calculator = new CompoundInterestCalculator()
            {
                Principal     = 1000.00,
                NumberOfYears = 12,
                InterestRate  = 1.5
            };

            //Act
            double result = calculator.CalculateAmountSaved();

            //Assert
            Assert.AreEqual(1195.62, result);
        }
        public void FutureBalance_1YearForward_ExpectsCorrectFutureBalance()
        {
            //Setup
            var      name    = "Savings Account 1";
            var      balance = 12.20m;
            var      expectedRateOfReturn  = 0.10m;
            var      contributionAmount    = 100m;
            DateTime targetDate            = DateTime.Now.AddYears(1);
            decimal  expectedFutureBalance = CompoundInterestCalculator.Calculate(balance, expectedRateOfReturn, 12,
                                                                                  CompoundInterestCalculator.FutureDateTimeToYears(targetDate), contributionAmount);

            //Test
            Account account = new Account(name, balance, expectedRateOfReturn, contributionAmount);

            //Assertion
            account.FutureBalance(targetDate).Should().Be(expectedFutureBalance);
        }
Beispiel #7
0
        public IActionResult Index(CompoundInterestCalculator model)
        {
            SetViewBagValues();
            if (!ModelState.IsValid)
            {
                return(View());
            }

            String compoundFrequency = model.SelectedCompoundedFrequency;

            switch (compoundFrequency)
            {
            case "Daily": model.CompoundFrequencyPerYear = 365;
                break;

            case "Weekly": model.CompoundFrequencyPerYear = 52;
                break;

            case "Fortnightly": model.CompoundFrequencyPerYear = 26;
                break;

            case "Monthly": model.CompoundFrequencyPerYear = 12;
                break;

            case "Quarterly": model.CompoundFrequencyPerYear = 4;
                break;

            case "SemiAnnually": model.CompoundFrequencyPerYear = 2;
                break;

            case "Yearly": model.CompoundFrequencyPerYear = 1;
                break;
            }

            model.TotalAccrued = model.CalculateAccruedAmount();



            return(View(model));
        }