@@ -35,22 +35,22 @@ def test_attributes_all(self):
3535
3636 def test_get_def_vars (self ):
3737 """ Test def_source_vars function."""
38- self .assertTrue (DiscRates .get_def_file_var_names ('xls' ) ==
38+ self .assertTrue (DiscRates .get_def_file_var_names ('xls' ) ==
3939 READ_SET ['XLS' ][0 ])
40- self .assertTrue (DiscRates .get_def_file_var_names ('.mat' ) ==
40+ self .assertTrue (DiscRates .get_def_file_var_names ('.mat' ) ==
4141 READ_SET ['MAT' ][0 ])
4242
4343class TestAppend (unittest .TestCase ):
4444 """Check append function"""
4545 def test_append_to_empty_same (self ):
46- """Append DiscRates to empty one."""
46+ """Append DiscRates to empty one."""
4747 disc_rate = DiscRates ()
4848 disc_rate_add = DiscRates ()
4949 disc_rate_add .tag .file_name = 'file1.txt'
5050 disc_rate_add .tag .description = 'descr1'
5151 disc_rate_add .years = np .array ([2000 , 2001 , 2002 ])
5252 disc_rate_add .rates = np .array ([0.1 , 0.2 , 0.3 ])
53-
53+
5454 disc_rate .append (disc_rate_add )
5555 disc_rate .check ()
5656
@@ -62,7 +62,7 @@ def test_append_to_empty_same(self):
6262 disc_rate_add .tag .description ))
6363
6464 def test_append_equal_same (self ):
65- """Append the same DiscRates. The inital DiscRates is obtained."""
65+ """Append the same DiscRates. The inital DiscRates is obtained."""
6666 disc_rate = DiscRates ()
6767 disc_rate .tag .file_name = 'file1.txt'
6868 disc_rate .tag .description = 'descr1'
@@ -74,7 +74,7 @@ def test_append_equal_same(self):
7474 disc_rate_add .tag .description = 'descr1'
7575 disc_rate_add .years = np .array ([2000 , 2001 , 2002 ])
7676 disc_rate_add .rates = np .array ([0.1 , 0.2 , 0.3 ])
77-
77+
7878 disc_rate .append (disc_rate_add )
7979 disc_rate .check ()
8080
@@ -97,7 +97,7 @@ def test_append_different_append(self):
9797 disc_rate_add .tag .description = 'descr2'
9898 disc_rate_add .years = np .array ([2000 , 2001 , 2003 ])
9999 disc_rate_add .rates = np .array ([0.11 , 0.22 , 0.33 ])
100-
100+
101101 disc_rate .append (disc_rate_add )
102102 disc_rate .check ()
103103
@@ -119,9 +119,62 @@ def test_read_two_pass(self):
119119 self .assertEqual (disc_rate .tag .description , 'desc1 + desc2' )
120120 self .assertEqual (disc_rate .years .size , 51 )
121121
122+ class TestSelect (unittest .TestCase ):
123+ """Test select method """
124+ def test_select_pass (self ):
125+ """Test select right time range."""
126+ disc_rate = DiscRates ()
127+ disc_rate .tag .file_name = 'file1.txt'
128+ disc_rate .tag .description = 'descr1'
129+ disc_rate .years = np .arange (2000 , 2050 )
130+ disc_rate .rates = np .arange (disc_rate .years .size )
131+
132+ year_range = np .arange (2010 , 2020 )
133+ sel_disc = disc_rate .select (year_range )
134+
135+ self .assertTrue (np .array_equal (sel_disc .years , year_range ))
136+ self .assertTrue (np .array_equal (sel_disc .rates , disc_rate .rates [10 :20 ]))
137+
138+ def test_select_wrong_pass (self ):
139+ """Test select wrong time range."""
140+ disc_rate = DiscRates ()
141+ disc_rate .tag .file_name = 'file1.txt'
142+ disc_rate .tag .description = 'descr1'
143+ disc_rate .years = np .arange (2000 , 2050 )
144+ disc_rate .rates = np .arange (disc_rate .years .size )
145+
146+ year_range = np .arange (2050 , 2060 )
147+ self .assertEqual (None , disc_rate .select (year_range ))
148+
149+ class TestNetPresValue (unittest .TestCase ):
150+ """Test select method """
151+ def test_net_present_value_pass (self ):
152+ """Test net_present_value right time range."""
153+ disc_rate = DiscRates ()
154+ disc_rate .tag .file_name = 'file1.txt'
155+ disc_rate .tag .description = 'descr1'
156+ disc_rate .years = np .arange (2000 , 2050 )
157+ disc_rate .rates = np .ones (disc_rate .years .size )* 0.02
158+
159+ val_years = np .ones (23 )* 6.512201157564418e9
160+ res = disc_rate .net_present_value (2018 , 2040 , val_years )
161+ self .assertEqual (res , 1.215049630691397e+11 )
162+
163+ def test_net_present_value_wrong_pass (self ):
164+ """Test net_present_value wrong time range."""
165+ disc_rate = DiscRates ()
166+ disc_rate .tag .file_name = 'file1.txt'
167+ disc_rate .tag .description = 'descr1'
168+ disc_rate .years = np .arange (2000 , 2050 )
169+ disc_rate .rates = np .arange (disc_rate .years .size )
170+ val_years = np .ones (11 )* 6.512201157564418e9
171+ self .assertEqual (None , disc_rate .net_present_value (2050 , 2060 , val_years ))
172+
122173# Execute Tests
123174TESTS = unittest .TestLoader ().loadTestsFromTestCase (TestChecker )
124175TESTS .addTests (unittest .TestLoader ().loadTestsFromTestCase (TestAppend ))
125176TESTS .addTests (unittest .TestLoader ().loadTestsFromTestCase (TestConstructor ))
126177TESTS .addTests (unittest .TestLoader ().loadTestsFromTestCase (TestReadParallel ))
178+ TESTS .addTests (unittest .TestLoader ().loadTestsFromTestCase (TestSelect ))
179+ TESTS .addTests (unittest .TestLoader ().loadTestsFromTestCase (TestNetPresValue ))
127180unittest .TextTestRunner (verbosity = 2 ).run (TESTS )
0 commit comments