mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#2560 Unit conversion : Add conversion based on parsing unit text string
This commit is contained in:
@@ -38,6 +38,8 @@ ${CMAKE_CURRENT_LIST_DIR}/RiaProjectFileVersionTools-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifElementPropertyTableReader-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimRelocatePath-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RigTransmissibilityCondenser-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RigTransmissibilityCondenser-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaEclipseUnitTools-Test
|
||||
)
|
||||
|
||||
list(APPEND CODE_HEADER_FILES
|
||||
|
||||
76
ApplicationCode/UnitTests/RiaEclipseUnitTools-Test.cpp
Normal file
76
ApplicationCode/UnitTests/RiaEclipseUnitTools-Test.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "RiaEclipseUnitTools.h"
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RiaEclipseUnitTools, TestConversionToMeter)
|
||||
{
|
||||
double deltaRange = 1e-7;
|
||||
|
||||
{
|
||||
double sourceValue = RiaEclipseUnitTools::feetPerMeter();
|
||||
QString unitText = "ft";
|
||||
double destValue = RiaEclipseUnitTools::convertToMeter(sourceValue, unitText);
|
||||
EXPECT_NEAR(1.0, destValue, deltaRange);
|
||||
}
|
||||
|
||||
{
|
||||
double sourceValue = RiaEclipseUnitTools::feetPerMeter() * 12.0;
|
||||
QString unitText = "in";
|
||||
double destValue = RiaEclipseUnitTools::convertToMeter(sourceValue, unitText);
|
||||
EXPECT_NEAR(1.0, destValue, deltaRange);
|
||||
}
|
||||
|
||||
{
|
||||
double sourceValue = 1.0;
|
||||
QString unitText = "m";
|
||||
double destValue = RiaEclipseUnitTools::convertToMeter(sourceValue, unitText);
|
||||
EXPECT_NEAR(1.0, destValue, deltaRange);
|
||||
}
|
||||
|
||||
{
|
||||
double sourceValue = 100.0;
|
||||
QString unitText = "cm";
|
||||
double destValue = RiaEclipseUnitTools::convertToMeter(sourceValue, unitText);
|
||||
EXPECT_NEAR(1.0, destValue, deltaRange);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RiaEclipseUnitTools, TestConversionToFeet)
|
||||
{
|
||||
double deltaRange = 1e-7;
|
||||
|
||||
{
|
||||
double sourceValue = 1.0;
|
||||
QString unitText = "ft";
|
||||
double destValue = RiaEclipseUnitTools::convertToFeet(sourceValue, unitText);
|
||||
EXPECT_NEAR(1.0, destValue, deltaRange);
|
||||
}
|
||||
|
||||
{
|
||||
double sourceValue = 1.0 * 12.0;
|
||||
QString unitText = "in";
|
||||
double destValue = RiaEclipseUnitTools::convertToFeet(sourceValue, unitText);
|
||||
EXPECT_NEAR(1.0, destValue, deltaRange);
|
||||
}
|
||||
|
||||
{
|
||||
double sourceValue = RiaEclipseUnitTools::meterPerFeet();
|
||||
QString unitText = "m";
|
||||
double destValue = RiaEclipseUnitTools::convertToFeet(sourceValue, unitText);
|
||||
EXPECT_NEAR(1.0, destValue, deltaRange);
|
||||
}
|
||||
|
||||
{
|
||||
double sourceValue = RiaEclipseUnitTools::meterPerFeet() * 100.0;
|
||||
QString unitText = "cm";
|
||||
double destValue = RiaEclipseUnitTools::convertToFeet(sourceValue, unitText);
|
||||
EXPECT_NEAR(1.0, destValue, deltaRange);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user