summaryrefslogtreecommitdiff
path: root/22_tests_power/README
blob: 24b1fd9f0456ef3f1384e9bb5485908c355ede9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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.