Colorado State University

Recitation R14 - Program Correctness
Fall 2013

CS160: Foundations in Programming


The purpose of this lab is to:

Pragmatic Testing

You won't see this material until upper level software engineering classes, but it should be incorporated into a slide set for this class. Some of this is fact and some is based on the observations of the instructor. However, many of these statements are commonly accepted in the areas of industry where I have worked: A recent trend in software engineering is Test-Driven Development (TDD), which specifies that tests be written before code. The philosophy behind this is that you can only truly understand (and define) the functionality of a piece of code by defining how it is tested. Many different approaches to testing exist, as shown below:
  1. Unit Testing: Test every method or subroutine in the software individually.
  2. Module Testing: Test the behavior of each module, taking into account state (member variables).
  3. Integration Testing: Test the interaction between modules, i.e. how does one class use another.
  4. System Testing: Test the software as a typical user would test it.
  5. Stress Testing: Try to overload the software, pushing it beyond normal usage.
  6. Code Coverage: Make sure that every line of software is tested.
  7. Branch Coverage: Test all branches through the software, i.e. every if/else-if/if in a conditional, every case in a switch, etc.
  8. Definition-Use: Test every path from the assignment of a variable to its use.
  9. Sanity Testing: Make sure the program doesn't crash immediately.
  10. Centerline Testing: Test using values that are expected.
  11. Boundary Testing: Test values that may cause problems: -1, 0, 1, zero length strings or arrays, null pointers.
  12. Error Testing: Test all the failure conditions to verify error paths in code.
  13. Regression Testing: Making sure that software does not go backwards by testing against an oracle.
  14. Platform Testing: Making sure that software is truly cross-platform (Windows, Mac, Linux).
And there are many, many, many more ways to test software: for example installation/acceptance/alpha/beta testing. The link to Wikipedia page on software testing is here. This is an area that occupies lots of software engineering researchers and developers in industry.


Program Correctness

The key ideas from the theoretical viewpoint of program correctness are as follows:
  1. Pre-Conditions characterize the input expected by a method, i.e. show the limitations of the code.
  2. Post-Conditions characterize the output expected from a method, i.e. show the functionality of the code.
  3. We can use these to prove program correctness, or more practically, to verify method behavior.
  4. We can account for pre and post-conditions even for different paths through the code (Conditional Rule).
  5. We can account for pre and post-conditions for iterative control such as loops (Loop Invariants).
  6. We can chain pre and post-conditions for individual methods to prove correctness for entire programs (Composition Rule).

Work on RamCT Quiz 5 with help from the TA


Checkin with the TA and show your score on RamCT Quiz 5 to get credit for this lab.

© 2013 CS160 Colorado State University. All Rights Reserved.