예제 #1
0
//Add and remove some items, making sure they come back in the
// correct order
void testAddRemove(ArrayQueue<int>& testQueue){
	testQueue.add(5);
	testQueue.add(10);
	testQueue.add(4);
	if (testQueue.getNumItems() == 3){
		std::cout << "SUCCESS: 3 items added" << std::endl;
	}
	else {
		std::cout << "ERROR: Added 3 items, but getNumItems says " << testQueue.getNumItems() << std::endl;
		return;
	}
	int x = testQueue.remove();
	int y = testQueue.remove();
	int z = testQueue.remove();
	if (x != 5 || y != 10 || z != 4){
		std::cout << "ERROR: Expected 5, 10, 4, but got " << x << ", " << y << ", " << "z" << std::endl;
	}
	else {
		std::cout << "SUCCESS: 3 added items came back out in the correct order" << std::endl;
	}
}
예제 #2
0
//Test to see if your queue still works if we do add, remove, add, remove
// many times
void testAroundTheHorn(ArrayQueue<int>& testQueue){
	//std::cout << "IM reall HERE" << std::endl;
	for (int i = 0; i<1000; i++){
		testQueue.add(i);
		int t = testQueue.remove();
		//std::cout << "IM HERE"<<t<<"!!" << std::endl;
		//breaks when trying to access i or t
		if (t != i){
			std::cout << "ERROR: Added " << i << " but got back " << t << std::endl;
			return;
		}
	}
	std::cout << "SUCCESS: Added and removed 1000 items successfully" << std::endl;
}
예제 #3
0
//Test to see if your queue can grow to handle lots of items
void testGrow(ArrayQueue<int>& testQueue){
  for(int i=0;i<1000;i++){
    testQueue.add(i);
  }

  if(testQueue.getNumItems() != 1000){
    std::cout << "ERROR: Should have 1000 items in queue, but only found " << testQueue.getNumItems() << std::endl;
    return;
  }

  for(int i=0;i<1000;i++){
    int t = testQueue.remove();
    if(t != i){
      std::cout << "ERROR: Added " << i << " but got back " << t << std::endl;
      return;
    }
  }
  std::cout << "SUCCESS: Added 1000 items, then removed 1000" << std::endl;
}