Skip to content

Commit 25cc43d

Browse files
use testcase in financial tests
1 parent 5b536cc commit 25cc43d

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using Algorithms.Financial;
45
using FluentAssertions;
56
using NUnit.Framework;
@@ -8,30 +9,21 @@ namespace Algorithms.Tests.Financial;
89

910
public static class PresentValueTests
1011
{
11-
[Test]
12-
public static void Present_Value_General_Tests()
13-
{
14-
PresentValue.Calculate(0.13, [10.0, 20.70, -293.0, 297.0])
15-
.Should()
16-
.Be(4.69);
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)]
1716

18-
PresentValue.Calculate(0.07, [-109129.39, 30923.23, 15098.93, 29734.0, 39.0])
19-
.Should()
20-
.Be(-42739.63);
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);
2122

22-
PresentValue.Calculate(0.07, [109129.39, 30923.23, 15098.93, 29734.0, 39.0])
23-
.Should()
24-
.Be(175519.15);
2523

26-
PresentValue.Calculate(0.0, [109129.39, 30923.23, 15098.93, 29734.0, 39.0])
27-
.Should()
28-
.Be(184924.55);
29-
}
24+
[TestCase(-1.0, new[] { 10.0, 20.70, -293.0, 297.0 })]
25+
[TestCase(-1.0,new double[] {})]
3026

31-
[Test]
32-
public static void Present_Value_Exception_Tests()
33-
{
34-
Assert.Throws<ArgumentException>(() => PresentValue.Calculate(-1.0, [10.0, 20.70, -293.0, 297.0]));
35-
Assert.Throws<ArgumentException>(() => PresentValue.Calculate(1.0, []));
36-
}
27+
public static void Present_Value_Exception_Tests(double discountRate, double[] cashFlow)
28+
=> Assert.Throws<ArgumentException>(() => PresentValue.Calculate(discountRate, cashFlow.ToList()));
3729
}

0 commit comments

Comments
 (0)