add units
This commit is contained in:
@@ -13,6 +13,7 @@ set(TESTS
|
||||
VoxImageCopyTest
|
||||
TriangleMeshTest
|
||||
BitCodeTest
|
||||
UnitsTest
|
||||
)
|
||||
|
||||
set(LIBRARIES
|
||||
|
||||
@@ -14,7 +14,9 @@ TESTS = MathVectorTest \
|
||||
PolicyTest \
|
||||
AccumulatorTest \
|
||||
VoxImageCopyTest \
|
||||
TriangleMeshTest
|
||||
TriangleMeshTest \
|
||||
BitCodeTest \
|
||||
UnitsTest
|
||||
|
||||
# else
|
||||
# TEST =
|
||||
|
||||
71
src/Math/testing/UnitsTest.cpp
Normal file
71
src/Math/testing/UnitsTest.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
#include "testing-prototype.h"
|
||||
#include "Math/Units.h"
|
||||
#include <cmath>
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
int main()
|
||||
{
|
||||
BEGIN_TESTING(Math Units);
|
||||
|
||||
// Length
|
||||
TEST0(1.0_m != 1000.0);
|
||||
TEST0(1_m != 1000.0);
|
||||
TEST0(1.0_cm != 10.0);
|
||||
TEST0(1_cm != 10.0);
|
||||
TEST0(1.0_mm != 1.0);
|
||||
TEST0(1_mm != 1.0);
|
||||
TEST0(1.0_km != 1000000.0);
|
||||
TEST0(1_km != 1000000.0);
|
||||
TEST0(std::abs(1.0_um - 1e-3) > 1e-12);
|
||||
TEST0(std::abs(1.0_nm - 1e-6) > 1e-15);
|
||||
|
||||
// Angle
|
||||
TEST0(std::abs(180.0_deg - M_PI) > 1e-9);
|
||||
TEST0(std::abs(180_deg - M_PI) > 1e-9);
|
||||
TEST0(std::abs(1.0_rad - 1.0) > 1e-9);
|
||||
|
||||
// Time
|
||||
TEST0(1.0_s != 1e9);
|
||||
TEST0(1_s != 1e9);
|
||||
TEST0(1.0_ms != 1e6);
|
||||
TEST0(1_ms != 1e6);
|
||||
TEST0(1.0_ns != 1.0);
|
||||
TEST0(1_ns != 1.0);
|
||||
|
||||
// Energy
|
||||
TEST0(1.0_MeV != 1.0);
|
||||
TEST0(1_MeV != 1.0);
|
||||
TEST0(1.0_GeV != 1000.0);
|
||||
TEST0(1_GeV != 1000.0);
|
||||
TEST0(1.0_TeV != 1000000.0);
|
||||
TEST0(1.0_keV != 1e-3);
|
||||
TEST0(1.0_eV != 1e-6);
|
||||
|
||||
END_TESTING;
|
||||
}
|
||||
Reference in New Issue
Block a user