1. ## At a loss

Okay, so I'm not asking you to do my homework for me, I just need help. It has to do with TDD in C. I was always taught that you need to write the tests first and then write the code. However, my professor gave us the code and told us to write the tests. I'm at a loss, I have no idea where to even start. This portion of the assignment is worth such a small portion of the grade but I can't move on with getting it to "go green" in TDD terms. I asked my professor for help and she basically laughed and told me she doesn't have time to explain. I'm seriously so lost and any help what so ever would be greatly appreciated. The written code that I need to write tests for is a simple swap method and a bubblesort method.

Code:
```/**
* swaps the values referenced by p and q
*/

void swap (int *p, int *q)
{
int tmp;
tmp = *p;
*p = *q;
*q = tmp;
}
/**
* an implementation of bubble sort
* n is the size of array a
*/
void bubble (int a[], int n)
{
int i, j;
for (i = 0; i<n-1; i++)
{
for (j = n-1; i < j; j--)
{
if (a[j-1] > a[j])
{
swap (&a[j-1], &a[j]);
}
}
}
}```

Any help at all is very much appreciated! Thank you in advance! 2. How about starting with a main? Create an unordered array and pass it to the function along with the length. Start with simple test that should work, then you can try to throw some curve balls to make it fail. 3. I know how to write the main() I just don't know how to write the actual tests. I don't understand the concept of what they do. I'm the kind of person who learns by seeing examples and I've never seen a test written in C before 4. If you have to do it in functions then just write them like you would a main. The tests are just to see if the code worked the way you expected. You can try and make the array of length 0 to see how it handles it, and other little curve balls.

Code:
```void test1(void)
{
//DECLARE LOCAL ARRAY
// fill array with random values
// print unordered array
//Pass array and legth the bubble function
//print array to see if it is now ordered
}``` 5. I don't understand. You say are used to writing the tests first and that you're accustomed to that. In that case pretend your professor hasn't given you the implementation and... write the tests. 6. I would go for dryrun testing. Traditionally we would create a "DryRun" test sheet with each variable in a column of its own. We would then work our way through a structure diagram of the program manually updating the variable on the test sheet as if they were being done by the program its self.

Part of the test design would be to select what inputs we were going to use (based on the scope of the question) and what our expected outcome would be.

Then using the inputs to work through the structure and recording on the test sheet we test that the outcome is the expected outcome. Popular pages Recent additions 