Beispiel #1
0
int main(int /*argc*/, char** /*argv*/) {

  //Create UtilsForTesting object
  UtilsForTesting u;

  //Try out the new sumVectorsAndThenDivide function

  //First, read in some vectors from the file Vectors.input

  OptionParser p(ReadFileIntoString("Vectors.input"));
  MyVector<double> A = p.Get<MyVector<double> >("FirstVectorToAdd");
  MyVector<double> B = p.Get<MyVector<double> >("SecondVectorToAdd");
  double divisor = p.Get<double>("Divisor",1.);
  
  //Next, make a vector to store the result

  MyVector<double> result(MV::Size(A.Size()),0.);
  
  //Test that the divisor is nonzero
  IS_TRUE(divisor != 0, "Divisor is zero");

  //REQUIRE the divisor to be nonzero
  //Commented out to verify that the IS_TRUE line above also causes the test 
  //to fail
  //REQUIRE(divisor != 0, "Divisor must be nonzero");

  //Do the computation
  
  result = sumVectorsAndThenDivide(A,B,divisor);

  //Print out the results
  
  std::cout << "Vector A = " << A << std::endl;
  std::cout << "Vector B = " << B << std::endl;
  std::cout << "(A+B)/divisor = " << result << std::endl;

  //Test that the result magnitude is zero
  double resultMagnitudeSq = 0.0;
  for(int i=0;i<result.Size();++i) {
    resultMagnitudeSq += result[i]*result[i];
  }

  IS_ZERO(resultMagnitudeSq,"Sum of vector and its negative nonzero.");

  //How many tests failed?
  std::cout << u.NumberOfTestsFailed() << " tests failed." << std::endl;

  //Return number of failed tests
  return u.NumberOfTestsFailed();
}
Beispiel #2
0
int main(int /*arc*/, char** /*argv*/) {
  
  double const PI = 3.1415926535897932;
  const MyVector<double> radii(MV::fill, 3.,4.,5.);
  double AnaVol = (4./3.)*PI*(radii[0]*radii[0]*radii[0] + \
                           radii[1]*radii[1]*radii[1] + \
                           radii[2]*radii[2]*radii[2]);
  double CalcVol = TotalVolumeOfSpheresFromRadii(radii);

  std::cout << "Analytical Volume Sum = " << AnaVol << std::endl;
  std::cout << "Calculated Volume Sum = " << CalcVol << std::endl;
  
  UtilsForTesting u;
  IS_TRUE(CalcVol-AnaVol<1.0e-10,"Error in TotalVolumeOfSpheresFromRadii!! Calculated Volume =/= real volume!! You stupid bitch!!");
             
  return u.NumberOfTestsFailed();
  //return EXIT_SUCCESS;
}
Beispiel #3
0
int main(int /*argc*/, char** /*argv*/) {
  UtilsForTesting u;
  //Try out the new sumVectors function                                         
 
  //First, create a couple of vectors, then add them together                   
/* 
  const MyVector<double> A(MV::fill, 3.,4.,5.);
  const MyVector<double> B(MV::fill, 6.,7.,8.);
*/
  OptionParser p(ReadFileIntoString("Vectors.input"));
  MyVector<double> A = p.Get<MyVector<double> >("FirstVectorToAdd");
  MyVector<double> B = p.Get<MyVector<double> >("SecondVectorToAdd");
  double divisor = p.Get<double>("Divisor",1.0);
  REQUIRE(divisor!=0.0, "Error: divisor set to zero");
  IS_TRUE(divisor!=0.0, "Error: divisor is equal to zero");

  //Next, make a vector to store the result                                     
 
  MyVector<double> result(MV::Size(A.Size()),0.);
 
  //Add the vectors together                                                    
 
  result = sumVectors(A,B,divisor);
 
  //Print out the results                                                       
 
  std::cout << "Vector A = " << A << std::endl;
  std::cout << "Vector B = " << B << std::endl;
  std::cout << "Sum      = " << result << std::endl;

  //Test that the result magnitude is zero                                      
  double resultMagnitudeSq = 0.0;
  for(int i=0;i<result.Size();++i) {
    resultMagnitudeSq += result[i]*result[i];
  }
  IS_ZERO(resultMagnitudeSq,"Sum of vector and its negative nonzero.");


  //Return success                                                              
  //return EXIT_SUCCESS;
  return u.NumberOfTestsFailed();
}
Beispiel #4
0
int main(int /*argc*/, char** /*argv*/) {

  //Try out the new sumVectors function                                         

  //First, create a couple of vectors, then add them together                   

  OptionParser p(ReadFileIntoString("Vectors.input"));
  MyVector<double> A = p.Get<MyVector<double> >("FirstVectorToAdd");
  MyVector<double> B = p.Get<MyVector<double> >("SecondVectorToAdd");
  const double C = p.Get<double>("DoubleToDivideBy");

  // Check that C isn't equal to 0
  UtilsForTesting u;
  IS_TRUE(C != 0.0, "ERROR: DoubleToDivideBy can't be 0.0"); 
  //REQUIRE(divisor != 0.0, "ERROR: DoubleToDivideBY can't be 0.0"); 

  //Next, make a vector to store the result                                     

  MyVector<double> result(MV::Size(A.Size()),0.);

  //Add the vectors together                                                    

  result = addDivideVectors(A,B,C);

  //Print out the results                                                       

  std::cout << "Vector A = " << A << std::endl;
  std::cout << "Vector B = " << B << std::endl;
  std::cout << "Result      = " << result << std::endl;

  double resultMagnitudeSq = 0.0;
  for(int i=0; i<result.Size(); ++i){
    resultMagnitudeSq += result[i]*result[i];
  }
  
  IS_ZERO(resultMagnitudeSq, "Sum of vector and its negative nonzero.");
 
  //Return success                                                              
  return u.NumberOfTestsFailed();
}
Beispiel #5
0
int main(int /*argc*/, char** /*argv*/) {
  //Try out the new sumVectors function                                         
 
  //First, create a couple of vectors, then add them together                   
  
  OptionParser p(ReadFileIntoString("Vectors.input"));
  
  MyVector <double> A = p.Get<MyVector<double> >("FirstVectorToAdd");
  MyVector <double> B = p.Get<MyVector<double> >("SecondVectorToAdd");

  //Next, make a vector to store the result                                     
 
  MyVector<double> result(MV::Size(A.Size()), 0.);
 
  //Test that the vectors are the same size                                    
  REQUIRE(A.Size() == B.Size(), "Error: vectors not the same size.\n");
  
  double d = p.Get<double>("Divider");
  UtilsForTesting u;
  IS_TRUE(d != 0,"The divider is zero.\n"); 
  //Add the vectors together                                                    
  result = sumVectorsDivided(A, B, d);
  //bug
  //result = A;
  double resultMagnitudeSq = 0.0;
  for(int i=0;i<result.Size();++i) {
    resultMagnitudeSq += result[i]*result[i];
  }
  //Test that the result magnitude is zero  
  IS_ZERO(resultMagnitudeSq, "The result magnitude is not zero\n"); 

  //Print out the results                                                       
 
  cout << "Vector A = " << A << endl;
  cout << "Vector B = " << B << endl;
  cout << "Sum divided by " << d << "  = " << result << endl;
                                      
  //Return success                                                              
  return u.NumberOfTestsFailed();
}