mirror of
https://github.com/OPM/ResInsight.git
synced 2025-01-03 20:57:39 -06:00
4a61226926
Replace tabs in summary quantity name with space
60 lines
2.0 KiB
C++
60 lines
2.0 KiB
C++
#include "gtest/gtest.h"
|
|
|
|
#include "RiaStdStringTools.h"
|
|
|
|
#include <QLocale>
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
TEST( RiaStdStringToolsTest, ParseNumbers )
|
|
{
|
|
auto decimalPoint = QLocale::c().decimalPoint().toLatin1();
|
|
|
|
{
|
|
std::string text = "8.73705e+06";
|
|
|
|
EXPECT_TRUE( RiaStdStringTools::isNumber( text, decimalPoint ) );
|
|
}
|
|
|
|
{
|
|
std::string text = "-8.73705e-06";
|
|
|
|
EXPECT_TRUE( RiaStdStringTools::isNumber( text, decimalPoint ) );
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
TEST( RiaStdStringToolsTest, EditDistance )
|
|
{
|
|
// Equal string needs zero edits
|
|
EXPECT_EQ( 0, RiaStdStringTools::computeEditDistance( "same", "same" ) );
|
|
|
|
// Empty strings are also zero edits
|
|
EXPECT_EQ( 0, RiaStdStringTools::computeEditDistance( "", "" ) );
|
|
|
|
// Examples from wikipedia
|
|
EXPECT_EQ( 3, RiaStdStringTools::computeEditDistance( "kitten", "sitting" ) );
|
|
EXPECT_EQ( 3, RiaStdStringTools::computeEditDistance( "sitting", "kitten" ) );
|
|
EXPECT_EQ( 3, RiaStdStringTools::computeEditDistance( "Saturday", "Sunday" ) );
|
|
EXPECT_EQ( 3, RiaStdStringTools::computeEditDistance( "Sunday", "Saturday" ) );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
TEST( RiaStdStringToolsTest, TrimStrings )
|
|
{
|
|
// Test replace of tabs with space
|
|
{
|
|
std::string text = "test\t\tnext word";
|
|
|
|
replace( text.begin(), text.end(), '\t', ' ' );
|
|
|
|
std::string expectedText = "test next word";
|
|
EXPECT_EQ( text, expectedText );
|
|
}
|
|
}
|