jeudi 7 janvier 2016

How can I create parameterized test in rust?

I want to write rust test cases that depend on parameters. So my test case should be executed for each parameter and I want to see whether it succeeds or fails for each parameter.

I'm used to write things like that in Java:

@RunWith(Parameterized.class)
public class FibonacciTest {
    @Parameters
    public static Collection<Object[]> data() {
        return Arrays.asList(new Object[][] {     
                 { 0, 0 }, { 1, 1 }, { 2, 1 }, { 3, 2 }, { 4, 3 }, { 5, 5 }, { 6, 8 }  
           });
    }

    private int fInput;

    private int fExpected;

    public FibonacciTest(int input, int expected) {
        fInput= input;
        fExpected= expected;
    }

    @Test
    public void test() {
        assertEquals(fExpected, Fibonacci.compute(fInput));
    }
}

How can I achieve something similar with rust? Simple test cases are working fine, but there are cases where they are not enough.

#[test]
fn it_works() {
    assert!(true);
}

Aucun commentaire:

Enregistrer un commentaire