jeudi 24 novembre 2016

why the test is failing when the inputs are different?

Im using unity to test some test cases, for example I want to test the addition operation. Im trying with the code below and Im not getting any error but in the command line when I run the program it appears: If I enter two numbers for example 20 and 10 i get: "Fail expeted 30 was 12 " If I enter two numbers equals I dont get any fail but it appears: "0 tests 0 failures 0 ignored" Do you know what can be wrong in the code below?

void addition()
{
    int n, total=0, k=0, number;
    printf("\nEnter the number of elements you want to add:");
    scanf("%d",&n);
    printf("Please enter %d numbers one by one: \n",n);
    while(k<n)
    {
        scanf("%d",&number);
        total=total+number;
        k=k+1;
    }
    printf("Sum of %d numbers = %d \n",n,total);

    runTestAddition(total, k, number);
}

void runTestAddition(int expected, int x, int y){
    UNITY_BEGIN();
    int actual;
    actual = x+y;
    TEST_ASSERT_EQUAL(expected, actual);
    return UNITY_END();
}

Aucun commentaire:

Enregistrer un commentaire