1
2 /*********************************************************
3 * Soothsayer, an extensible predictive text entry system
4 * ------------------------------------------------------
5 *
6 * Copyright (C) 2008 Matteo Vescovi <matteo.vescovi@yahoo.co.uk>
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 **********(*)*/
23
24 #include "testStringSuite.h"
25
26 #include <iostream>
27 #include <assert.h>
28
29 ////
30 // TestString
TestString(std::string str,std::vector<std::string> tokens)31 TestStringSuite::TestString::TestString(
32 std::string str,
33 std::vector<std::string> tokens )
34 : m_string (str),
35 m_tokens (tokens)
36 {}
37
~TestString()38 TestStringSuite::TestString::~TestString()
39 {}
40
getstr() const41 const std::string TestStringSuite::TestString::getstr() const
42 {
43 // DEBUG
44 //std::cerr << "TestString::str() called" << std::endl;
45 //std::cerr << "Returning string: " << m_string << std::endl;
46 return m_string;
47 }
48
tokencount() const49 const int TestStringSuite::TestString::tokencount() const
50 {
51 return m_tokens.size();
52 }
53
token(const size_t index) const54 const std::string TestStringSuite::TestString::token(const size_t index) const
55 {
56 assert(index < m_tokens.size());
57 return m_tokens[index];
58 }
59
60 ////
61 // TestStringSuite
TestStringSuite()62 TestStringSuite::TestStringSuite()
63 {
64 std::string str;
65 std::vector<std::string> tokens;
66
67 str = "foo bar. Foo, bar! Foo bar... Foobar";
68 tokens.push_back("foo");
69 tokens.push_back("bar");
70 tokens.push_back("Foo");
71 tokens.push_back("bar");
72 tokens.push_back("Foo");
73 tokens.push_back("bar");
74 tokens.push_back("Foobar");
75 testStrings.push_back(new TestString(str, tokens));
76
77 tokens.clear();
78 str = "foo bar. Foo!!";
79 tokens.push_back("foo");
80 tokens.push_back("bar");
81 tokens.push_back("Foo");
82 tokens.push_back("");
83 testStrings.push_back(new TestString(str, tokens));
84
85 tokens.clear();
86 str = "FoO.\n \nBaR. fOoBaR\n.";
87 tokens.push_back("FoO");
88 tokens.push_back("BaR");
89 tokens.push_back("fOoBaR");
90 tokens.push_back("");
91 testStrings.push_back(new TestString(str, tokens));
92
93 tokens.clear();
94 str = "foo bar foobar ";
95 tokens.push_back("foo");
96 tokens.push_back("bar");
97 tokens.push_back("foobar");
98 tokens.push_back("");
99 testStrings.push_back(new TestString(str, tokens));
100
101 tokens.clear();
102 str = "frobnik ";
103 tokens.push_back("frobnik");
104 tokens.push_back("");
105 testStrings.push_back(new TestString(str, tokens));
106
107 //// REVISIT:
108 // These two following strings will cause tests to fail due to the
109 // blankspace at the beginning whitespace.
110 // Need to fix ReverseTokenizer!
111 //
112 // tokens.clear();
113 // str = " foo bar foobar";
114 // tokens.push_back("foo");
115 // tokens.push_back("bar");
116 // tokens.push_back("foobar");
117 // testStrings.push_back(new TestString(str, tokens));
118 //
119 // tokens.clear();
120 // str = " foo bar foobar ";
121 // tokens.push_back("foo");
122 // tokens.push_back("bar");
123 // tokens.push_back("foobar");
124 // tokens.push_back("");
125 // testStrings.push_back(new TestString(str, tokens));
126 ////
127
128 // DEBUG
129 //std::cerr << "TestStringSuite::TestStringSuite()" << std::endl;
130 //for (std::vector<TestString*>::iterator it = testStrings.begin();
131 // it != testStrings.end();
132 // it++) {
133 // std::cerr << (*it)->getstr() << std::endl;
134 //}
135
136 iter = testStrings.begin();
137 }
138
139
~TestStringSuite()140 TestStringSuite::~TestStringSuite()
141 {
142 for (iter = testStrings.begin();
143 iter != testStrings.end();
144 iter++) {
145 delete *iter;
146 }
147 }
148
hasMoreTestStrings() const149 bool TestStringSuite::hasMoreTestStrings() const
150 {
151 return ( iter == testStrings.end() ? false : true );
152 }
153
nextTestString()154 TestStringSuite::TestString* TestStringSuite::nextTestString()
155 {
156 return *(iter++);
157 }
158
currentTestString()159 TestStringSuite::TestString* TestStringSuite::currentTestString()
160 {
161 // DEBUG
162 //std::cerr << "Entered currentTestString()" << std::endl;
163 //std::cerr << "Returning pointer: " << *iter << std::endl;
164 return *iter;
165 }
166