Ejemplo n.º 1
0
TEST(VectorMapTest, InsertTest)
{
	Vec v;
	ASSERT_TRUE(v.empty());
	ASSERT_EQ(0, v.size());
	v.insert(10, 1);
	ASSERT_TRUE(v.end() != v.find(10));
	Pair const& p = *(v.find(10));
	ASSERT_EQ(1, p.second);
}
Ejemplo n.º 2
0
TEST(VectorMapTest, UpdateTest)
{
	Vec v;
	ASSERT_TRUE(v.empty());
	ASSERT_EQ(0, v.size());
	ASSERT_FALSE( v.update(10, 1) );
	ASSERT_TRUE( v.update(10, 1) );
	Pair const& p = *(v.find(10));
	ASSERT_EQ(1, p.second);
	ASSERT_TRUE( v.update(10, 2) );
	Pair const& p2 = *(v.find(10));
	ASSERT_EQ(2, p2.second);
	ASSERT_EQ(1, v.size());
}
Ejemplo n.º 3
0
TEST(VectorMapTest, EmptyTest)
{
	Vec v;
	ASSERT_TRUE(v.empty());
	ASSERT_EQ(0, v.size());
	ASSERT_TRUE(v.end() == v.find(10));
}
Ejemplo n.º 4
0
TEST(VectorMapTest, EraseTest)
{
	Vec v;
	ASSERT_TRUE(v.empty());
	ASSERT_EQ(0, v.size());
	ASSERT_FALSE(v.remove(10));
	v.insert(10, 1);
	v.insert(11, 2);
	ASSERT_TRUE(v.end() != v.find(10));
	{
		Pair const& p = *(v.find(10));
		ASSERT_EQ(1, p.second);
	}
	{
		Pair const& p = *(v.erase( v.find(10) ));
		ASSERT_EQ(2, p.second);
	}
}
Ejemplo n.º 5
0
 static double mult(Vec& u, Vec& v)
 {
   double s = 0.;
   Vec::const_iterator it = u.begin();
   for(;it != u.end(); it ++) {
     const unsigned int i = it->first;
     if(v.find(i) != v.end()) {
       double t = it->second;
       s += t * v[i];
     }
   }
   return s;  
 }
Ejemplo n.º 6
0
//! Add given item to the tail end only if it's unique. Use given comparison
//! function to compare items. Return true if item was added successful. Return
//! false otherwise (vector is full or item already exists).
inline bool RefVec::addIfNotFound(item_t item, diff_t diff)
{
    size_t foundIndex;
    bool ok = find(item, diff, foundIndex)? false: add(item);
    return ok;
}