Advanced C Programming

Fall 2022 ECE 264 :: Purdue University :: Section 3 (Quinn)

⚠ This is a PAST SEMESTER (Fall 2022).
Due 9/8

TDD

Goals

This assignment has the following goals:

  1. Learn how to tackle a programming assignment incrementally.
  2. Learn the basics of test-driven development
  3. Prepare to do HW05.

Overview

In this class—and virtually all future programming courses—the only viable way to build up a project is to build it incrementally, while testing and re-testing your implementation at every step. For many students, it can take a long time to learn this valuable lesson.

How to spend less time debugging (and more time enjoying the sunshine)

Let's illustrate t by example. Consider two approaches to doing HW05:

Student X and Student Y spend the same amount of time reading, coding, and making tests. The difference is that if Student Y has a bug, it must have been introduced no more than about 10 minutes ago, since the code is never broken for more than about 10 minutes at a time. When Student X has a bug, it could be practically anywhere, so each bug takes much longer to diagnose and fix.

Although this is just an illustration, it is based on our observations of students in past semesters, our own experiences, and a well-established software engineering process. Our version of TDD is simplified, but the core process is the same.

Test-driven development

To begin, first create an empty test code file (e.g., a main(…) with just one line: return EXIT_SUCCESS;) and an empty output file (e.g., empty text file). Make sure your testing process is working by simply running the test code file and verifying that the output matches the test output file. (Commands were given in HW02.) Then, proceed as follows:
  1. Create test. Choose the smallest/easiest piece of functionality that you can add to your implementation file (mintf.c). Add a test to your test code file (test_mintf.c) and the expected output in your test output file (test_mintf.txt).
  2. Add code. Write just enough code so that the new test passes. Your impelementation won't be complete yet, but everything you've written so far should work.
  3. Test. Check that your code now passes all of the tests written so far. If anything doesn't work, fix it before you go on. At the end of each cycle, 100% of your code should be working, even though some parts for other features may not be written yet.

Instructions

Read the instructions for HW05 before you proceed.

Create a file called plan.c with only a main(…) function.

In the main(…) function, write out a series of at least 10 stages that you will use to build your HW05 incrementally using TDD. Each stage must be in the following form:

// Test ##
TEST_CODE
// Expect: "EXPECTED_OUTPUT"

These stages will trace the steps from beginning your HW05 to finishing it. Each stage adds a small amount of required functionality that was not present in previous stages.

Later, when you implement your code for HW05, your code should never be broken for more than 10-15 minutes at a time, because you will be writing it in very small increments. After each stage, you will get your code completely working—for that subset of the functionality.

Assume that you are starting with a working print_integer(…). Thus, you do not need to have steps for testing internal aspects of print_integer(…). You are planning the development of your mintf(…) function for HW05.

More detailed criteria are given below under Requirements.

Note: Your plan.c will not be compiled or run by us. Instead, it is just serving as a sort of document for you to communicate your planned stages to us. Yes, this is weird.

Definitions: For purposes of these instructions, “implementation code” means your mintf.c; “test code” means your test_mintf.c; “test output” means your test_mintf.txt; and “test” means a small section of your plan.c (most likely in the main(…) and the corresponding snippet in your test_mintf.txt, which together can be used to verify that some aspect of your program works according to the specification.

Starter code

There is no starter code for HW03.

Requirements

  1. One file is required: plan.c
  2. Your plan.c must contain a main(…) containing ≥10 stages meeting the following criteria:
    1. Stage 00 is an empty test to check your testing framework. It should always pass.
    2. Tests for all stages from 0 to n pass with the implementation for stage n. In other words, the changes you make in stage i will not require breaking any of the tests associated with previous stages.
    3. Implementation code in stage i would fail the tests for stages <i.
    4. Implementation code in stage i+1 will be different from code in stage i.
    5. Implementation code in stage n+1 will add required functionality that was not in stage n.
    6. Implementation code in stage n+2 has more sloc* than implementation code for stage n.
      * sloc = “source lines of code” (excluding comments and blank lines)
    7. Altogether, the tests will comprehensively test your final implementation of mintf(…) for HW05. In other words, any implementation of mintf(…) that passes all of your tests mustshould be working perfectly.
  3. Each stage must be in the following format:
    // Test ##
    TEST_CODE
    // Expect: "EXPECTED_OUTPUT"
    
  4. Special for this assignment:
    1. You may copy anything in the screenshot, including stages 00 and 01. The rest of your test cases must be your own.
    2. Your code does not need to compile or run for this assignment (HW03).

While these requirements may initially sound complex, they are not. If you are following the spirit of the TDD method, all of this will almost certainly happen naturally.

The result will look something like this. You may copy/adapt anything in this screenshot ↓ ↓ ↓.

Scoring

Scores will be based on how well your steps follow the requirements.

Submit

To submit HW03 from within your hw03 directory, type 264submit HW03 plan.c

Q&A

  1. Will there be partial credit?
    No.
  2. Will this be accepted late?
    No.
  3. How many mistakes will you accept while still giving credit?
    ≥0.
  4. Why is this due before HW05?
    It will be more useful if you do it before you get too far into HW04.
  5. What if I have already finished HW05?
    If you followed TDD, you can use this to explain your process. If not, you can use this to explain how you could have used TDD for HW05.
  6. Is this unfair to those who already finished HW05?
    Maybe a little, but everyone can benefit. Also, it's a small thing. As of the time of posting this (Mon 2/3/2020 morning), 31.7% of the class had started, 6.9% had submitted something, and 1.5% had submitted something that passes the current pretester.