11import pytest
2- import numpy as np
32
43from project_selection import select_proposals_to_fund
54
2019 ],
2120)
2221def test_select_proposals_wrong_input (proposals , errmessage ):
23- np .random .seed (2025 )
2422 budget = 5
2523 funding_limit = 2
2624 with pytest .raises (ValueError , match = errmessage ):
27- select_proposals_to_fund (budget , funding_limit , proposals )
25+ select_proposals_to_fund (budget , funding_limit , proposals , seed = 2025 )
2826
2927
3028def test_select_proposals_all_funds (capfd ):
31- np .random .seed (2025 )
3229 budget = 5
3330 funding_limit = 2
3431 proposals = [("A" , 2 , 0 ), ("B" , 1 , 0 ), ("C" , 1 , 0 ), ("D" , 0.5 , 0 ), ("E" , 0.5 , 0 )]
@@ -55,15 +52,17 @@ def test_select_proposals_all_funds(capfd):
5552 'Fund "C" for $1 bringing its project\' s annual total to $1.\n '
5653 'Fund "A" for $2 bringing its project\' s annual total to $2.\n '
5754 )
58- result = select_proposals_to_fund (budget , funding_limit , proposals )
55+ result = select_proposals_to_fund (budget ,
56+ funding_limit ,
57+ proposals ,
58+ seed = 2025 )
5959 captured = capfd .readouterr ()
6060
6161 assert set (result ) == expected_result
6262 assert captured .out == expected_captured
6363
6464
6565def test_select_proposals_more_than_funds (capfd ):
66- np .random .seed (2025 )
6766 budget = 5
6867 funding_limit = 2
6968 proposals = [
@@ -103,15 +102,17 @@ def test_select_proposals_more_than_funds(capfd):
103102 'Fund "B" for $1 bringing its project\' s annual total to $1.\n '
104103 'Fund "A" for $2 bringing its project\' s annual total to $2.\n '
105104 )
106- result = select_proposals_to_fund (budget , funding_limit , proposals )
105+ result = select_proposals_to_fund (budget ,
106+ funding_limit ,
107+ proposals ,
108+ seed = 2025 )
107109 captured = capfd .readouterr ()
108110
109111 assert set (result ) == expected_result
110112 assert captured .out == expected_captured
111113
112114
113115def test_select_proposals_more_than_funds_under (capfd ):
114- np .random .seed (2025 )
115116 budget = 4.1
116117 funding_limit = 2
117118 proposals = [
@@ -150,15 +151,17 @@ def test_select_proposals_more_than_funds_under(capfd):
150151 'Fund "D" for $0.5 bringing its project\' s annual total to $0.5.\n '
151152 'Fund "B" for $1 bringing its project\' s annual total to $1.\n '
152153 )
153- result = select_proposals_to_fund (budget , funding_limit , proposals )
154+ result = select_proposals_to_fund (budget ,
155+ funding_limit ,
156+ proposals ,
157+ seed = 2025 )
154158 captured = capfd .readouterr ()
155159
156160 assert set (result ) == expected_result
157161 assert captured .out == expected_captured
158162
159163
160164def test_select_proposals_more_than_funds_eqweight_zero (capfd ):
161- np .random .seed (2025 )
162165 budget = 6
163166 funding_limit = 2
164167 proposals = [
@@ -198,15 +201,17 @@ def test_select_proposals_more_than_funds_eqweight_zero(capfd):
198201 'Fund "C" for $1 bringing its project\' s annual total to $1.\n '
199202 'Fund "A" for $1 bringing its project\' s annual total to $1.\n '
200203 )
201- result = select_proposals_to_fund (budget , funding_limit , proposals )
204+ result = select_proposals_to_fund (budget ,
205+ funding_limit ,
206+ proposals ,
207+ seed = 2025 )
202208 captured = capfd .readouterr ()
203209
204210 assert set (result ) == expected_result
205211 assert captured .out == expected_captured
206212
207213
208214def test_select_proposals_more_than_funds_eqweight_under (capfd ):
209- np .random .seed (2025 )
210215 budget = 5.4
211216 funding_limit = 2
212217 proposals = [
@@ -245,15 +250,17 @@ def test_select_proposals_more_than_funds_eqweight_under(capfd):
245250 'Fund "D" for $1 bringing its project\' s annual total to $1.\n '
246251 'Fund "C" for $1 bringing its project\' s annual total to $1.\n '
247252 )
248- result = select_proposals_to_fund (budget , funding_limit , proposals )
253+ result = select_proposals_to_fund (budget ,
254+ funding_limit ,
255+ proposals ,
256+ seed = 2025 )
249257 captured = capfd .readouterr ()
250258
251259 assert set (result ) == expected_result
252260 assert captured .out == expected_captured
253261
254262
255263def test_select_proposals_more_than_funds_eqweight_over (capfd ):
256- np .random .seed (2025 )
257264 budget = 6.6
258265 funding_limit = 2
259266 proposals = [
@@ -294,7 +301,10 @@ def test_select_proposals_more_than_funds_eqweight_over(capfd):
294301 'Fund "A" for $1 bringing its project\' s annual total to $1.\n '
295302 'Fund "F" for $1 bringing its project\' s annual total to $1.\n '
296303 )
297- result = select_proposals_to_fund (budget , funding_limit , proposals )
304+ result = select_proposals_to_fund (budget ,
305+ funding_limit ,
306+ proposals ,
307+ seed = 2025 )
298308 captured = capfd .readouterr ()
299309
300310 assert set (result ) == expected_result
0 commit comments