Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-05-17 03:00:12

0001 #include <iomanip>
0002 
0003 #include <cppunit/extensions/HelperMacros.h>
0004 
0005 #include "DataFormats/Math/interface/GeantUnits.h"
0006 #include "CLHEP/Units/GlobalSystemOfUnits.h"
0007 #include "CLHEP/Units/SystemOfUnits.h"
0008 
0009 #include "cppunit/TestAssert.h"
0010 #include "cppunit/TestFixture.h"
0011 
0012 using namespace geant_units;
0013 using namespace geant_units::operators;
0014 using namespace std;
0015 
0016 class testDDUnits : public CppUnit::TestFixture {
0017   CPPUNIT_TEST_SUITE(testDDUnits);
0018   CPPUNIT_TEST(checkUnits);
0019   CPPUNIT_TEST_SUITE_END();
0020 
0021 public:
0022   void setUp() override {}
0023   void tearDown() override {}
0024   void checkUnits();
0025 };
0026 
0027 CPPUNIT_TEST_SUITE_REGISTRATION(testDDUnits);
0028 
0029 void testDDUnits::checkUnits() {
0030   std::cout << "\nMy pi: " << std::setprecision(16) << piRadians << " == " << 1_pi << " == " << 1._pi << "\n";
0031 
0032   CPPUNIT_ASSERT(M_PI == piRadians);
0033   CPPUNIT_ASSERT(M_PI == 1_pi);
0034   CPPUNIT_ASSERT(M_PI == 1._pi);
0035 
0036   double twoPiAngle = 2_pi;
0037   std::cout << "My 2pi angle: " << twoPiAngle << " [rad] == " << convertRadToDeg(twoPiAngle) << " [deg]\n";
0038 
0039   CPPUNIT_ASSERT(2 * M_PI == 2 * piRadians);
0040   CPPUNIT_ASSERT(2 * M_PI == twoPiAngle);
0041   CPPUNIT_ASSERT(2 * M_PI == 2_pi);
0042   CPPUNIT_ASSERT(2 * M_PI == 2._pi);
0043 
0044   CPPUNIT_ASSERT(90_deg == 1_pi / 2);
0045   CPPUNIT_ASSERT(120_deg == 2_pi / 3);
0046   CPPUNIT_ASSERT(135_deg == 3_pi / 4);
0047   CPPUNIT_ASSERT(150_deg == 5_pi / 6);
0048 
0049   double angle90 = convertRadToDeg(1_pi / 2);
0050   CPPUNIT_ASSERT(angle90 == 90);
0051 
0052   double angle120 = convertRadToDeg(2_pi / 3);
0053   CPPUNIT_ASSERT(almostEqual(angle120, 120., 2));
0054 
0055   double angle135 = convertRadToDeg(3_pi / 4);
0056   CPPUNIT_ASSERT(almostEqual(angle135, 135., 2));
0057 
0058   double angle150 = convertRadToDeg(5_pi / 6);
0059   CPPUNIT_ASSERT(almostEqual(angle150, 150., 2));
0060 
0061   cout << "Mass of 1 kg is " << 1._kg << " or " << 1 * CLHEP::kg << "\n";
0062   cout << "Mass of 1  g is " << 1._g << " or " << 1 * CLHEP::g << "\n";
0063   cout << "Ratio of 1._kg / CLHEP::kg is " << 1._kg / (1 * CLHEP::kg) << endl;
0064   cout << "Difference of 1._kg - CLHEP::kg is " << std::abs(1._kg - (1 * CLHEP::kg)) << endl;
0065   cout << "Ratio of 1._g / CLHEP::g is " << 1._g / (1 * CLHEP::g) << endl;
0066   cout << "Difference of 1._g - CLHEP::g is " << std::abs(1._g - (1 * CLHEP::g)) << endl;
0067 }