Question: Can I get some advice about how should I solve this problem, I really have no idea what's been causing the issue from passing these

Can I get some advice about how should I solve this problem, I really have no idea what's been causing the issue from passing these tests.
So here's the test result message:
TestMap::test_access_standardLeftRead()
line:1603 condition:s == int(30)
line:1608 condition:m.bst.numElements ==3
line:1608 condition:m.bst.root->pLeft->pRight == nullptr
TestMap::test_access_standardLeftWrite()
line:1690 condition:m.bst.root->pLeft->data.second == int(33)
line:1693 condition:m.bst.numElements ==3
line:1693 condition:m.bst.root->pLeft->pRight == nullptr
TestMap::test_access_standardRightRead()
line:1627 condition:s == int(70)
line:1632 condition:m.bst.numElements ==3
line:1632 condition:m.bst.root->pRight->pRight == nullptr
TestMap::test_access_standardRightWrite()
line:1721 condition:m.bst.root->pRight->data.second == int(77)
line:1724 condition:m.bst.numElements ==3
line:1724 condition:m.bst.root->pRight->pRight == nullptr
TestMap::test_access_standardRootRead()
line:1579 condition:s == int(50)
line:1584 condition:m.bst.numElements ==3
line:1584 condition:m.bst.root->pRight->pLeft == nullptr
TestMap::test_access_standardRootWrite()
line:1659 condition:m.bst.root->data.second == int(55)
line:1662 condition:m.bst.numElements ==3
line:1662 condition:m.bst.root->pRight->pLeft == nullptr
And here's the code I think that need to improve:
/*****************************************************
* MAP :: ACCESS
****************************************************/
template
const V& map::operator[](const K& k) const
{
auto it = bst.find(Pairs(k, V()));
if (it == bst.end())
throw std::out_of_range("invalid map key");
return (*it).second;
}
template
V& map::operator[](const K& k)
{
auto result = bst.insert(Pairs(k, V()));
return const_cast((*result.first).second);
}
template
const V& map::at(const K& k) const
{
auto it = bst.find(Pairs(k, V()));
if (it == bst.end())
throw std::out_of_range("invalid map key");
return it.operator*().second;
}
template
V& map::at(const K& k)
{
auto it = bst.find(Pairs(k, V()));
if (it == bst.end())
throw std::out_of_range("invalid map key");
return const_cast(it.operator*().second);
}
template
typename map::iterator map::find(const K& k)
{
return iterator(bst.find(Pairs(k, V())));
}
/*****************************************************
* MAP :: INSERT
****************************************************/
template
custom::pair::iterator, bool> map::insert(const Pairs& rhs)
{
auto result = bst.insert(rhs);
return custom::pair(iterator(result.first), result.second);
}
template
custom::pair::iterator, bool> map::insert(Pairs&& rhs)
{
auto result = bst.insert(std::move(rhs));
return custom::pair(iterator(result.first), result.second);
}
template
template
void map::insert(Iterator first, Iterator last)
{
for (auto it = first; it != last; ++it)
bst.insert(*it);
}
template
void map::insert(const std::initializer_list & il)
{
insert(il.begin(), il.end());
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!