// http://rosettacode.org/wiki/Roots_of_a_function

fn find_roots<T: Copy + PartialOrd + Signed>(f: |T| -> T, start: T, stop: T,
                                             step: T, epsilon: T) -> Vec<T> {
    let mut ret = vec![];
    let mut current = start;
    while current < stop {
        if f(current).abs() < epsilon {
            ret.push(current);
        }
        current = current + step;
    }
    ret
}

#[test]
fn test_find_roots() {
    let roots = find_roots(|x: f64| x*x*x - 3.0*x*x + 2.0*x,
                           -1.0, 3.0, 0.0001, 0.00000001);
    let expected = [0.0f64, 1.0, 2.0];

    for (&a, &b) in roots.iter().zip(expected.iter()) {
        assert!((a - b).abs() < 0.0001);
    }
}

#[cfg(not(test))]
fn main() {
    let roots = find_roots(|x: f64| x*x*x - 3.0*x*x + 2.0*x,
                           -1.0, 3.0, 0.0001, 0.00000001);

    println!("roots of f(x) = x^3 - 3x^2 + 2x are: {}", roots);
}

Implement "Roots of a function" problem.
Implement "Roots of a function" problem.
