Software Methods and Tools

Kenneth M. Anderson <kena@cs.colorado.edu>

Lecture 17: Program Verification

Today's Lecture

Program Verification

Program Correctness

Program Specifications

Testing Terminology

Term Definition
Error a mistake made by a programmer.

Implies that for some input i, F(i) ≠ expected output

Fault an incorrect state of a program that is entered due to an error.

Some errors don’t cause failures right away, every state between the error and the failure are faults For this class, however, you can think of a “fault” as being the location in the code where the error exists

Failure a symptom of an error.

For example, a crash, incorrect output, incorrect behavior, …

Discussion

An Example

if (x < y)
if (x <= y)
  • The error may be a typo, or could be the result of the programmer not understanding the problem domain or the program's specification
  • The fault is the location of the error, e.g. the expression contained in the if statement, or more explicitly the missing “=”
  • A failure may occur if x equals y and the if statement is executed
  • Creating Correct Programs (1 of 3)

    Creating Correct Programs (2 of 3)

    Creating Correct Programs (3 of 3)

    Creating Test Cases

    A test case consists of:

    Input The specific values given to a program
    Expected Output The output predicated by a program's specification
    Documentation What type of failure is this test case testing?

    Test Run

    Test cases are applied to a program during a test run. A test run consists of:

    Actual Output The output generated by a program when given the input of a test case
    Pass/Fail Grade Did the actual output match the expected output?

    Test runs are typically supported by a “testing harness” or “test scaffolding”. This refers to the software that helps you perform (or sometimes automate) test runs

    Testing Process

    1. For each class of failure defined in the documentation
    2. For each test case in that class
    3. Apply the input and compare the output to the specification
    4. Record results
    5. Fix discovered problems
    6. Repeat until all test cases pass
    TestingProcess

    Creating Test Cases

    Example

    int GreatestCommonDivisor(int x, int y)
    1. x=6 y=9, returns 3, tests common case
    2. x=2 y=4, returns 2, tests when x is the GCD
    3. x=3 y=5, returns 1, tests two primes
    4. x=9 y=0, returns ?, tests zero input value
    5. x=-3 y=9, returns ?, tests negative input value

    To test exhaustively is impossible (both parameters can take on an infinite number of values) but with 5 categories identified, we can get by with only 5 test cases!

    Coming Up Next