Hi Team
I have a class that uses std::map, but i am struggling to create a test function that will test my logic scenario. The scenario is i have implemented a logic to function called void assign that loop through value associate with it and does not duplicate it.
How to i then create a test function from my class to test this scenario using c++?
`class interval_map {
    friend void IntervalMapTest();
    V m_valBegin;
    typedef std::map m_map;
public:
interval_map(V const& val)
: m_valBegin(val)
{}
void assign( K const& keyBegin, K const& keyEnd, V const& val )
{
    for( auto it = m_map.find( keyBegin ); * it != keyEnd; ++it )
    {
        * it = val;
    }
}
// look-up of the value associated with key
V const& operator[]( K const& key ) const {
    auto it=m_map.upper_bound(key);
    if(it==m_map.begin()) {
        return m_valBegin;
    } else {
        return (--it)->second;
    }
}
};
int main()
{
    m_map map;
    m_map::iterator mpIter;
int keyEnd, keyBegin;
int count;
// keep track of values with a std::set
std::set<std::string> values;
for(count = 0; count < 3; count++)
{
    cin >> key;
    cin >> value;
    auto found = map.find(key);
    if(found != map.end()) // key already in map
        continue; // don't add it again
}
return 0;
}`
    
Top comments (0)