Difference between revisions of "CPP/Debugging/Assert"

From ProgrammingExamples
< CPP
Jump to: navigation, search
(Assert.cpp)
(Assert.cpp)
Line 5: Line 5:
 
#include <cassert>
 
#include <cassert>
 
#include <string>
 
#include <string>
 +
#include <cmath>
  
 
using namespace std;
 
using namespace std;
  
void didPass(const string& password){
+
float Sqrt(float n){
  assert(password == "drama");
+
  assert(n >= 0);
 +
return sqrt(n);
 
}
 
}
 
int main(){
 
int main(){
  
   didPass("drama");
+
   Sqrt(16); //pass
    
+
   Sqrt(-16); //fail
  cout << "Test 1 passed\n";
+
 
+
  assert("DRunk");
+
 
   
 
   
 
   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;
}