int main() { DynamicStack <int> testStack; if(testStack.intTest()) cout << "int test passed" <<endl; else cout << "int test failed" << endl; DynamicStack <char> test2Stack; if(testStack.charTest()) cout << "char test passed" <<endl; else cout << "char test failed" << endl; DynamicStack <string> test3Stack; if(testStack.stringTest()) cout << "string test passed" <<endl; else cout << "string test failed" << endl; system("pause"); }
// Full stack doubles properly bool test5() { DynamicStack stack; for(int i = 0; i < 17; i++) stack.push(i); ASSERT_TRUE(stack.capacity_ == 32) for(int i = 16; i >= 0; i--) ASSERT_TRUE(stack.pop() == i) ASSERT_TRUE(stack.pop() == DynamicStack::EMPTY_STACK) return true; }
// Push a number of items equal to initial size + 1 and then remove slightly more than half of them so that //no. of items is less than half the new size of the stack. The size limit should be halved by then bool test8() { DynamicStack stack; for(int i = 0; i < 17; i++) stack.push(i); ASSERT_TRUE(stack.capacity_ == 32) for(int i = 16; i >= 6; i--) ASSERT_TRUE(stack.pop() == i) ASSERT_TRUE(stack.capacity_ == 16) return true; }
// Push a number of items equal to initial size and then remove most of them so that no. of items //is less than half the size of the stack. As the size limit is still the initial size, no //changes in its value should take place bool test7() { DynamicStack stack; for(int i = 0; i < 16; i++) stack.push(i); ASSERT_TRUE(stack.capacity_ == 16) for(int i = 15; i >= 1; i--) ASSERT_TRUE(stack.pop() == i) ASSERT_TRUE(stack.capacity_ == 16) ASSERT_TRUE(stack.size() == 1) return true; }
void test2() { DynamicStack<int> iStack; iStack.push(1); iStack.push(2); iStack.push(3); iStack.push(4); iStack.push(5); iStack.push(6); cout << "Traverse elements" << endl; for(DynamicStackIterator<int> iter = DynamicStackIterator<int>(iStack); iter != iter.end(); iter++){ cout << "value: " << *iter << endl; } }
void popItem(DynamicStack<string> &stack) { string item=""; stack.pop(item); if(item!="") cout<<item<<" was popped.\n"; }
void pushItem(DynamicStack<string> &stack) { string item; cin.ignore(); cout<<"\nEnter an item "; getline(cin,item); stack.push(item); }
const View<char> Allocate(DynamicStack& ds, const char* text) { size_t length = strlen(text); auto view = ds.Allocate(length); memcpy(view.first, text, length); return { reinterpret_cast<char*>(view.first), view.length }; }
// Push one item and then pop it bool test2() { DynamicStack stack; stack.push(10); ASSERT_TRUE(stack.empty() == false) ASSERT_TRUE(stack.size() == 1) ASSERT_TRUE(stack.pop() == 10); ASSERT_TRUE(stack.empty() == true) ASSERT_TRUE(stack.size() == 0) return true; }
void test1() { DynamicStack<int> iStack; iStack.push(1); iStack.push(2); iStack.push(3); iStack.push(4); iStack.push(5); iStack.push(6); cout << "top: " << iStack.top() << endl; iStack.pop(); iStack.pop(); cout << "top: " << iStack.top() << endl; iStack.pop(); cout << "top: " << iStack.top() << endl; cout << "size: " << iStack.size() << endl; cout << "is empty: " << (iStack.isEmpty() ? "T" : "F") << endl; iStack.pop(); iStack.pop(); iStack.pop(); cout << "is empty: " << (iStack.isEmpty() ? "T" : "F") << endl; }