void baseReqTests(IntVector& intVector) { assert(intVector.empty()); assert(intVector.size() == 0); // Insert 20 things into the vector for (int i = 0; i < 20; i++) { intVector.push_back(i); } // Make sure vector is no longer empty assert(!intVector.empty()); // Make sure there is exactly 20 things in vector assert(intVector.size() == 20); // Make sure things are in the right place assert(intVector.at(0) == 0); assert(intVector.at(5) == 5); assert(intVector.at(15) == 15); assert(intVector.at(19) == 19); // Let's pop something assert(intVector.pop_back() == 19); assert(intVector.size() == 19); try { intVector.at(19); } catch (int e) { assert(true); } // Let's pop everything int old = 19; while (!intVector.empty()) { int temp = intVector.pop_back(); assert(temp == old - 1); old = temp; } }
void intermediateReqTests(IntVector& intVector) { assert(intVector.empty()); intVector.push_back(5); assert(intVector.count(5) == 1); intVector.insert(5, 0); intVector.insert(5, 2); assert(intVector.count(5) == 3); intVector.remove(0); assert(intVector.count(5) == 2); intVector.remove(1); assert(intVector.count(5) == 1); intVector.remove(0); }
bool Enemy::isVisible(float x1, float z1, float x2, float z2, IntVector fields) { if (fields.empty()) return true; CollisionModel collMod(COLL_RECTANGLE); //collMod.setYBottom(0.0f); //collMod.setYTop(0.1f); float m = (z2 - z1) / (x2 - x1); float ax = AI_COLL_WIDTH / 2.0f / sqrtf(1.0f + 1.0f / (m * m)); float az = -ax / m; collMod.setVertex(0, x1 + ax, z1 + az); collMod.setVertex(1, x1 - ax, z1 - az); collMod.setVertex(2, x2 + ax, z2 + az); collMod.setVertex(3, x2 - ax, z2 - az); return !Scene::RectCollidesWithFields(&collMod, fields); }
void testValues(IntVector& test) { cout << "Size: " << test.size() << endl; cout << "Capacity: " << test.capacity() << endl; cout << "Array: " << endl; //display array if vector is NOT empty if (!test.empty()) { for (int i = 0; i < test.size(); i++) { cout << "#" << i << ": " << test.at(i); cout << endl; } } else { cout << "Vector is empty!" << endl; } cout << endl; }
void advancedReqTests(IntVector& intVector) { assert(intVector.empty()); IntVector mySecondVector; for (int i = 0; i < 100; i++) { mySecondVector.push_back(i); } intVector = mySecondVector; assert(intVector == mySecondVector); assert(intVector[0] == 0); assert(intVector[99] == 99); intVector[0] = 5; assert(!(intVector == mySecondVector)); assert(intVector[0] == 5); }
// Clearing a standard container using clear() is treated as a // re-initialization. void standardContainerClearIsReinit() { { std::string container; std::move(container); container.clear(); container.empty(); } { std::vector<int> container; std::move(container); container.clear(); container.empty(); } { std::deque<int> container; std::move(container); container.clear(); container.empty(); } { std::forward_list<int> container; std::move(container); container.clear(); container.empty(); } { std::list<int> container; std::move(container); container.clear(); container.empty(); } { std::set<int> container; std::move(container); container.clear(); container.empty(); } { std::map<int> container; std::move(container); container.clear(); container.empty(); } { std::multiset<int> container; std::move(container); container.clear(); container.empty(); } { std::multimap<int> container; std::move(container); container.clear(); container.empty(); } { std::unordered_set<int> container; std::move(container); container.clear(); container.empty(); } { std::unordered_map<int> container; std::move(container); container.clear(); container.empty(); } { std::unordered_multiset<int> container; std::move(container); container.clear(); container.empty(); } { std::unordered_multimap<int> container; std::move(container); container.clear(); container.empty(); } // This should also work for typedefs of standard containers. { typedef std::vector<int> IntVector; IntVector container; std::move(container); container.clear(); container.empty(); } // But it shouldn't work for non-standard containers. { // This might be called "vector", but it's not in namespace "std". struct vector { void clear() {} } container; std::move(container); container.clear(); // CHECK-MESSAGES: [[@LINE-1]]:5: warning: 'container' used after it was // CHECK-MESSAGES: [[@LINE-3]]:5: note: move occurred here } // An intervening clear() on a different container does not reinitialize. { std::vector<int> container1, container2; std::move(container1); container2.clear(); container1.empty(); // CHECK-MESSAGES: [[@LINE-1]]:5: warning: 'container1' used after it was // CHECK-MESSAGES: [[@LINE-4]]:5: note: move occurred here } }
inline bool IndexedList::empty(void) const { return _list.empty(); }
bool MSProductParameters::getSequenceElements ( ParameterList* params, const string& num, string& sequence, string& nTermName, string& cTermName, string& neutralLossName ) { sequence = params->getStrippedStringValue ( "sequence" + num, "" ); if ( sequence.empty () ) return false; nTermName = params->getStringValue ( "nterm" + num, "" ); cTermName = params->getStringValue ( "cterm" + num, "" ); neutralLossName = params->getStringValue ( "nloss" + num, "" ); if ( nTermName.empty () && cTermName.empty () && neutralLossName.empty () ) { static StringVector nTermNames = ConstMod::getNTermNames (); static StringVector cTermNames = ConstMod::getCTermNames (); static StringVector nLossNames = ConstMod::getNLossNames (); IntVector plusIdx; IntVector minusIdx; for ( StringSizeType i = 0 ; i < sequence.length () ; i++ ) { char p = sequence [i]; if ( p == '+' ) plusIdx.push_back ( i ); else if ( p == '-' )minusIdx.push_back ( i ); else if ( p == '(' ) { int bracket = 0; for ( ; i < sequence.length () ; i++ ) { char a = sequence [i]; if ( a == '(' ) bracket++; if ( a == ')' ) bracket--; if ( bracket == 0 ) break; } } } if ( !plusIdx.empty () ) { for ( int i = 0 ; i < nLossNames.size () ; i++ ) { string nL = nLossNames [i]; if ( isSuffix ( sequence, "+" + nL ) ) { sequence = sequence.substr ( 0, sequence.length () - 1 - nL.length () ); neutralLossName = nL; break; } } if ( neutralLossName.empty () ) { string possNLoss = sequence.substr ( plusIdx.back () + 1 ); // Add 1 to the last + if ( genStringIsFloat ( possNLoss ) ) { // Check if number sequence = sequence.substr ( 0, plusIdx.back () ); neutralLossName = possNLoss; } } while ( !minusIdx.empty () && minusIdx.back () >= sequence.length () ) minusIdx.pop_back (); } if ( !minusIdx.empty () ) { for ( int i = 0 ; i < cTermNames.size () ; i++ ) { string nC = cTermNames [i]; if ( nC.empty () ) continue; if ( isSuffix ( sequence, "-" + nC ) ) { sequence = sequence.substr ( 0, sequence.length () - 1 - nC.length () ); cTermName = nC; break; } } if ( cTermName.empty () ) { int idx = minusIdx.back (); if ( sequence [idx-1] != '-' ) idx += 1; string possCTerm = sequence.substr ( idx ); // Add 1 to the last - if ( genStringIsFloat ( possCTerm ) ) { // Check if number sequence = sequence.substr ( 0, idx - 1 ); cTermName = possCTerm; } } while ( minusIdx.back () >= sequence.length () ) minusIdx.pop_back (); } if ( !minusIdx.empty () ) { for ( int j = 0 ; j < nTermNames.size () ; j++ ) { string nN = nTermNames [j]; if ( nN.empty () ) continue; if ( isPrefix ( sequence, nN + "-" ) ) { sequence = sequence.substr ( nN.length () + 1 ); nTermName = nN; break; } } if ( nTermName.empty () ) { int idx = ( sequence [0] == '-' ) ? minusIdx [1] : minusIdx [0]; string possNTerm = sequence.substr ( 0, idx ); if ( genStringIsFloat ( possNTerm ) ) { // Check if number sequence = sequence.substr ( idx + 1 ); nTermName = possNTerm; } } } params->addOrReplaceName ( "sequence" + num, sequence ); params->addOrReplaceName ( "nterm" + num, nTermName ); params->addOrReplaceName ( "cterm" + num, cTermName ); params->addOrReplaceName ( "nloss" + num, neutralLossName ); } return true; }