Example program
Contents of the example
The file example.tar contains:
- The main file "example.cpp", which makes use of CAC++ and runs the verifications.
- The file "student.cpp", which simulates the code implemented by a student.
-
A "Makefile" with the following rules (see Setup to configure this file):
- check: compile and execute the program.
- clean: remove the generated files.
Extract the files and place the folder "example" in the same directory as the extracted folder of the CAC++ library ("cac++"). Then execute "make check":
cd example
make check
What the example checks
The program has been implemented to check that:
-
There is a class with the name Example. To that end, the
verification
findClassis used. -
There is a default constructor defined for that class. To that
end, the verification
defaultConstructoris used. -
A method with the name referencedMethod or referredMethod is invoked
within the method mainMethod(int). To that end, the verification
methodWithReferencedMethodis used.
Notes:
- A wildcard (?) can be used to indicate that a particular parameter of the verification should not be taken into account, especially when the information is not known or is unimportant. For instance, it is not relevant whether the involved methods are const or not.
-
A regular expression can be used when there are different alternatives for
the name of a declaration. For instance, in the case of referencedMethod or
referredMethod, we use
refer.*edMethod.
Result of the execution
The result of the execution should be:
Verifications for the class Example
*************************************
Reuse is not being carried out as indicated in the practice.
-------------------
Review the messages related to the class Example.
The third verification is not met by the current code in "student.cpp" since mainMethod is not calling referencedMethod. Open the file "student.cpp" and replace mainMethod with:
void mainMethod(int p){
a = referencedMethod() + p;
}
If you compile and execute again with "make check", the result should be:
Verifications for the class Example
*************************************
Class Example correct.