Newer
Older
#ifndef MANTID_SUPPORTTEST_H_
#define MANTID_SUPPORTTEST_H_
#include <cxxtest/TestSuite.h>
Janik Zikovsky
committed
#include "MantidKernel/Strings.h"
Janik Zikovsky
committed
using namespace Mantid::Kernel::Strings;
Janik Zikovsky
committed
/**
Janik Zikovsky
committed
\class StringsTest
\brief test of Strings components
\date September 2005
\author S.Ansell
Janik Zikovsky
committed
Checks the basic string operations in Strings
Janik Zikovsky
committed
class StringsTest : public CxxTest::TestSuite
{
public:
void testExtractWord()
Janik Zikovsky
committed
/**
Applies a test to the extractWord
The object is to find a suitable lenght
of a string in a group of words
Janik Zikovsky
committed
@retval -1 :: failed find word in string
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
when the pattern exists.
*/
{
std::string Ln="Name wav wavelength other stuff";
int retVal=extractWord(Ln,"wavelengt",4);
TS_ASSERT_EQUALS(Ln, "Name wav other stuff");
}
void testConvert()
{
int i;
//valid double convert
TS_ASSERT_EQUALS(convert(" 568 ",i), 1);
TS_ASSERT_EQUALS(i,568);
double X;
//valid double convert
TS_ASSERT_EQUALS(convert(" 3.4 ",X), 1);
TS_ASSERT_EQUALS(X,3.4);
X=9.0;
//invalid leading stuff
TS_ASSERT_EQUALS(convert(" e3.4 ",X),0);
TS_ASSERT_EQUALS(X,9.0);
//invalid trailing stuff
TS_ASSERT_EQUALS(convert(" 3.4g ",X),0);
TS_ASSERT_EQUALS(X,9.0);
std::string Y;
TS_ASSERT_EQUALS(convert(" 3.4y ",Y),1);
TS_ASSERT_EQUALS(Y,"3.4y");
}
void testSection()
{
std::string Mline="V 1 tth ";
std::string Y;
TS_ASSERT_EQUALS(section(Mline,Y),1);
TS_ASSERT_EQUALS(Y,"V");
TS_ASSERT_EQUALS(Mline," 1 tth "); // Note the non-remove spc
}
void testSectPartNum()
{
double X;
std::string NTest=" 3.4 ";
TS_ASSERT_EQUALS(sectPartNum(NTest,X),1);
TS_ASSERT_EQUALS(X,3.4);
X=9.0;
NTest=" 3.4g ";
TS_ASSERT_EQUALS(sectPartNum(NTest,X),1);
TS_ASSERT_EQUALS(X,3.4);
X=9.0;
NTest=" e3.4 ";
TS_ASSERT_DIFFERS(sectPartNum(NTest,X),1);
TS_ASSERT_EQUALS(X,9.0);
}
Janik Zikovsky
committed
void test_Join()
{
std::vector<std::string> v;
v.push_back("Help");
v.push_back("Me");
v.push_back("I'm");
v.push_back("Stuck");
v.push_back("Inside");
v.push_back("A");
v.push_back("Test");
std::string out = join(v.begin(), v.end(), ",");
TS_ASSERT_EQUALS( out, "Help,Me,I'm,Stuck,Inside,A,Test");
}
};
#endif //MANTID_SUPPORTTEST_H_