summaryrefslogtreecommitdiff
path: root/22_tests_power/README
diff options
context:
space:
mode:
authorHaidong Ji2022-04-15 15:51:30 -0500
committerHaidong Ji2022-04-15 15:51:30 -0500
commit442a49ad5a48d417345959b903ae6a6d32d55759 (patch)
treec7127bb497e5e439018b1915e0136eec2c9cb124 /22_tests_power/README
Great C programming funHEADmaster
Excellent fundamentals and displine training, many tools and techniques exercises: gdb, emacs, valgrind, git
Diffstat (limited to '22_tests_power/README')
-rw-r--r--22_tests_power/README46
1 files changed, 46 insertions, 0 deletions
diff --git a/22_tests_power/README b/22_tests_power/README
new file mode 100644
index 0000000..24b1fd9
--- /dev/null
+++ b/22_tests_power/README
@@ -0,0 +1,46 @@
+For this assignment, you will be writing test cases for
+
+unsigned power (unsigned x, unsigned y);
+
+which you will be writing in the next assignment (if you want to read
+the instructions for the next assignment, they are provided in next-README).
+
+Unlike your previous testing assignments, you will be writing
+C code to perform the tests. In particular, you should create a file
+called test-power.c, which has a main function that performs the tests.
+
+If the power function passes all test cases, your program should exit
+with EXIT_SUCCESS. If the power function fails any test case, your program
+should exit with EXIT_FAILURE. Note that your program's exit status is the
+return value from main, if main returns. However, you can make your program
+exit immediately (wherever it is) by calling exit, passing in either EXIT_SUCCESS
+or EXIT_FAILURE, e.g.,
+
+exit(EXIT_FAILURE);
+
+A few notes about doing this assignment:
+ (1) You will want to write the prototype for power in your test-power.c
+ file before you call power, to let the compiler know the signature
+ of this function, and that the implementation will be found elsewhere.
+ (2) One correct and many broken implementations of power are provided
+ in the form of compiled object files in /usr/local/l2p/power/.
+ Of these, power.o is correct, and the others are broken.
+ (3) We have provided run_all.sh, which iterates over the object
+ files in /usr/local/l2p/power, and compiles your test code
+ and links it with each object file. It will make sure that
+ the correct implementation passes all of your test cases,
+ and that each broken implementation fails at least one test case.
+ (4) When I did this, I wrote the following helper function:
+ void run_check(unsigned x, unsigned y, unsigned expected_ans)
+ which calls power, checks that the result is expected_ans,
+ and if not, prints a message and calls exit(EXIT_FAILURE).
+ (5) You need your own way to provide the expected answers.
+ You might come up with them by hand, or find some other
+ means to produce them. However, there is no direct way
+ to invoke the correct implementation.
+ (6) As before, these broken implementations were created by making
+ small modifications to the correct implementation. All of them
+ can be found by reasonably crafted tests. The one that is likely
+ to be the most tricky arises due to the programmer using a variable
+ of an incorrect type somewhere (hint)...
+You should submit test-power.c when you are finished.