To implement a C program that allows users to register for an event based on their age, we'll first decide the acceptable age range. For this example, let's assume the valid age range is 18 to 60, inclusive. The program will validate user input against this range and provide feedback.
Below is a simple C program that accomplishes this task, followed by the design of test cases using equivalence class value testing strategies.
C Program
#include <stdio.h>
int main() {
int age;
printf("Enter your age to register for the event: ");
scanf("%d", &age);
if (age >= 18 && age <= 60) {
printf("Registration successful.\n");
} else {
printf("Invalid age. Registration unsuccessful.\n");
}
return 0;
}
Test Cases Using Equivalence Class Value Testing
Equivalence class value testing involves dividing input data into partitions of equivalent data from which test cases can be derived. Here are test cases that cover the typical, boundary, and invalid inputs:
-
Typical Valid Input (Middle Point)
- Test Case 1: Age = 30 (within valid range)
- Expected Outcome: Registration successful.
-
Boundary Valid Inputs
- Test Case 2: Age = 18 (lower boundary of valid range)
- Expected Outcome: Registration successful.
- Test Case 3: Age = 60 (upper boundary of valid range)
- Expected Outcome: Registration successful.
-
Boundary Invalid Inputs
- Test Case 4: Age = 17 (just below the valid range)
- Expected Outcome: Invalid age. Registration unsuccessful.
- Test Case 5: Age = 61 (just above the valid range)
- Expected Outcome: Invalid age. Registration unsuccessful.
-
Invalid Inputs (Out of Range)
- Test Case 6: Age = 10
- Expected Outcome: Invalid age. Registration unsuccessful.
- Test Case 7: Age = 70
- Expected Outcome: Invalid age. Registration unsuccessful.
-
Non-integer Input
- Test Case 8: Enter a non-integer value (such as a string or a special character). Note: The C program will need additional handling to cover non-integer cases as
scanf will fail with non-integer input; typically, this is handled through input sanitization before calling scanf.
- Expected Outcome: The program may not behave correctly unless enhanced input validation logic is implemented.
By executing these test cases, you can ensure that the program correctly validates ages against the defined criteria and provides appropriate feedback, fulfilling the requirements of equivalence class testing. To handle Test Case 8 accurately, consider adding error handling for non-integer inputs.