00001
00012 #include <sstream>
00013
00014 #include "PosCasoPrueba.hpp"
00015 #include "Elias.hpp"
00016 #include "Pos.hpp"
00017
00018 CPPUNIT_TEST_SUITE_REGISTRATION(PosCasoPrueba);
00019
00020
00021 string posAstringYBorra(set<Pos> *n)
00022 {
00023 ASSERT(n!=NULL);
00024 std::stringstream sso;
00025 sso << *n;
00026 delete n;
00027
00028 return sso.str();
00029 }
00030
00031
00036 string numC(long n)
00037 {
00038 std::stringstream ss;
00039 escribe_elias_gama(ss, (unsigned int)n);
00040 return ss.str();
00041 }
00042
00043
00047 unsigned long cNum(string s)
00048 {
00049 std::stringstream ss;
00050 ss.str(s);
00051 unsigned long n = lee_elias_gama(ss);
00052 return n;
00053 }
00054
00055
00056 void PosCasoPrueba::prueba_escribePos()
00057 {
00058 std::stringstream ss;
00059 ss.clear();
00060 escribePos(ss, NULL);
00061 CPPUNIT_ASSERT(ss.str() == "}");
00062
00063 set<Pos> cp;
00064 ss.clear();
00065 ss.str("");
00066 escribePos(ss, &cp);
00067 CPPUNIT_ASSERT(ss.str() == "}");
00068
00069 cp.insert(Pos(2,1));
00070 ss.clear();
00071 ss.str("");
00072 escribePos(ss, &cp);
00073 CPPUNIT_ASSERT(ss.str() == numC(2) + numC(1) + "}");
00074
00075 cp.insert(Pos(2,2));
00076 ss.clear();
00077 ss.str("");
00078 escribePos(ss, &cp);
00079
00080 CPPUNIT_ASSERT(ss.str() == numC(2) + numC(1) + numC(1) + "}");
00081 cp.insert(Pos(1,2));
00082 ss.clear();
00083 ss.str("");
00084 escribePos(ss, &cp);
00085
00086 CPPUNIT_ASSERT(ss.str() == numC(1) + numC(2) + "(" + numC(2) + numC(1)
00087 + numC(1) + "}");
00088 cp.insert(Pos(1,5));
00089 ss.clear();
00090 ss.str("");
00091 escribePos(ss, &cp);
00092
00093 CPPUNIT_ASSERT(ss.str() == numC(1) + numC(2) + numC(3) + "(" +
00094 numC(2) + numC(1) + numC(1) + "}");
00095
00096
00097
00098
00099 }
00100
00101 void PosCasoPrueba::prueba_longPos()
00102 {
00103 long r = longPos(NULL);
00104
00105 CPPUNIT_ASSERT(r == 1);
00106
00107 set<Pos> cp;
00108 r = longPos(&cp);
00109
00110 CPPUNIT_ASSERT(r == 1);
00111
00112 cp.insert(Pos(2,1));
00113 r = longPos(&cp);
00114
00115 CPPUNIT_ASSERT(r == 3);
00116
00117 cp.insert(Pos(2,2));
00118 r = longPos(&cp);
00119
00120 CPPUNIT_ASSERT(r == 4);
00121
00122 cp.insert(Pos(1,2));
00123 r = longPos(&cp);
00124
00125 CPPUNIT_ASSERT(r == 7);
00126
00127 cp.insert(Pos(1,5));
00128 r = longPos(&cp);
00129
00130 CPPUNIT_ASSERT(r == 8);
00131
00132
00133
00134 }
00135
00136
00137 void PosCasoPrueba::prueba_leePos()
00138 {
00139 std::stringstream ss;
00140 ss.clear();
00141 ss << "";
00142 CPPUNIT_ASSERT_THROW(leePos(ss), std::string);
00143 ss.str("");
00144 ss.clear();
00145 ss << "adsfa";
00146 CPPUNIT_ASSERT_THROW(leePos(ss), std::string);
00147 ss.str("");
00148 ss.clear();
00149 ss << "{}";
00150 CPPUNIT_ASSERT_THROW(leePos(ss), std::string);
00151 ss.str("");
00152 ss.clear();
00153 ss << "}";
00154 CPPUNIT_ASSERT(posAstringYBorra(leePos(ss)) == "{}");
00155 ss.str("");
00156 ss.clear();
00157 ss << "(}";
00158 CPPUNIT_ASSERT_THROW(leePos(ss), std::string);
00159 ss.str("");
00160 ss.clear();
00161 ss << numC(1) << numC(1) << "(}";
00162 CPPUNIT_ASSERT_THROW(leePos(ss), std::string);
00163 ss.str("");
00164 ss.clear();
00165 ss << numC(1) << numC(1) << "}";
00166
00167 string r = posAstringYBorra(leePos(ss));
00168
00169 CPPUNIT_ASSERT(r == "{(1,1)}");
00170
00171 ss.str("");
00172 ss.clear();
00173 ss << numC(1) << numC(1) << ";}";
00174
00175 CPPUNIT_ASSERT_THROW(leePos(ss), std::string);
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185 set<Pos> cp;
00186 cp.insert(Pos(1,2));
00187 cp.insert(Pos(1,1));
00188 ss.str("");
00189 ss.clear();
00190 escribePos(ss, &cp);
00191
00192 CPPUNIT_ASSERT(posAstringYBorra(leePos(ss)) == "{(1,1), (1,2)}");
00193 cp.clear();
00194 cp.insert(Pos(2,1));
00195 cp.insert(Pos(1,2));
00196 ss.str("");
00197 ss.clear();
00198 escribePos(ss, &cp);
00199 CPPUNIT_ASSERT(posAstringYBorra(leePos(ss)) == "{(1,2), (2,1)}");
00200
00201
00202 vector<long> renum;
00203 renum.push_back(-1);
00204 cp.clear();
00205 cp.insert(Pos(1,2));
00206 cp.insert(Pos(1,1));
00207 ss.clear();
00208 ss.str("");
00209 ss.clear();
00210 ss.seekp(-1);
00211 ss.seekg(0);
00212 ss.clear();
00213 escribePos(ss, &cp);
00214
00215 string sr = posAstringYBorra(leePos(ss, &renum));
00216
00217 CPPUNIT_ASSERT( sr == "{}");
00218 cp.clear();
00219 renum.push_back(0);
00220 cp.insert(Pos(1,1));
00221 cp.insert(Pos(2,1));
00222 ss.str("");
00223 ss.clear();
00224 escribePos(ss, &cp);
00225 CPPUNIT_ASSERT(posAstringYBorra(leePos(ss, &renum)) == "{(1,1)}");
00226
00227 }
00228
00229
00230 void PosCasoPrueba::prueba_copiaPos()
00231 {
00232 std::stringstream ss;
00233 ss.clear();
00234 set<Pos> cp;
00235 cp.insert(Pos(2,1));
00236 set<Pos> *cp2 = copiaPos(cp, NULL);
00237
00238 CPPUNIT_ASSERT(cp2->size() == 1);
00239 string r = posAstringYBorra(cp2);
00240
00241 CPPUNIT_ASSERT(r == "{(2,1)}");
00242
00243 cp.insert(Pos(2,2));
00244 cp2 = copiaPos(cp, NULL);
00245 CPPUNIT_ASSERT(cp2->size() == 2);
00246 r = posAstringYBorra(cp2);
00247
00248 CPPUNIT_ASSERT(r == "{(2,1), (2,2)}");
00249
00250 cp.insert(Pos(1,2));
00251 cp2 = copiaPos(cp, NULL);
00252 CPPUNIT_ASSERT(cp2->size() == 3);
00253 r = posAstringYBorra(cp2);
00254
00255 CPPUNIT_ASSERT(r == "{(1,2), (2,1), (2,2)}");
00256
00257 cp.insert(Pos(1,5));
00258 cp2 = copiaPos(cp, NULL);
00259 CPPUNIT_ASSERT(cp2->size() == 4);
00260 r = posAstringYBorra(cp2);
00261
00262 CPPUNIT_ASSERT(r == "{(1,2), (1,5), (2,1), (2,2)}");
00263
00264 vector<long> renum;
00265 renum.push_back(1);
00266 renum.push_back(0);
00267 cp2 = copiaPos(cp, &renum);
00268 CPPUNIT_ASSERT(cp2->size() == 4);
00269 r = posAstringYBorra(cp2);
00270
00271 CPPUNIT_ASSERT(r == "{(1,1), (1,2), (2,2), (2,5)}");
00272
00273 renum.clear();
00274 renum.push_back(-1);
00275 renum.push_back(0);
00276 cp2 = copiaPos(cp, &renum);
00277 CPPUNIT_ASSERT(cp2->size() == 2);
00278 r = posAstringYBorra(cp2);
00279
00280 CPPUNIT_ASSERT(r == "{(1,1), (1,2)}");
00281
00282
00283 }
00284
00285
00286 void PosCasoPrueba::setUp()
00287 {
00288 return;
00289 }