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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>

// For this example, we will do HW04 for print_integer(…) instead of for mintf(…).

int main(int argc, char* argv[]) {

    // Test 00: empty test (to check mechanics of running tests)
    // (nothing)
    // Expect: ""
    
    // Test 01: fixed digit in any base with no prefix
    print_integer(0, 10, "");
    // Expect: "0"

    // Test 02: non-negative single-digit number in base 10
    print_integer(5, 10, "");
    // Expect: "5"

    // Test 03: … any base
    print_integer(10, 16, "");
    // Expect: "a"

    // Test 04: … multiple digits
    print_integer(123, 10, "");
    // Expect: "123"
    
    // Note:  At this point (before test 05—and the corresponding implememtation code—have been
    // added), print_integer(-123, 10, "") should fail.  Therefore, you satisfy the criteria,
    // “Implementation code in stage i would fail the tests for stages <i.”
    //
    // To make print_integer(-123, 10, "") pass, you will need to CHANGE your implementation code,
    // and therefore you will satisfy the criteria, “Implementation code in stage i+1 will be
    // different from code in stage i.”
    //
    // Because test 05 adds the functionality of dealing with negative numbers, you will satisfy the
    // criteria, “Implementation code in stage n+1 will add required functionality that was not in
    // stage n.”


    // Test 05: … negative
    print_integer(-123, 10, "");
    // Expect: "-123"

    // Test 06: … with single-character prefix
    print_integer(-123, 10, "$");
    // Expect: "-$123"

    // Test 07: … with multiple-character prefix
    print_integer(-123, 10, "$/€");
    // Expect: "-$/€123"

    // Your implementation «is» "complete" at this point.  IOW, you now have all of the features
    // that print_integer(…) is supposed to have.  However, there might be bugs.  That's where
    // (the rest of your) testing comes in.
    //
    // IN THEORY… Your implementation «should» be perfect at this point.

    /*
     Q: Should we implement any specific test cases for INT_MAX/INT_MIN?
     A: Yes, to “test” your code adequately, you should check for such edge cases, but that is
        not a necessary part of using TDD.

     Q: Sorry follow up question: since Its not necessary to have edge cases, should we not include
        them in hw04 or hw05?  Or just include it naturally in other cases?
     A: Definitely check edge cases in your test code.  It is probably not necessary for TDD, but
        if you follow the criteria, you may.  Scoring will be based on “plausible” and “reasonable”
        implementation strategies.
     
     Q: Should the TDD process for HW04 include the steps we took to use TDD for HW02?
     A: No.  Focus on what YOU need to do to implement HW05.  This is a planning exercise.
        The purpose of HW04 is to help you think through your path so you avoid coding all of HW05
        at once—and then spending a painful night(s) debugging.
     
     Q: Can we add explanation after "Test ##"?
     A: Yes.
     */

    /*
    int n = 011;  // n is 9 (= 8 + 1)
     */

    return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */

© Copyright 2021 Alexander J. Quinn         This content is protected and may not be shared, uploaded, or distributed.