#include "mqueue.h" #include <sstream> #include <random> class Tester { private: static…
- User
#include "mqueue.h" #include #include
class Tester { private: static int getImportance(const Order& order) { return order.getImportance(); } Order genRandomOrder();
public: bool testConstructor(); bool testCopyConstructor(); bool testCopyConstructorEmpty(); bool testCopyConstructorNotEmpty(); bool testDestructor();
};
//Main function to run tests in int main() { Tester tester; bool constructorResult = tester.testConstructor(); cout << (constructorResult ? "Constructor test passed\n" : "Constructor test failed\n") << endl; bool copyConstructorResult = tester.testCopyConstructor(); cout << (copyConstructorResult ? "Copy constructor test passed\n" : "Copy constructor test failed\n") << endl; bool copyConstructorEmptyResult = tester.testCopyConstructorEmpty(); cout << (copyConstructorEmptyResult ? "Copy constructor empty test passed\n" : "Copy constructor empty test failed\n") << endl; bool copyConstructorNotEmptyResult = tester.testCopyConstructorNotEmpty(); cout << (copyConstructorNotEmptyResult ? "Copy constructor not empty test passed\n" : "Copy constructor not empty test failed\n") << endl; bool destructorResult = tester.testDestructor(); cout << (destructorResult ? "Destructor test passed\n" : "Destructor test failed\n") << endl; }
bool Tester::testConstructor() { // Create an MQueue instance with specific heap type and structure MQueue testQueue(getImportance, MINHEAP, LEFTIST);
// Check initial conditions for MQueue bool CorrectPrioFn = (testQueue.getPriorityFn() == getImportance); bool CorrectHeapType = (testQueue.getHeapType() == MINHEAP); bool CorrectStructure = (testQueue.getStructure() == LEFTIST); bool isEmpty = (testQueue.numOrders() == 0); // Return true if all conditions pass false otherwise return CorrectPrioFn && CorrectHeapType && CorrectStructure && isEmpty;}
bool Tester::testCopyConstructor() { // Create an MQueue instance with specific heap type and structure MQueue testQueue(getImportance, MINHEAP, LEFTIST);
// Insert some orders into the original queue for (int i = 0; i < 50; i++) { Order randomOrder = genRandomOrder(); testQueue.insertOrder(randomOrder); cout << "Order inserted: " << randomOrder << endl; } // Create a copy of the original queue using the copy constructor MQueue copiedQueue(testQueue); // Verify that the copied queue has the same state as the original queue bool SamePrioFn = (copiedQueue.getPriorityFn() == testQueue.getPriorityFn()); bool SameHeapType = (copiedQueue.getHeapType() == testQueue.getHeapType()); bool SameStructure = (copiedQueue.getStructure() == testQueue.getStructure()); bool SameNumOrders = (copiedQueue.numOrders() == testQueue.numOrders()); //testQueue.dump(); // Return true if all conditions pass false otherwise return SamePrioFn && SameHeapType && SameStructure && SameNumOrders;}
bool Tester::testCopyConstructorEmpty() { //Create an Mqueue instance with specific heap type and structure MQueue testQueue(getImportance, MINHEAP, SKEW);
- Assistant
- User
is there a simplier way to fix this? if i want to retain everything within the randomOrder function
- Assistant
- User
But these are not truly random are they
- Assistant
The randomness provided by
std::mt19937andstd::random_devicein C++ is pseudo-random rather than truly random. Let me explain the terminology and the potential implications: