Ejemplo n.º 1
0
int main(void)
{
	const std::string saveFileName = "ShoppingListData.txt";
	ShoppingList theList;

	Output::PrintLanding();

	if (theList.loadFromFile(saveFileName) != SL_SUCCESS)
	{
		std::cout << "Unable to open file '" << saveFileName << "'." << std::endl;
		return 1;
	}
	std::cout << std::endl << theList.getItemCount() << " records have been loaded from '" << saveFileName << "'." << std::endl;


	main_loop(theList);


	if (theList.writeToFile(saveFileName) != SL_SUCCESS)
	{
		std::cout << "Unable to write to '" << saveFileName << "'." << std::endl;
		return 1;
	}

	std::cout << "Wrote " << theList.getItemCount() << " items to '" << saveFileName << "'." << std::endl;

	std::cout << std::endl;
	//for demo purposes only
	system("PAUSE"); 

	return 0;
}
int main(int argc, char* argv[]) {
    QApplication app(argc, argv);


    app.setQuitOnLastWindowClosed(false) ; /* this is necessary
      if there is no QMainWindow and we are opening/closing 
      dialogs. */

    ShoppingList shplst;
    loadShoppingList(shplst);
    qDebug() << "Send the following list to the printer:\n\n";
    qDebug() << shplst.makePrintList();
    return 0;
}
Ejemplo n.º 3
0
int main(){

	ShoppingList myList;

	myList.addItemAtEnd("Bananas", 3.20);
	myList.addItemAtEnd("Milk", 5.20);
	myList.addItemAtEnd("Eggs", 1.30);
	myList.addItemAtEnd("Toilet Paper", 19.48);
	myList.addItemAtEnd("Bread", 0.50);
	myList.addItemAtEnd("Poopuri", 7.99);

	std::cout << myList.showList() << std::endl;
	std::cout << myList.showSize() << std::endl;
	ShoppingList *list = &myList;
	mergeSort(&list);
	//std::cout << list->showList() << std::endl;

}	
Ejemplo n.º 4
0
void main_loop(ShoppingList& theList)
{
	int option = 0;
	std::string input;

	while(1)
	{
		std::cout << std::endl;
		Output::PrintMainMenu();
		std::cout << std::endl;
		option = Input::GetMainMenuChoice();
		//std::cout << std::endl;
		
		switch(option)
		{
			case OPTION_ADD:
				Input::AddItem(theList);
				break;
			case OPTION_DELETE:
				Input::DeleteItem(theList);
				break;
			case OPTION_EDIT:
				Input::EditItem(theList);
				break;
			case OPTION_PRIMARYKEY:
				input = Input::StringPrompt("Enter the name of the item to print:");
				theList.displayItem(input);
				break;
			case OPTION_HASHSEQ:
				theList.printListHashSeq();
				break;
			case OPTION_KEYSEQ:
				theList.printListByName();
				break;
			case OPTION_BST:
				theList.printTree();
				break;
			case OPTION_EFFICIENCY:
				theList.printHashTableEfficiency();
				break;
			case OPTION_BYSTORE:
				input = Input::StringPrompt("Enter the store to search by:");

				theList.printByStore(input);
				break;
			case OPTION_QUIT:
				return;
				break;
		}
		//std::cout << std::endl << "There are " << theList.getItemCount() << " items in the list." << std::endl;
	}
}
Ejemplo n.º 5
0
void unittest ()
{
    cout << "\nSTARTING UNIT TEST\n\n";

    ShoppingList* myList = new ShoppingList;

    cout << "* DEFAULT CONSTRUCTOR *\n\n";

    try {
        btassert<bool>(myList->getMaxItems() == 25);
        cout << "Passed TEST 1: ShoppingList::getMaxItems () \n";
    } catch (bool b) {
        cout << "# FAILED TEST 1: ShoppingList::getMaxItems () #\n";
    }

    try {
        btassert<bool>(myList->getItemCount() == 0);
        cout << "Passed TEST 2: ShoppingList::getItemCount () \n";
    } catch (bool b) {
        cout << "# FAILED TEST 2: ShoppingList::getItemCount () #\n";
    }

    try {
        myList->getItem(0);
        btassert<bool>(false);
    } catch (ArrayException e) {
        try {
            btassert<bool>(e.message == "INVALID ARRAY INDEX");
            cout << "Passed TEST 3: ShoppingList::getItem(0) EXCEPTION HANDLING \n";
        } catch (bool b) {
            cout << "# FAILED TEST 3: ShoppingList::getItem(0) EXCEPTION HANDLING #\n";
        }
    } catch(bool b) {
        cout << "# FAILED TEST 3: ShoppingList::getItem(0) EXCEPTION HANDLING #\n";
    }

    try {
        btassert<bool>(myList->addItem("apples") == true);
        cout << "Passed TEST 4: ShoppingList::addItem(\"apples\") \n";
    } catch (bool b) {
        cout << "# FAILED TEST 4: ShoppingList::addItem(\"apples\") #\n";
    }

    try {
        btassert<bool>(myList->getItemCount() == 1);
        cout << "Passed TEST 5: ShoppingList::getItemCount () \n";
    } catch (bool b) {
        cout << "# FAILED TEST 5: ShoppingList::getItemCount () #\n";
    }

    try {
        btassert<bool>(myList->getItem(0) == "apples");
        cout << "Passed TEST 6: ShoppingList::getItem(0) \n";
    } catch (bool b) {
        cout << "# FAILED TEST 6: ShoppingList::getItem(0) #\n";
    }

    myList->getItem(0) = "oranges";
    try {
        btassert<bool>(myList->getItem(0) == "oranges");
        cout << "Passed TEST 7: string& ShoppingList::getItem(0) \n";
    } catch (bool b) {
        cout << "# FAILED TEST 7: string& ShoppingList::getItem(0) #\n";
    }

    try {
        btassert<bool>(myList->removeItem(0) == "oranges");
        cout << "Passed TEST 8: ShoppingList::removeItem(0) \n";
    } catch (bool b) {
        cout << "# FAILED TEST 8: ShoppingList::removeItem(0) #\n";
    }

    try {
        btassert<bool>(myList->getItemCount() == 0);
        cout << "Passed TEST 9: ShoppingList::getItemCount () \n";
    } catch (bool b) {
        cout << "# FAILED TEST 9: ShoppingList::getItemCount () #\n";
    }

    for (unsigned int i=0; i<myList->getMaxItems(); i++)
        myList->addItem("grapes");

    try {
        btassert<bool>(myList->getItemCount() == 25);
        cout << "Passed TEST 10: ShoppingList::getItemCount () \n";
    } catch (bool b) {
        cout << "# FAILED TEST 10: ShoppingList::getItemCount () #\n";
    }

    try {
        myList->getItem(26);
        btassert<bool>(false);
    } catch (ArrayException e) {
        try {
            btassert<bool>(e.message == "INVALID ARRAY INDEX");
            cout << "Passed TEST 11: ShoppingList::getItem(11) EXCEPTION HANDLING \n";
        } catch (bool b) {
            cout << "# FAILED TEST 11: ShoppingList::setItem(11) EXCEPTION HANDLING #\n";
        }
    } catch(bool b) {
        cout << "# FAILED TEST 11: ShoppingList::setItem(11) EXCEPTION HANDLING #\n";
    }

    try {
        btassert<bool>(myList->addItem("bananas") == false);
        cout << "Passed TEST 12: ShoppingList::addItem(\"bananas\") \n";
    } catch (bool b) {
        cout << "# FAILED TEST 12: ShoppingList::getItem(\"bananas\") #\n";
    }

    unsigned int itemsToRemove = myList->getItemCount();
    for (unsigned int i=0; i<itemsToRemove; i++)
        myList->removeItem(0);

    try {
        btassert<bool>(myList->getItemCount() == 0);
        cout << "Passed TEST 13: ShoppingList::getItemCount () \n";
    } catch (bool b) {
        cout << "# FAILED TEST 13: ShoppingList::getItemCount () #\n";
    }

    try {
        myList->getItem(0) = "oranges";
        btassert<bool>(false);
    } catch (ArrayException e) {
        try {
            btassert<bool>(e.message == "INVALID ARRAY INDEX");
            cout << "Passed TEST 14: string& ShoppingList::getItem(0) EXCEPTION HANDLING \n";
        } catch (bool b) {
            cout << "# FAILED TEST 14: string& ShoppingList::setItem(0) EXCEPTION HANDLING #\n";
        }
    } catch(bool b) {
        cout << "# FAILED TEST 14: string& ShoppingList::setItem(0) EXCEPTION HANDLING #\n";
    }

    try {
        btassert<bool>(myList->getMaxItems() == 25);
        cout << "Passed TEST 15: ShoppingList::getMaxItems () \n";
    } catch (bool b) {
        cout << "# FAILED TEST 15: ShoppingList::getMaxItems () #\n";
    }

    delete myList;
    myList = new ShoppingList(1);

    cout << "\n* OVERLOADED CONSTRUCTOR *\n\n";

    try {
        btassert<bool>(myList->getMaxItems() == 1);
        cout << "Passed TEST 16: ShoppingList::getMaxItems () \n";
    } catch (bool b) {
        cout << "# FAILED TEST 16: ShoppingList::getMaxItems () #\n";
    }

    try {
        btassert<bool>(myList->addItem("apples") == true);
        cout << "Passed TEST 17: ShoppingList::addItem(\"apples\") \n";
    } catch (bool b) {
        cout << "# FAILED TEST 17: ShoppingList::addItem(\"apples\") #\n";
    }

    try {
        btassert<bool>(myList->getItem(0) == "apples");
        cout << "Passed TEST 18: ShoppingList::getItem(0) \n";
    } catch (bool b) {
        cout << "# FAILED TEST 18: ShoppingList::getItem(0) #\n";
    }

    try {
        myList->removeItem(1);
        btassert<bool>(false);
    } catch (ArrayException e) {
        try {
            btassert<bool>(e.message == "INVALID ARRAY INDEX");
            cout << "Passed TEST 19: ShoppingList::removeItem(1) EXCEPTION HANDLING \n";
        } catch (bool b) {
            cout << "# FAILED TEST 19: ShoppingList::removeItem(1) EXCEPTION HANDLING #\n";
        }
    } catch(bool b) {
        cout << "# FAILED TEST 19: ShoppingList::removeItem(1) EXCEPTION HANDLING #\n";
    }

    try {
        myList->getItem(1);
        btassert<bool>(false);
    } catch (ArrayException e) {
        try {
            btassert<bool>(e.message == "INVALID ARRAY INDEX");
            cout << "Passed TEST 20: ShoppingList::getItem(1) EXCEPTION HANDLING \n";
        } catch (bool b) {
            cout << "# FAILED TEST 20: ShoppingList::getItem(1) EXCEPTION HANDLING #\n";
        }
    } catch(bool b) {
        cout << "# FAILED TEST 20: ShoppingList::getItem(1) EXCEPTION HANDLING #\n";
    }

    cout << "\n* RESET FUNCTION *\n\n";

    try {
        myList->reset(0);
        btassert<bool>(false);
    } catch (ArrayException e) {
        try {
            btassert<bool>(e.message == "INVALID ARRAY SIZE");
            cout << "Passed TEST 21: ShoppingList::reset(0) EXCEPTION HANDLING \n";
        } catch (bool b) {
            cout << "# FAILED TEST 21: ShoppingList::reset(0) EXCEPTION HANDLING #\n";
        }
    } catch(bool b) {
        cout << "# FAILED TEST 21: ShoppingList::reset(0) EXCEPTION HANDLING #\n";
    }

    try {
        btassert<bool>(myList->getMaxItems() == 1);
        cout << "Passed TEST 22: ShoppingList::getMaxItems () \n";
    } catch (bool b) {
        cout << "# FAILED TEST 22: ShoppingList::getMaxItems () #\n";
    }

    myList->reset(5);

    try {
        btassert<bool>(myList->getMaxItems() == 5);
        cout << "Passed TEST 23: ShoppingList::getMaxItems () \n";
    } catch (bool b) {
        cout << "# FAILED TEST 23: ShoppingList::getMaxItems () #\n";
    }

    try {
        btassert<bool>(myList->getItemCount() == 0);
        cout << "Passed TEST 24: ShoppingList::getItemCount () \n";
    } catch (bool b) {
        cout << "# FAILED TEST 24: ShoppingList::getItemCount () #\n";
    }

    for (unsigned int i=0; i<myList->getMaxItems(); i++)
        myList->addItem("grapes");

    try {
        btassert<bool>(myList->getItemCount() == 5);
        cout << "Passed TEST 25: ShoppingList::getItemCount () \n";
    } catch (bool b) {
        cout << "# FAILED TEST 25: ShoppingList::getItemCount () #\n";
    }

    try {
        myList->getItem(6);
        btassert<bool>(false);
    } catch (ArrayException e) {
        try {
            btassert<bool>(e.message == "INVALID ARRAY INDEX");
            cout << "Passed TEST 26: ShoppingList::getItem(6) EXCEPTION HANDLING \n";
        } catch (bool b) {
            cout << "# FAILED TEST 26: ShoppingList::setItem(6) EXCEPTION HANDLING #\n";
        }
    } catch(bool b) {
        cout << "# FAILED TEST 26: ShoppingList::setItem(6) EXCEPTION HANDLING #\n";
    }

    try {
        btassert<bool>(myList->addItem("bananas") == false);
        cout << "Passed TEST 27: ShoppingList::addItem(\"bananas\") \n";
    } catch (bool b) {
        cout << "# FAILED TEST 27: ShoppingList::getItem(\"bananas\") #\n";
    }

    itemsToRemove = myList->getItemCount();
    for (unsigned int i=0; i<itemsToRemove; i++)
        myList->removeItem(0);

    try {
        btassert<bool>(myList->getItemCount() == 0);
        cout << "Passed TEST 28: ShoppingList::getItemCount () \n";
    } catch (bool b) {
        cout << "# FAILED TEST 28: ShoppingList::getItemCount () #\n";
    }

    try {
        myList->getItem(0) = "oranges";
        btassert<bool>(false);
    } catch (ArrayException e) {
        try {
            btassert<bool>(e.message == "INVALID ARRAY INDEX");
            cout << "Passed TEST 29: string& ShoppingList::getItem(0) EXCEPTION HANDLING \n";
        } catch (bool b) {
            cout << "# FAILED TEST 29: string& ShoppingList::setItem(0) EXCEPTION HANDLING #\n";
        }
    } catch(bool b) {
        cout << "# FAILED TEST 29: string& ShoppingList::setItem(0) EXCEPTION HANDLING #\n";
    }

    try {
        btassert<bool>(myList->getMaxItems() == 5);
        cout << "Passed TEST 30: ShoppingList::getMaxItems () \n";
    } catch (bool b) {
        cout << "# FAILED TEST 30: ShoppingList::getMaxItems () #\n";
    }

    cout << "\nUNIT TEST COMPLETE\n\n";
}
Ejemplo n.º 6
0
// For testing (DO NOT ALTER)
void UnitTest(int test) {
  string temp = "This unit test will test your code:\n";
  cout << temp << string(temp.length() - 1, '-') << endl;

  ShoppingList* myList = new ShoppingList;
  cout << "* DEFAULT CONSTRUCTOR *\n\n";

  Test(myList->max_items() == 25, "max_items()");
  Test(myList->item_count() == 0, "item_count()");
  if (test == 1)
    myList->GetItem(0);
  Test(myList->AddItem("apples") == true, "AddItem(\"apples\")");
  Test(myList->item_count() == 1, "item_count()");
  Test(myList->GetItem(0) == "apples", "GetItem(0)");

  myList->GetItem(0) = "oranges";
  Test(myList->GetItem(0) == "oranges", "GetItem(0) = \"oranges\"");

  for (unsigned int i = 0; i < myList->max_items(); i++)
    myList->AddItem("grapes");

  Test(myList->item_count() == 25, "item_count() - Full List");
  Test(myList->AddItem("bananas") == false, "AddItem(\"bananas\")");
  Test(myList->max_items() == 25, "max_items()");
  if (test == 2)
    myList->GetItem(26);

  delete myList;
  myList = new ShoppingList(1);

  cout << "\n* OVERLOADED CONSTRUCTOR *\n\n";
  Test(myList->max_items() == 1, "max_items()");
  Test(myList->item_count() == 0, "item_count()");
  if (test == 3)
    myList->GetItem(0) = "oranges";
  Test(myList->AddItem("apples") == true, "AddItem(\"apples\")");
  Test(myList->item_count() == 1, "item_count()");
  Test(myList->GetItem(0) == "apples", "GetItem(0)");
  if (test == 4)
    myList->GetItem(1);

  cout << "\n* RESET FUNCTION *\n\n";
  if (test == 5)
    myList->Reset(0);

  myList->Reset(5);
  Test(myList->max_items() == 5, "max_items() - Reset to 5");
  Test(myList->item_count() == 0, "item_count()");
  if (test == 6)
    myList->GetItem(6);

  for (unsigned int i = 0; i < myList->max_items(); i++)
    myList->AddItem("grapes");
  Test(myList->item_count() == 5, "item_count() - Full List");
  Test(myList->AddItem("bananas") == false, "AddItem(\"bananas\")");
  Test(myList->max_items() == 5, "max_items()");

  cout << string(temp.length() - 1, '-') << endl;
  cout << "Unit Test Complete!\n\n";
}
Ejemplo n.º 7
0
void unittest () {

    unsigned short utCount = 15;
    unsigned short utPassed = 0;

    cout << "\nSTARTING UNIT TEST\n\n";

    ShoppingList myList;

    try {
        btassert<bool>(myList.getMaxItems() == 10);
        cout << "Passed TEST 1: ShoppingList::getMaxItems () \n";
        ++utPassed;
    } catch (bool b) {
        cout << "# FAILED TEST 1: ShoppingList::getMaxItems () #\n";
    }

    try {
        btassert<bool>(myList.getItemCount() == 0);
        cout << "Passed TEST 2: ShoppingList::getItemCount () \n";
        ++utPassed;
    } catch (bool b) {
        cout << "# FAILED TEST 2: ShoppingList::getItemCount () #\n";
    }

    try {
        myList.getItem(0);
        btassert<bool>(false);
    } catch (ArrayException e) {
        try {
            btassert<bool>(e.message == "INVALID ARRAY INDEX");
            cout << "Passed TEST 3: ShoppingList::getItem(0) EXCEPTION HANDLING \n";
            ++utPassed;
        } catch (bool b) {
            cout << "# FAILED TEST 3: ShoppingList::getItem(0) EXCEPTION HANDLING #\n";
        }
    } catch(bool b) {
        cout << "# FAILED TEST 3: ShoppingList::getItem(0) EXCEPTION HANDLING #\n";
    }

    try {
        btassert<bool>(myList.addItem("apples") == true);
        cout << "Passed TEST 4: ShoppingList::addItem(\"apples\") \n";
        ++utPassed;
    } catch (bool b) {
        cout << "# FAILED TEST 4: ShoppingList::addItem(\"apples\") #\n";
    }

    try {
        btassert<bool>(myList.getItemCount() == 1);
        cout << "Passed TEST 5: ShoppingList::getItemCount () \n";
        ++utPassed;
    } catch (bool b) {
        cout << "# FAILED TEST 5: ShoppingList::getItemCount () #\n";
    }

    try {
        btassert<bool>(myList.getItem(0) == "apples");
        cout << "Passed TEST 6: ShoppingList::getItem(0) \n";
        ++utPassed;
    } catch (bool b) {
        cout << "# FAILED TEST 6: ShoppingList::getItem(0) #\n";
    }

    myList.getItem(0) = "oranges";
    try {
        btassert<bool>(myList.getItem(0) == "oranges");
        cout << "Passed TEST 7: string& ShoppingList::getItem(0) \n";
        ++utPassed;
    } catch (bool b) {
        cout << "# FAILED TEST 7: string& ShoppingList::getItem(0) #\n";
    }

    try {
        btassert<bool>(myList.removeItem(0) == "oranges");
        cout << "Passed TEST 8: ShoppingList::removeItem(0) \n";
        ++utPassed;
    } catch (bool b) {
        cout << "# FAILED TEST 8: ShoppingList::removeItem(0) #\n";
    }
    
    try {
        btassert<bool>(myList.getItemCount() == 0);
        cout << "Passed TEST 9: ShoppingList::getItemCount () \n";
        ++utPassed;
    } catch (bool b) {
        cout << "# FAILED TEST 9: ShoppingList::getItemCount () #\n";
    }

    for (unsigned int i=0; i<myList.getMaxItems(); i++)
        myList.addItem("grapes");

    try {
        btassert<bool>(myList.getItemCount() == 10);
        cout << "Passed TEST 10: ShoppingList::getItemCount () \n";
        ++utPassed;
    } catch (bool b) {
        cout << "# FAILED TEST 10: ShoppingList::getItemCount () #\n";
    }

    try {
        myList.getItem(11);
        btassert<bool>(false);
    } catch (ArrayException e) {
        try {
            btassert<bool>(e.message == "INVALID ARRAY INDEX");
            cout << "Passed TEST 11: ShoppingList::getItem(11) EXCEPTION HANDLING \n";
            ++utPassed;
        } catch (bool b) {
            cout << "# FAILED TEST 11: ShoppingList::setItem(11) EXCEPTION HANDLING #\n";
        }
    } catch (bool b) {
        cout << "# FAILED TEST 11: ShoppingList::setItem(11) EXCEPTION HANDLING #\n";
    }

    try {
        btassert<bool>(myList.addItem("bananas") == false);
        cout << "Passed TEST 12: ShoppingList::addItem(\"bananas\") \n";
        ++utPassed;
    } catch (bool b) {
        cout << "# FAILED TEST 12: ShoppingList::getItem(\"bananas\") #\n";
    }

    unsigned int itemsToRemove = myList.getItemCount();
    for (unsigned int i=0; i<itemsToRemove; i++)
        myList.removeItem(0);

    try {
        btassert<bool>(myList.getItemCount() == 0);
        cout << "Passed TEST 13: ShoppingList::getItemCount () \n";
        ++utPassed;
    } catch (bool b) {
        cout << "# FAILED TEST 13: ShoppingList::getItemCount () #\n";
    }

    try {
        myList.getItem(0) = "oranges";
        btassert<bool>(false);
    } catch (ArrayException e) {
        try {
            btassert<bool>(e.message == "INVALID ARRAY INDEX");
            cout << "Passed TEST 14: string& ShoppingList::getItem(0) EXCEPTION HANDLING \n";
            ++utPassed;
        } catch (bool b) {
            cout << "# FAILED TEST 14: string& ShoppingList::setItem(0) EXCEPTION HANDLING #\n";
        }
    } catch (bool b) {
        cout << "# FAILED TEST 14: string& ShoppingList::setItem(0) EXCEPTION HANDLING #\n";
    }

    try {
        btassert<bool>(myList.getMaxItems() == 10);
        cout << "Passed TEST 15: ShoppingList::getMaxItems () \n";
        ++utPassed;
    } catch (bool b) {
        cout << "# FAILED TEST 15: ShoppingList::getMaxItems () #\n";
    }

    cout << "\nUNIT TEST COMPLETE\n\n";
    
    cout << "PASSED " << utPassed << " OF " << utCount << " UNIT TEST";
    if (utCount > 1) {
        cout << "S";
    }
    cout << "\n\n";
}