, " " . , n.
#include <limits>
#include <cassert>
bool IsAnInteger(int)
{
return true;
}
int main()
{
assert(IsAnInteger(std::numeric_limits<int>::min()));
assert(IsAnInteger(0));
assert(IsAnInteger(1));
}
Hold on!
for actual code, the parameter is not even an integer
What is it?
#include <cassert>
template <class T>
bool IsAnInteger(const T&)
{
return true;
}
int main()
{
assert(IsAnInteger(0));
assert(IsAnInteger("I am not a number!"));
assert(IsAnInteger(42.0f));
}
Your function has 100% test coverage, and your unit tests accurately document how it behaves. In TDD, you just need to write enough code for your unit tests to pass. You are done with this and can move on.
source
share