Skip to content

Commit

Permalink
irr: add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Anexen committed Oct 10, 2023
1 parent 337fc7e commit 9140fa0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/core/periodic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,8 @@ pub fn irr(values: &[f64], guess: Option<f64>) -> Result<f64, InvalidPaymentsErr

#[rustfmt::skip]
let breakpoint_list = [
&[0.0, 0.1, 0.3, 0.7, 1.0, 1e6],
&[0.0, -0.1, -0.3, -0.7, -0.9, -0.99999999999999]
&[0.0, 0.5, 1.0, 1e9],
&[0.0, -0.5, -0.9, -0.99999999999999]
];

for breakpoints in breakpoint_list {
Expand Down
28 changes: 28 additions & 0 deletions tests/test_periodic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,13 @@ fn test_nfv() {
#[case(&[-5.0, 10.5, 1.0, -8.0, 1.0], 0.08859833852)]
#[case(&[-5.0, 10.5, 1.0, -8.0, 1.0, 0.0, 0.0, 0.0], 0.08859833852)]
#[case(&[-40000.0, 5000.0, 8000.0, 12000.0, 30000.0], 0.10582259840)]
#[case(&[-10.0, 2.0, 2.0, 2.0, 2.0], -0.08364541746615073)]
#[case(&[
-5099701.25, -22503.796875, -22503.79296875, -22503.79296875, -20907.26171875,
-17899.7421875, -17899.7421875, -17899.7421875, -14660.69140625, -12447.80078125,
-12447.796875, -12018.1640625, -5991.81640625, -5991.81640625, -5991.81640625,
-2885.875, 1653.125, 1653.125, 1653.125, 8307.328125, 11110408.45703125
], 0.038039605693757084)]
fn test_irr_works(#[case] input: &[f64], #[case] expected: f64) {
Python::with_gil(|py| {
let values = PyList::new(py, input);
Expand All @@ -612,6 +619,27 @@ fn test_irr_works(#[case] input: &[f64], #[case] expected: f64) {
#[case(&[87.17; 5], &[-86.43], -0.49367042606)]
#[case(&[-87.17; 180], &[5809.3], -0.01352676905)]
#[case(&[-172545.848122807], &[787.735232517999; 480], 0.0038401048)]
#[case(&[
-12138.436076306429, 576.20775733699475, 576.20775733699475, 576.20775733699475,
576.20775733699475, 576.20775733699475, 576.20775733699475, 576.20775733699475,
576.20775733699475, 576.20775733699475, 576.20775733699475, 576.20775733699475,
576.20775733699475, 576.20775733699475, 576.20775733699475, 576.20775733699475,
576.20775733699475, 576.20775733699475, 576.20775733699475, 576.20775733699475,
], &[-528.88945762181788], -0.01562626238348752)]
#[case(&[
-10351.121144852736, 450.71546738230256, 450.71546738230256, 450.71546738230256,
450.71546738230256, 450.71546738230256, 450.71546738230256, 450.71546738230256,
450.71546738230256, 450.71546738230256, 450.71546738230256, 450.71546738230256,
450.71546738230256, 450.71546738230256, 450.71546738230256, 450.71546738230256,
450.71546738230256, 450.71546738230256, 450.71546738230256, 450.71546738230256,
], &[-654.38174757651018], -0.02792064231450042)]
#[case(&[
-15634.416942708685, 800.12182531566373, 800.12182531566373, 800.12182531566373,
800.12182531566373, 800.12182531566373, 800.12182531566373, 800.12182531566373,
800.12182531566373, 800.12182531566373, 800.12182531566373, 800.12182531566373,
800.12182531566373, 800.12182531566373, 800.12182531566373, 800.12182531566373,
800.12182531566373, 800.12182531566373, 800.12182531566373, 800.12182531566373
], &[-304.9753896431489], -0.004883289820554082)]
fn test_irr_equal_payments(#[case] first: &[f64], #[case] other: &[f64], #[case] expected: f64) {
let input: Vec<_> = first.iter().chain(other).collect();

Expand Down

0 comments on commit 9140fa0

Please sign in to comment.