Question: Need help with running tests C + + code Step 5 : Run tests TreeTestCommand is an abstract base class defined in TreeCommands.h . A
Need help with running tests C code
Step : Run tests
TreeTestCommand is an abstract base class defined in TreeCommands.h A TreeTestCommand object is an executable command that operates on a binary search tree. Classes inheriting from TreeTestCommand are also declared in TreeCommands.h:
TreeInsertCommand inserts keys into the tree
TreeRemoveCommand removes keys from the tree
TreeVerifyKeysCommand verifies the tree's keys using an inorder traversal
TreeVerifySubtreeCountsCommand verifies that each node in the tree has the expected subtree key count
TreeGetNthCommand verifies that GetNthKey returns an expected value
Code in main.cpp contains three automated test cases. Each test executes a vector of TreeTestCommand objects in sequence. The third test includes TreeGetNthCommands and will not pass until the completion of Step The first two tests should pass after completion of step
Before proceeding to Step verify that the first two tests in main.cpp pass. Then submit code and ensure that the first two unit tests pass.
Having test and Unit Test errors. Here is the error code:
usercoderuncodingroomsunittests.sh: line : Segmentation fault core dumpedaout
#ifndef EXTENDEDAVLNODEH
#define EXTENDEDAVLNODEH
#include "AVLNode.h
#include
class ExtendedAVLNode : public AVLNode
private:
int subtreeKeyCount;
public:
ExtendedAVLNodeint nodeKey : AVLNodenodeKey
subtreeKeyCount ;
std::cout "Node created with key: nodeKey std::endl;
int GetSubtreeKeyCount
return subtreeKeyCount;
void UpdateSubtreeKeyCount
int leftCount GetLeftExtendedAVLNodeGetLeftGetSubtreeKeyCount : ;
int rightCount GetRightExtendedAVLNodeGetRightGetSubtreeKeyCount : ;
subtreeKeyCount leftCount rightCount;
std::cout "Updated subtreeKeyCount for node GetKey: subtreeKeyCount std::endl;
virtual void SetLeftBSTNode newLeftChild override
std::cout "Setting left child for node GetKey std::endl;
AVLNode::SetLeftnewLeftChild;
UpdateSubtreeKeyCount;
std::cout "Set left child for node GetKey std::endl;
virtual void SetRightBSTNode newRightChild override
std::cout "Setting right child for node GetKey std::endl;
AVLNode::SetRightnewRightChild;
UpdateSubtreeKeyCount;
std::cout "Set right child for node GetKey std::endl;
;
#endif EXTENDEDAVLNODE
#ifndef EXTENDEDAVLTREEH
#define EXTENDEDAVLTREEH
#include "AVLTree.h
#include "ExtendedAVLNode.h
#include
class ExtendedAVLTree : public AVLTree
protected:
virtual BSTNode MakeNewNodeint key override
std::cout "Creating new node with key: key std::endl;
return new ExtendedAVLNodekey;
virtual void InsertNodeBSTNode node override
std::cout "Inserting node with key: nodeGetKey std::endl;
AVLTree::InsertNodenode;
UpdateSubtreeKeyCountsExtendedAVLNodenode;
virtual bool RemoveNodeBSTNode nodeToRemove override
std::cout "Removing node with key: nodeToRemoveGetKey std::endl;
bool result AVLTree::RemoveNodenodeToRemove;
if result
ExtendedAVLNode parent ExtendedAVLNodenodeToRemoveGetParent;
if parent
std::cout "Updating subtree key counts starting from parent node with key: parentGetKey std::endl;
UpdateSubtreeKeyCountsparent;
else
std::cout "Removed node was the root." std::endl;
return result;
void UpdateSubtreeKeyCountsExtendedAVLNode node
while node
nodeUpdateSubtreeKeyCount;
node ExtendedAVLNodenodeGetParent;
public:
virtual int GetNthKeyint n override
std::cout "Getting the n th key" std::endl;
return GetNthKeyHelperExtendedAVLNoderoot n;
private:
int GetNthKeyHelperExtendedAVLNode node, int n
if node throw std::outofrangeIndex out of range";
int leftCount nodeGetLeftExtendedAVLNodenodeGetLeftGetSubtreeKeyCount : ;
if n leftCount
return GetNthKeyHelperExtendedAVLNodenodeGetLeft n;
else if n leftCount
return nodeGetKey;
else
return GetNthKeyHelperExtendedAVLNodenodeGetRight n leftCount ;
;
#endif
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
