Difference between revisions of "CPP/Debugging/Assert"
From ProgrammingExamples
< CPP
FirstPerson (Talk | contribs) (→Assert.cpp) |
FirstPerson (Talk | contribs) (→Assert.cpp) |
||
Line 5: | Line 5: | ||
#include <cassert> | #include <cassert> | ||
#include <string> | #include <string> | ||
+ | #include <cmath> | ||
using namespace std; | using namespace std; | ||
− | + | float Sqrt(float n){ | |
− | assert( | + | assert(n >= 0); |
+ | return sqrt(n); | ||
} | } | ||
int main(){ | int main(){ | ||
− | + | Sqrt(16); //pass | |
− | + | Sqrt(-16); //fail | |
− | + | ||
− | + | ||
− | + | ||
return 0; | return 0; |
Revision as of 07:58, 30 June 2010
Assert.cpp
#include <iostream> #include <cassert> #include <string> #include <cmath> using namespace std; float Sqrt(float n){ assert(n >= 0); return sqrt(n); } int main(){ Sqrt(16); //pass Sqrt(-16); //fail return 0; }