1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . Linq ;
3
4
using Algorithms . Financial ;
4
5
using FluentAssertions ;
5
6
using NUnit . Framework ;
@@ -8,30 +9,21 @@ namespace Algorithms.Tests.Financial;
8
9
9
10
public static class PresentValueTests
10
11
{
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 ) ]
17
16
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 ) ;
21
22
22
- PresentValue . Calculate ( 0.07 , [ 109129.39 , 30923.23 , 15098.93 , 29734.0 , 39.0 ] )
23
- . Should ( )
24
- . Be ( 175519.15 ) ;
25
23
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 [ ] { } ) ]
30
26
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 ( ) ) ) ;
37
29
}
0 commit comments