October 24, 2024
Chicago 12, Melborne City, USA
C#

Testing if the program is running correctly


I’ve got a program that it basically saying if the users input are inside, outside or on the rectangle edge and now i have written a test for this program that is suppost to tell the user if the test/tests are successful or not and i want to do do a test for every dot in a x-y table and then in the end tell if all test where successful or not.

The problem I have is that i’m not sure how to put it inside the base code so the test will work. Is it suppost to be in the beginning or the end(since the program exits after it tells the user where the dot is located)? Should I do an array for the test or not? Thankful for any help how to write the code inside the base code:

#include <stdio.h>

int throw_at_rectangle(double x, double y, double x1, double y1, double x2, double y2)
{
    // First corner (bottom left) of the rectangle
    printf("Choose x and y for the first corner that the rectangle should start:\n");
    scanf("%lf%lf", &x1, &y1);

    // Opposite corner(top right) that should make the rectangle possible 
    printf("Choose x and y for the first corner that the rectangle should end:\n");
    scanf("%lf%lf", &x2, &y2);

    // The position of the point that should be checked
    printf("Choose the x and y that should be checked:\n");
    scanf("%lf%lf", &x, &y);

    if (x1 < x && x < x2 && y1 < y && y < y2)
    {
        return 5;
    }
    else if ((x1 == x || x == x2) && (y1 == y || y == y2))
    {
        return 3;
    }
    else
    {
        return 0;
}

This is the test i want to use:

int testx()             //i'm doing 6 test(for every dot) with the different names(testx/testy/testx1/testx2 etc.)
{
int result;
const int expected = n;
result = throw_at_rectangle (…);    //throw_at_rectangle ( name of function at the moment its called main() )
if(result == expected){
    printf(“testx succeeded!\n”);
    return 1;
}
else{
    printf(“testx failed!\n”);
    return 0;
}
}

example:

(After base code has been run and told the user where the dot is located it goes to the tests)

If each of the test functions returns 1 when the test case succeeds(it returns the correct result) and it returns 0 if the test case fails



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video