''Ogle this student code, to convert a number to base 36:'' #include #include using std::abs; using std::cout; using std::endl; using std::reverse; using std::string; char charTable[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; void printBase(int i, int base) { if ((abs(base) <= 1) || (abs(base) > 36) || (i == 0)) { cout << "0" << endl; return; } string str = ""; if ((base > 0) && (i < 0)) { str += "-"; i = -i; } do { if (i % base >= 0) { str += charTable[i % base]; i = i / base; } else { str += charTable[i % base - base]; i = i /base + 1; } } while(i); reverse(str.begin(), str.end()); cout << str << endl; } int main() { for(int i = -55; i <= 55; i++) { cout << i << " = "; printBase(i,-10); } } --manoj ''Suppose TestDrivenDevelopment generated it. Would TDD be sufficient to cover its branches?'' ''answers reposted from news:comp.lang.c++ without permission'' ''Would BranchTesting be inadequate for converting an integer to a string???'' Certainly inadequate as a testing discipline in general, and almost certainly inadequate for testing a function that converts an integer to a string. Whether it gives you adequate coverage in any particular case depends on the case. Applied to the original code it is inadequate. For example, branch analysis could be satisfied with test cases that only exercise the do loop exactly twice: once to branch back to the head of the loop and once to branch out of it. That doesn't test what happens when you need exactly one digit or three or more digits to represent the value. Of course, doing that one thoroughly requires path testing, which is known to be prohibitively expensive , although perhaps workable for this example. For another example, if the charTable had some incorrect values, a test suite based only on branch testing wouldn't necessarily find them. --PeteBecker At least insufficient. For example, branch testing would not detect the error which is in the original code when passing ''std::numeric_limits::min()'': the value range for integers is [normally] asymmetric and "i = -i" is the identity operation for the two values ''0'' and ''std::numeric_limits::min()'' (well, for the latter value the behavior may actually be undefined or implementation defined). That is, in addition to branch testing you need to perform at least some testing for CornerCase''''''s. --DietmarKuehl