In: Computer Science
Its a (Test) Case of Swapping
Download swap_case_test.c here, or copy it to your CSE account using the following command:
cp -n /web/cs1511/20T3/activities/swap_case_test/swap_case_test.c .
Read Me First: Software Testing
One of the most fundamental parts of writing software is testing. In this course, we mostly do the testing for you -- the autotest program checks your software is correct. While this is handy, testing will not always be so easy. In the following labs, and in Assignment 2, there will be a focus on writing tests yourself.
For this program, you will be asked to write a program that tests some code -- the code you will test is your swap_case function from the previous exercise. To test your code, we have written some incorrect solutions. Your job is to tell us in whether the solution meets the specification given in the last exercise. That means, you will have to tell us whether swap_case:
Swap Case Test
Edit the C program swap_case_test.c (linked above) so that it tests whether the swap_case function is correct. You should not edit the main function; and you should not use scanf, printf, getchar or any other functions from stdio.h. You can hardcode the inputs to swap_case inside your testing functions.
You will only need to edit the test_lower_to_upper function, the test_upper_to_lower and the test_non_alphabetical function. Each function should call swap_case, and depending on it's output, should return MEETS_SPEC (if swap_case did the right thing, or DOES_NOT_MEET_SPEC if it does something unexpected.
For example, if swap_case was the following function:
int swap_case(int character) { return character; }
Your program should behave as follows:
dcc swap_case_test.c -o swap_case_test ./swap_case_test Testing turning an lowercase into uppercase: DOES NOT MEET SPEC Testing turning an uppercase into lowercase: DOES NOT MEET SPEC Testing a non-alphabetical character not changing: MEETS SPEC
For example, if swap_case was the following function:
int swap_case(int character) { return 1000; }
Your program should behave as follows:
dcc swap_case_test.c -o swap_case_test ./swap_case_test Testing turning an lowercase into uppercase: DOES NOT MEET SPEC Testing turning an uppercase into lowercase: DOES NOT MEET SPEC Testing a non-alphabetical character not changing: DOES NOT MEET SPEC
For example, if swap_case was the code you wrote in the last exercise, Your program should (hopefully) behave as follows:
dcc swap_case_test.c -o swap_case_test ./swap_case_test Testing turning an lowercase into uppercase: MEETS SPEC Testing turning an uppercase into lowercase: MEETS SPEC Testing a non-alphabetical character not changing: MEETS SPEC
NOTE: You don't need to test every valid input -- only testing one or two will be enough.
Solution:
Givendata:
One of the most fundamental parts of writing software is testing. In this course, we mostly do the testing for you -- the autotest program checks your software is correct. While this is handy, testing will not always be so easy. In the following labs, and in Assignment 2, there will be a focus on writing tests yourself.
Answer:
int swap_case(int character)
{
return character;
}
the problem with this code is that this code uses "int" to store a character. but it is not possible.
"int" stores only integer values.
so when you try to input any alphabet in "character", then you will get an error.
one should write 'char character' instead of 'int character'.
also, the function is a integer type. it can return only integer value. but we want the function to return characters.
so instead of 'int swap_case', we should use 'char swap_case'.
also, in the question you provided, there's no code written to swap the case of the characters.
so, even if we make the changes i told above, we will get the same output we took in the input. the case will not change.
for example:
'a' will remain 'a' only and will not be changed to 'A'.
so, we need to modify the code as well.
PLEASE GIVEME THUMBUP.....