|
1 | 1 | import math
|
2 | 2 | from decimal import Decimal
|
3 | 3 |
|
4 |
| -import hypothesis.extra.numpy as npst |
5 |
| -import hypothesis.strategies as st |
6 |
| - |
7 | 4 | # Don't use 'import numpy as np', to avoid accidentally testing
|
8 | 5 | # the versions in numpy instead of numpy_financial.
|
9 | 6 | import numpy
|
10 | 7 | import pytest
|
11 |
| -from hypothesis import assume, given, settings |
| 8 | +from hypothesis import assume, given |
12 | 9 | from numpy.testing import (
|
13 | 10 | assert_,
|
14 | 11 | assert_allclose,
|
|
17 | 14 | )
|
18 | 15 |
|
19 | 16 | import numpy_financial as npf
|
20 |
| - |
21 |
| - |
22 |
| -def float_dtype(): |
23 |
| - return npst.floating_dtypes(sizes=[32, 64], endianness="<") |
24 |
| - |
25 |
| - |
26 |
| -def int_dtype(): |
27 |
| - return npst.integer_dtypes(sizes=[32, 64], endianness="<") |
28 |
| - |
29 |
| - |
30 |
| -def uint_dtype(): |
31 |
| - return npst.unsigned_integer_dtypes(sizes=[32, 64], endianness="<") |
32 |
| - |
33 |
| - |
34 |
| -real_scalar_dtypes = st.one_of(float_dtype(), int_dtype(), uint_dtype()) |
35 |
| - |
36 |
| - |
37 |
| -cashflow_array_strategy = npst.arrays( |
38 |
| - dtype=real_scalar_dtypes, |
39 |
| - shape=npst.array_shapes(min_dims=1, max_dims=2, min_side=0, max_side=25), |
40 |
| -) |
41 |
| -cashflow_list_strategy = cashflow_array_strategy.map(lambda x: x.tolist()) |
42 |
| - |
43 |
| -cashflow_array_like_strategy = st.one_of( |
| 17 | +from numpy_financial.tests.strategies import ( |
44 | 18 | cashflow_array_strategy,
|
45 |
| - cashflow_list_strategy, |
46 |
| -) |
47 |
| - |
48 |
| -short_scalar_array_strategy = npst.arrays( |
49 |
| - dtype=real_scalar_dtypes, |
50 |
| - shape=npst.array_shapes(min_dims=0, max_dims=1, min_side=0, max_side=5), |
51 |
| -) |
52 |
| - |
53 |
| - |
54 |
| -when_strategy = st.sampled_from( |
55 |
| - ['end', 'begin', 'e', 'b', 0, 1, 'beginning', 'start', 'finish'] |
| 19 | + cashflow_array_like_strategy, |
| 20 | + short_nicely_behaved_doubles, |
| 21 | + when_strategy, |
56 | 22 | )
|
57 | 23 |
|
58 | 24 |
|
@@ -285,8 +251,7 @@ def test_npv(self):
|
285 | 251 | rtol=1e-2,
|
286 | 252 | )
|
287 | 253 |
|
288 |
| - @given(rates=short_scalar_array_strategy, values=cashflow_array_strategy) |
289 |
| - @settings(deadline=None) |
| 254 | + @given(rates=short_nicely_behaved_doubles, values=cashflow_array_strategy) |
290 | 255 | def test_fuzz(self, rates, values):
|
291 | 256 | npf.npv(rates, values)
|
292 | 257 |
|
@@ -421,17 +386,17 @@ def test_mirr_no_real_solution_exception(self):
|
421 | 386 |
|
422 | 387 | @given(
|
423 | 388 | values=cashflow_array_like_strategy,
|
424 |
| - finance_rate=short_scalar_array_strategy, |
425 |
| - reinvestment_rate=short_scalar_array_strategy, |
| 389 | + finance_rate=short_nicely_behaved_doubles, |
| 390 | + reinvestment_rate=short_nicely_behaved_doubles, |
426 | 391 | )
|
427 | 392 | def test_fuzz(self, values, finance_rate, reinvestment_rate):
|
428 | 393 | assume(finance_rate.size == reinvestment_rate.size)
|
429 | 394 | npf.mirr(values, finance_rate, reinvestment_rate)
|
430 | 395 |
|
431 | 396 | @given(
|
432 | 397 | values=cashflow_array_like_strategy,
|
433 |
| - finance_rate=short_scalar_array_strategy, |
434 |
| - reinvestment_rate=short_scalar_array_strategy, |
| 398 | + finance_rate=short_nicely_behaved_doubles, |
| 399 | + reinvestment_rate=short_nicely_behaved_doubles, |
435 | 400 | )
|
436 | 401 | def test_mismatching_rates_raise(self, values, finance_rate, reinvestment_rate):
|
437 | 402 | assume(finance_rate.size != reinvestment_rate.size)
|
@@ -468,10 +433,10 @@ def test_broadcast(self):
|
468 | 433 | )
|
469 | 434 |
|
470 | 435 | @given(
|
471 |
| - rates=short_scalar_array_strategy, |
472 |
| - payments=short_scalar_array_strategy, |
473 |
| - present_values=short_scalar_array_strategy, |
474 |
| - future_values=short_scalar_array_strategy, |
| 436 | + rates=short_nicely_behaved_doubles, |
| 437 | + payments=short_nicely_behaved_doubles, |
| 438 | + present_values=short_nicely_behaved_doubles, |
| 439 | + future_values=short_nicely_behaved_doubles, |
475 | 440 | whens=when_strategy,
|
476 | 441 | )
|
477 | 442 | def test_fuzz(self, rates, payments, present_values, future_values, whens):
|
|
0 commit comments