|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using Algorithms.Financial; |
| 5 | +using FluentAssertions; |
| 6 | +using NUnit.Framework; |
| 7 | + |
| 8 | +namespace Algorithms.Tests.Financial; |
| 9 | + |
| 10 | +public static class PresentValueTests |
| 11 | +{ |
| 12 | + [TestCase(0.13,new[] { 10.0, 20.70, -293.0, 297.0 },4.69)] |
| 13 | + [TestCase(0.07,new[] { -109129.39, 30923.23, 15098.93, 29734.0, 39.0 }, -42739.63)] |
| 14 | + [TestCase(0.07, new[] { 109129.39, 30923.23, 15098.93, 29734.0, 39.0 }, 175519.15)] |
| 15 | + [TestCase(0.0, new[] { 109129.39, 30923.23, 15098.93, 29734.0, 39.0 }, 184924.55)] |
| 16 | + |
| 17 | + public static void Present_Value_General_Tests(double discountRate,double[] cashFlow ,double expected) |
| 18 | + => |
| 19 | + PresentValue.Calculate(discountRate, cashFlow.ToList()) |
| 20 | + .Should() |
| 21 | + .Be(expected); |
| 22 | + |
| 23 | + |
| 24 | + [TestCase(-1.0, new[] { 10.0, 20.70, -293.0, 297.0 })] |
| 25 | + [TestCase(1.0,new double[] {})] |
| 26 | + |
| 27 | + public static void Present_Value_Exception_Tests(double discountRate, double[] cashFlow) |
| 28 | + => Assert.Throws<ArgumentException>(() => PresentValue.Calculate(discountRate, cashFlow.ToList())); |
| 29 | +} |
0 commit comments