CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

testUnits.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 // $Id: testUnits.cc,v 1.4 2011/07/20 23:00:04 garren Exp $
3 // ---------------------------------------------------------------------------
4 //
5 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
6 //
7 // This is a small program for testing the Units module
8 //
9 
10 #include <assert.h>
11 #include "CLHEP/Units/defs.h"
12 #include "CLHEP/Units/PhysicalConstants.h"
13 #include <iostream>
14 #include <iomanip>
15 #include <sstream>
16 #include <cmath>
17 
18 int main() {
19 
20  int nbad=0;
21 
22  // Check that local m does not interfere with global m
23 
24  double m=0;
25  for (int i=0; i<7; i++, m++) { assert(m == double(i)); }
26  assert(m != CLHEP::meter);
27 
28  //std::cout << "Speed of light is " << std::setw(10) << std::setprecision(8)
29  // << CLHEP::c_light << std::endl;
30  //output: Speed of light is 299.79246
31 
32  std::ostringstream os1, os2, os3, os4;
33  os1 << std::setprecision(8) << CLHEP::c_light;
34  os2 << "299.79246";
35  if( os1.str() != os2.str() ) {
36  std::cout << "compare --" << os1.str() << "-- to --" << os2.str() << "--" << std::endl;
37  nbad++;
38  }
39  os3 << std::setprecision(16) << CLHEP::pi ;
40  os4 << "3.141592653589793";
41  if( os3.str() != os4.str() ) {
42  nbad++;
43  std::cout << "compare --" << os3.str() << "--" << std::endl;
44  std::cout << " to --" << os4.str() << "--" << std::endl;
45 #ifndef USING_VISUAL
46  std::cout << "M_PI --" << std::setprecision(16) << M_PI << "--" << std::endl;
47 #endif
48  }
49 
50  return nbad;
51 
52 }