Changeset 1044 for cpp/frams/_demos/simil_unittests.cpp
- Timestamp:
- 12/10/20 22:33:22 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/_demos/simil_unittests.cpp
r351 r1044 3 3 // See LICENSE.txt for details. 4 4 5 #include "frams/model/similarity/simil _match.h"5 #include "frams/model/similarity/simil-match.h" 6 6 7 7 /** Runs unit tests of classes used in computation of similarity. … … 42 42 for (i = 0; i < nSize1; i++) 43 43 { 44 assert(match1. IsMatched(j, i) == false);44 assert(match1.isMatched(j, i) == false); 45 45 } 46 46 } 47 47 48 48 // test if all are unmatched - new method 49 assert(match1. IsEmpty() == true);49 assert(match1.isEmpty() == true); 50 50 51 51 // check assymetric matching … … 55 55 for (i = 0; i < nSize1; i++) 56 56 { 57 assert(match2. IsMatched(0, i) == false);57 assert(match2.isMatched(0, i) == false); 58 58 } 59 59 // check if all elements are unmatched yet in object 1 60 60 for (i = 0; i < nSize2; i++) 61 61 { 62 assert(match2. IsMatched(1, i) == false);62 assert(match2.isMatched(1, i) == false); 63 63 } 64 64 65 65 // test if all are unmatched - new method 66 assert(match2. IsEmpty() == true);66 assert(match2.isEmpty() == true); 67 67 68 68 return 0; … … 89 89 90 90 // check size of both objects 91 assert(pMatching-> GetObjectSize(0) == i);92 assert(pMatching-> GetObjectSize(1) == j);91 assert(pMatching->getObjectSize(0) == i); 92 assert(pMatching->getObjectSize(1) == j); 93 93 94 94 // delete disused object … … 114 114 SimilMatching Source(iSize, iSize); 115 115 // check if it is empty 116 assert(Source. IsEmpty() == true);116 assert(Source.isEmpty() == true); 117 117 // check sizes of objects 118 assert(Source. GetObjectSize(0) == iSize);119 assert(Source. GetObjectSize(1) == iSize);118 assert(Source.getObjectSize(0) == iSize); 119 assert(Source.getObjectSize(1) == iSize); 120 120 // create a copy of this matching 121 121 SimilMatching Dest(Source); 122 122 // check the copy: 123 123 // - sizes of matched object 124 assert(Dest. GetObjectSize(0) == Source.GetObjectSize(0));125 assert(Dest. GetObjectSize(1) == Source.GetObjectSize(1));124 assert(Dest.getObjectSize(0) == Source.getObjectSize(0)); 125 assert(Dest.getObjectSize(1) == Source.getObjectSize(1)); 126 126 // - the copy should be empty, too 127 assert(Dest. IsEmpty() == true);127 assert(Dest.isEmpty() == true); 128 128 // make it empty once again 129 Dest. Empty();129 Dest.empty(); 130 130 // and check once more 131 assert(Dest. IsEmpty() == true);131 assert(Dest.isEmpty() == true); 132 132 } 133 133 … … 136 136 SimilMatching Source(iSize, iSize); 137 137 // check if it is empty 138 assert(Source. IsEmpty() == true);138 assert(Source.isEmpty() == true); 139 139 // check sizes of objects 140 assert(Source. GetObjectSize(0) == iSize);141 assert(Source. GetObjectSize(1) == iSize);140 assert(Source.getObjectSize(0) == iSize); 141 assert(Source.getObjectSize(1) == iSize); 142 142 // match objects (iObj, iObj) 143 143 for (iObj = 0; iObj < iSize; iObj++) 144 144 { 145 Source. Match(0, iObj, 1, iObj);145 Source.match(0, iObj, 1, iObj); 146 146 } 147 147 // check if the matching is full 148 assert(Source. IsFull() == true);148 assert(Source.isFull() == true); 149 149 // now create a copy of the matching 150 150 SimilMatching Dest(Source); 151 151 // check the copy 152 152 // - sizes of matched object 153 assert(Dest. GetObjectSize(0) == Source.GetObjectSize(0));154 assert(Dest. GetObjectSize(1) == Source.GetObjectSize(1));153 assert(Dest.getObjectSize(0) == Source.getObjectSize(0)); 154 assert(Dest.getObjectSize(1) == Source.getObjectSize(1)); 155 155 // - the copy should be full, too 156 assert(Dest. IsFull() == true);156 assert(Dest.isFull() == true); 157 157 // - the copy should have exactly the same assignments in matching 158 158 for (iObj = 0; iObj < iSize; iObj++) … … 160 160 // all object should be matched! 161 161 // check both directions: 0 -> 1 162 assert(Dest. IsMatched(0, iObj) == true);163 assert(iObj == Dest. GetMatchedIndex(0, iObj));162 assert(Dest.isMatched(0, iObj) == true); 163 assert(iObj == Dest.getMatchedIndex(0, iObj)); 164 164 // and: 1 -> 0 165 assert(Dest. IsMatched(1, iObj) == true);166 assert(iObj == Dest. GetMatchedIndex(1, iObj));165 assert(Dest.isMatched(1, iObj) == true); 166 assert(iObj == Dest.getMatchedIndex(1, iObj)); 167 167 } 168 168 // make it empty 169 Dest. Empty();169 Dest.empty(); 170 170 // and check once more 171 assert(Dest. IsEmpty() == true);171 assert(Dest.isEmpty() == true); 172 172 } 173 173 … … 176 176 SimilMatching Source(iSize, iSize); 177 177 // check if it is empty 178 assert(Source. IsEmpty() == true);178 assert(Source.isEmpty() == true); 179 179 // check sizes of objects 180 assert(Source. GetObjectSize(0) == iSize);181 assert(Source. GetObjectSize(1) == iSize);180 assert(Source.getObjectSize(0) == iSize); 181 assert(Source.getObjectSize(1) == iSize); 182 182 // match objects (iObj, N - iObj - 1) 183 183 for (iObj = 0; iObj < iSize; iObj++) 184 184 { 185 Source. Match(0, iObj, 1, iSize - iObj - 1);185 Source.match(0, iObj, 1, iSize - iObj - 1); 186 186 } 187 187 // check if the matching is full 188 assert(Source. IsFull() == true);188 assert(Source.isFull() == true); 189 189 // now create a copy of the matching 190 190 SimilMatching Dest(Source); 191 191 // check the copy 192 192 // - sizes of matched object 193 assert(Dest. GetObjectSize(0) == Source.GetObjectSize(0));194 assert(Dest. GetObjectSize(1) == Source.GetObjectSize(1));193 assert(Dest.getObjectSize(0) == Source.getObjectSize(0)); 194 assert(Dest.getObjectSize(1) == Source.getObjectSize(1)); 195 195 // - the copy should be full, too 196 assert(Dest. IsFull() == true);196 assert(Dest.isFull() == true); 197 197 // - the copy should have exactly the same assignments in matching 198 198 for (iObj = 0; iObj < iSize; iObj++) … … 200 200 // all object should be matched! 201 201 // check both directions: 0 -> 1 202 assert(Dest. IsMatched(0, iObj) == true);203 assert((iSize - iObj - 1) == Dest. GetMatchedIndex(0, iObj));202 assert(Dest.isMatched(0, iObj) == true); 203 assert((iSize - iObj - 1) == Dest.getMatchedIndex(0, iObj)); 204 204 // and: 1 -> 0 205 assert(Dest. IsMatched(1, iObj) == true);206 assert((iSize - iObj - 1) == Dest. GetMatchedIndex(1, iObj));205 assert(Dest.isMatched(1, iObj) == true); 206 assert((iSize - iObj - 1) == Dest.getMatchedIndex(1, iObj)); 207 207 } 208 208 // make it empty 209 Dest. Empty();209 Dest.empty(); 210 210 // and check once more 211 assert(Dest. IsEmpty() == true);211 assert(Dest.isEmpty() == true); 212 212 } 213 213 … … 216 216 SimilMatching Source(iSize, 2 * iSize); 217 217 // check if it is empty 218 assert(Source. IsEmpty() == true);218 assert(Source.isEmpty() == true); 219 219 // check sizes of objects 220 assert(Source. GetObjectSize(0) == iSize);221 assert(Source. GetObjectSize(1) == 2 * iSize);220 assert(Source.getObjectSize(0) == iSize); 221 assert(Source.getObjectSize(1) == 2 * iSize); 222 222 // match objects (iObj, 2 * iObj) 223 223 for (iObj = 0; iObj < iSize; iObj++) 224 224 { 225 Source. Match(0, iObj, 1, 2 * iObj);225 Source.match(0, iObj, 1, 2 * iObj); 226 226 } 227 227 // check if the matching is full (should be, as the smaller set is completely matched 228 assert(Source. IsFull() == true);228 assert(Source.isFull() == true); 229 229 // now create a copy of the matching 230 230 SimilMatching Dest(Source); 231 231 // check the copy 232 232 // - sizes of matched object 233 assert(Dest. GetObjectSize(0) == Source.GetObjectSize(0));234 assert(Dest. GetObjectSize(1) == Source.GetObjectSize(1));233 assert(Dest.getObjectSize(0) == Source.getObjectSize(0)); 234 assert(Dest.getObjectSize(1) == Source.getObjectSize(1)); 235 235 // - the copy should be full, too 236 assert(Dest. IsFull() == true);236 assert(Dest.isFull() == true); 237 237 // - the copy should have exactly the same assignments in matching 238 238 for (iObj = 0; iObj < iSize; iObj++) … … 240 240 // check both directions: 0 -> 1 241 241 // (all matched, (iObj, 2 * iObj)) 242 assert(Dest. IsMatched(0, iObj) == true);243 assert((2 * iObj) == Dest. GetMatchedIndex(0, iObj));242 assert(Dest.isMatched(0, iObj) == true); 243 assert((2 * iObj) == Dest.getMatchedIndex(0, iObj)); 244 244 // and direction; 1 -> 0 245 245 // (only even are matched, ( 2 * iObj, iObj)) 246 246 // for 2 * iObj (which are even): matched 247 assert(Dest. IsMatched(1, 2 * iObj) == true);248 assert(iObj == Dest. GetMatchedIndex(1, 2 * iObj));247 assert(Dest.isMatched(1, 2 * iObj) == true); 248 assert(iObj == Dest.getMatchedIndex(1, 2 * iObj)); 249 249 // for 2 * iObj + 1 (which are odd): unmatched 250 assert(Dest. IsMatched(1, 2 * iObj + 1) == false);250 assert(Dest.isMatched(1, 2 * iObj + 1) == false); 251 251 } 252 252 // make it empty 253 Dest. Empty();253 Dest.empty(); 254 254 // and check once more 255 assert(Dest. IsEmpty() == true);255 assert(Dest.isEmpty() == true); 256 256 } 257 257 … … 273 273 274 274 // matching is empty 275 assert(match1. IsEmpty() == true);275 assert(match1.isEmpty() == true); 276 276 277 277 // create matching - (i,i) … … 280 280 281 281 // matching is not full 282 assert(match1. IsFull() == false);282 assert(match1.isFull() == false); 283 283 284 284 // these are not matched yet 285 assert(match1. IsMatched(0, i) == false);286 assert(match1. IsMatched(1, i) == false);285 assert(match1.isMatched(0, i) == false); 286 assert(match1.isMatched(1, i) == false); 287 287 288 288 // now - match! 289 match1. Match(0, i, 1, i);289 match1.match(0, i, 1, i); 290 290 291 291 // matching is not empty 292 assert(match1. IsEmpty() == false);292 assert(match1.isEmpty() == false); 293 293 294 294 // now they are matched 295 assert(match1. IsMatched(0, i) == true);296 assert(match1. IsMatched(1, i) == true);295 assert(match1.isMatched(0, i) == true); 296 assert(match1.isMatched(1, i) == true); 297 297 298 298 // check the matched index for object 0 and 1 299 assert(match1. GetMatchedIndex(0, i) == i);300 assert(match1. GetMatchedIndex(1, i) == i);299 assert(match1.getMatchedIndex(0, i) == i); 300 assert(match1.getMatchedIndex(1, i) == i); 301 301 } 302 302 303 303 // now matching have to be full 304 assert(match1. IsFull() == true);304 assert(match1.isFull() == true); 305 305 306 306 // check some symmetric matching … … 308 308 309 309 // matching is empty 310 assert(match2. IsEmpty() == true);310 assert(match2.isEmpty() == true); 311 311 312 312 // create matching - (i, nSize1 - 1 - i) … … 315 315 316 316 // matching is not full 317 assert(match2. IsFull() == false);317 assert(match2.isFull() == false); 318 318 319 319 // these are not matched yet 320 assert(match2. IsMatched(0, i) == false);321 assert(match2. IsMatched(1, nSize1 - 1 - i) == false);320 assert(match2.isMatched(0, i) == false); 321 assert(match2.isMatched(1, nSize1 - 1 - i) == false); 322 322 323 323 // now - match (but use the opposite syntax)! 324 match2. Match(1, nSize1 - 1 - i, 0, i);324 match2.match(1, nSize1 - 1 - i, 0, i); 325 325 326 326 // matching is not empty 327 assert(match2. IsEmpty() == false);327 assert(match2.isEmpty() == false); 328 328 329 329 // now they are matched 330 assert(match2. IsMatched(0, i) == true);331 assert(match2. IsMatched(1, nSize1 - 1 - i) == true);330 assert(match2.isMatched(0, i) == true); 331 assert(match2.isMatched(1, nSize1 - 1 - i) == true); 332 332 333 333 // check the matched index for object 0 and 1 334 assert(match2. GetMatchedIndex(0, i) == (nSize1 - 1 - i));335 assert(match2. GetMatchedIndex(1, nSize1 - 1 - i) == i);334 assert(match2.getMatchedIndex(0, i) == (nSize1 - 1 - i)); 335 assert(match2.getMatchedIndex(1, nSize1 - 1 - i) == i); 336 336 } 337 337 338 338 // now matching have to be full 339 assert(match2. IsFull() == true);339 assert(match2.isFull() == true); 340 340 341 341 // check some asymmnetic matching, too … … 343 343 344 344 // matching is empty 345 assert(match3. IsEmpty() == true);345 assert(match3.isEmpty() == true); 346 346 347 347 // create matching - (i, 2 * i) … … 350 350 351 351 // matching is not full 352 assert(match3. IsFull() == false);352 assert(match3.isFull() == false); 353 353 354 354 // these are not matched yet 355 assert(match3. IsMatched(0, i) == false);356 assert(match3. IsMatched(1, 2 * i) == false);355 assert(match3.isMatched(0, i) == false); 356 assert(match3.isMatched(1, 2 * i) == false); 357 357 358 358 // now - match (but use the opposite syntax)! 359 match3. Match(1, 2 * i, 0, i);359 match3.match(1, 2 * i, 0, i); 360 360 361 361 // matching is not empty 362 assert(match3. IsEmpty() == false);362 assert(match3.isEmpty() == false); 363 363 364 364 // now they are matched 365 assert(match3. IsMatched(0, i) == true);366 assert(match3. IsMatched(1, 2 * i) == true);365 assert(match3.isMatched(0, i) == true); 366 assert(match3.isMatched(1, 2 * i) == true); 367 367 368 368 // but the odd elements of object 1 are not matched 369 assert(match3. IsMatched(1, 2 * i + 1) == false);369 assert(match3.isMatched(1, 2 * i + 1) == false); 370 370 371 371 // check the matched index for object 0 and 1 372 assert(match3. GetMatchedIndex(0, i) == 2 * i);373 assert(match3. GetMatchedIndex(1, 2 * i) == i);372 assert(match3.getMatchedIndex(0, i) == 2 * i); 373 assert(match3.getMatchedIndex(1, 2 * i) == i); 374 374 } 375 375 376 376 // now matching have to be full (because the smallest object has all elements matched). 377 assert(match3. IsFull() == true);377 assert(match3.isFull() == true); 378 378 379 379 return 0;
Note: See TracChangeset
for help on using the changeset viewer.