tstConcentrationUnit.cpp

./Core/dc/tests/tstConcentrationUnit.cpp

#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include "Nemesis/gtest/nemesis_gtest.hh"
#include "Origen/Core/config.h"
using namespace Origen;
{
// first 4 for match
EXPECT_EQ( ABSORPTIONS, convertStringToConcUnit( "abso" ) );
EXPECT_EQ( AIRM_3, convertStringToConcUnit( "airm" ) );
EXPECT_EQ( APELEM, convertStringToConcUnit( "apel" ) );
EXPECT_EQ( ATOMS_B_CM, convertStringToConcUnit( "atom" ) );
EXPECT_EQ( BECQUERELS, convertStringToConcUnit( "becq" ) );
EXPECT_EQ( CURIES, convertStringToConcUnit( "curi" ) );
EXPECT_EQ( GAMWATTS, convertStringToConcUnit( "gamw" ) );
EXPECT_EQ( GATOMS, convertStringToConcUnit( "gato" ) );
EXPECT_EQ( GRAMS, convertStringToConcUnit( "gram" ) );
EXPECT_EQ( H2OM_3, convertStringToConcUnit( "h2om" ) );
EXPECT_EQ( KILOGRAMS, convertStringToConcUnit( "kilo" ) );
EXPECT_EQ( WPELEM, convertStringToConcUnit( "wpel" ) );
EXPECT_EQ( WATTS, convertStringToConcUnit( "watt" ) );
EXPECT_EQ( PARTICLES_SEC, convertStringToConcUnit( "part" ) );
EXPECT_EQ( PARTICLES_SEC_MEV, convertStringToConcUnit( "inte" ) );
EXPECT_EQ( ENERGY_SEC_MEV, convertStringToConcUnit( "ener" ) );
EXPECT_EQ( MOLES, convertStringToConcUnit( "mole" ) );
// accepts garbage after
EXPECT_EQ( ABSORPTIONS, convertStringToConcUnit( "absoasdf" ) );
EXPECT_EQ( AIRM_3, convertStringToConcUnit( "airmasdf" ) );
EXPECT_EQ( APELEM, convertStringToConcUnit( "apelasdf" ) );
EXPECT_EQ( ATOMS_B_CM, convertStringToConcUnit( "atomasdf" ) );
EXPECT_EQ( BECQUERELS, convertStringToConcUnit( "becqasdf" ) );
EXPECT_EQ( CURIES, convertStringToConcUnit( "curiasdf" ) );
EXPECT_EQ( GAMWATTS, convertStringToConcUnit( "gamwasdf" ) );
EXPECT_EQ( GATOMS, convertStringToConcUnit( "gatoasdf" ) );
EXPECT_EQ( GRAMS, convertStringToConcUnit( "gramasdf" ) );
EXPECT_EQ( H2OM_3, convertStringToConcUnit( "h2omasdf" ) );
EXPECT_EQ( KILOGRAMS, convertStringToConcUnit( "kiloasdf" ) );
EXPECT_EQ( WPELEM, convertStringToConcUnit( "wpelasdf" ) );
EXPECT_EQ( WATTS, convertStringToConcUnit( "wattasdf" ) );
EXPECT_EQ( PARTICLES_SEC, convertStringToConcUnit( "partasdf" ) );
EXPECT_EQ( PARTICLES_SEC_MEV, convertStringToConcUnit( "inteasdf" ) );
EXPECT_EQ( ENERGY_SEC_MEV, convertStringToConcUnit( "enerasdf" ) );
EXPECT_EQ( MOLES, convertStringToConcUnit( "moleasdf" ) );
}
TEST( ConcentrationUnit, IntConversion )
{
// conversion to ints
EXPECT_EQ( (int)GATOMS, unitAsInt( GATOMS ) );
EXPECT_EQ( (int)ATOMS_B_CM, unitAsInt( ATOMS_B_CM ) );
EXPECT_EQ( (int)GRAMS, unitAsInt( GRAMS ) );
EXPECT_EQ( (int)CURIES, unitAsInt( CURIES ) );
// conversion from ints (stored on files)
EXPECT_EQ( GATOMS, intAsUnit( 0 ) );
EXPECT_EQ( ATOMS_B_CM, intAsUnit( 1 ) );
EXPECT_EQ( GRAMS, intAsUnit( 2 ) );
EXPECT_EQ( CURIES, intAsUnit( 3 ) );
// check that we don't pull something for the other ones
for( int u = -1; u < LAST_CONCENTRATION_UNIT; ++u )
{
if( u >= 0 && u <= 3 ) continue;
EXPECT_ANY_THROW( intAsUnit( u ) ) << "u=" << u;
}
// check that we don't pull something for the other ones
for( int u = -1; u < LAST_CONCENTRATION_UNIT; ++u )
{
if( u >= 0 && u <= 3 ) continue;
EXPECT_ANY_THROW( unitAsInt( static_cast<ConcentrationUnit>( u ) ) )
<< "u=" << u;
}
}
{
for( int u = 0; u < LAST_CONCENTRATION_UNIT; ++u )
{
EXPECT_NE(
"",
convertConcUnitToString( static_cast<ConcentrationUnit>( u ) ) );
}
}
{
for( int u = 0; u < LAST_CONCENTRATION_UNIT; ++u )
{
EXPECT_NE( "",
static_cast<ConcentrationUnit>( u ) ) );
}
}
TEST( ConcentrationUnit, Categories )
{
// check unit categories
for( int u = 0; u < LAST_CONCENTRATION_UNIT; ++u )
{
ConcentrationUnit unit = static_cast<ConcentrationUnit>( u );
EXPECT_TRUE( isMassUnit( unit ) || isNumberUnit( unit ) ||
isDecayUnit( unit ) || isSpectrumUnit( unit ) ||
isReactionUnit( unit ) )
}
}
TEST( ConcentrationUnit, VolumeConversions )
{
// check volumetric units
for( int u = 0; u < LAST_CONCENTRATION_UNIT; ++u )
{
ConcentrationUnit unit = static_cast<ConcentrationUnit>( u );
// is volumetric
if( unit == GPERCM_3 || unit == ATOMS_B_CM )
{
EXPECT_TRUE( isVolumetric( unit ) );
}
// not a volumetric unit
else
{
EXPECT_FALSE( isVolumetric( unit ) );
}
}
// check needing volume to convert (if both are volumetric or not then
// don't need volume)
for( int u = 0; u < LAST_CONCENTRATION_UNIT; ++u )
{
ConcentrationUnit unit = static_cast<ConcentrationUnit>( u );
for( int v = 0; v < LAST_CONCENTRATION_UNIT; ++v )
{
ConcentrationUnit unitv = static_cast<ConcentrationUnit>( v );
if( ( isVolumetric( unitv ) && !isVolumetric( unit ) ) ||
( isVolumetric( unit ) && !isVolumetric( unitv ) ) )
{
EXPECT_TRUE( needsVolumeToConvert( unit, unitv ) );
}
else
{
EXPECT_FALSE( needsVolumeToConvert( unit, unitv ) );
}
}
}
}