Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update erf::polynomial #1413

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

chris-ha458
Copy link

I changed erf::polynomial into more idiomatic code.

Although tests (cargo test) pass, I wasnt sure about the coverage so I tested it with my own version of the code.

#[cfg(test)]
mod tests {
    use super::*;

    fn run_tests(f: fn(f64, &[f64]) -> f64) -> Vec<(f64, f64)> {
        vec![
            (2.0, vec![1.0, 2.0, 3.0], 17.0),
            (2.0, vec![], 0.0),
            (2.0, vec![5.0], 5.0),
            (
                2.0,
                vec![1000000000.0, 2000000000.0, 3000000000.0],
                17000000000.0,
            ),
            (2.0, vec![0.001, 0.002, 0.003], 0.017),
            (2.0, vec![-1.0, -2.0, -3.0], -17.0),
        ]
        .into_iter()
        .map(|(z, coeff, expected)| {
            let result = f(z, &coeff);
            (result, expected)
        })
        .collect()
    }

    #[test]
    fn test_polynomial() {
        for (result, expected) in run_tests(polynomial) {
            assert_eq!(result, expected);
        }
    }

    #[test]
    fn test_polynom() {
        for (result, expected) in run_tests(polynom) {
            assert_eq!(result, expected);
        }
    }

    #[test]
    fn test_equivalence() {
        for (z, coeff, _) in vec![
            (2.0, vec![1.0, 2.0, 3.0], 17.0),
            (2.0, vec![], 0.0),
            (2.0, vec![5.0], 5.0),
            (
                2.0,
                vec![1000000000.0, 2000000000.0, 3000000000.0],
                17000000000.0,
            ),
            (2.0, vec![0.001, 0.002, 0.003], 0.017),
            (2.0, vec![-1.0, -2.0, -3.0], -17.0),
        ] {
            let result_poly = polynomial(z, &coeff);
            let result_polynom = polynom(z, &coeff);
            assert_eq!(result_poly, result_polynom);
        }
    }
}

The above code tests each the oroginal code polynomial, changed code polynom and whether they are equivalent to each other.

change into more idiomatic code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant