Esempio n. 1
0
TEST_F(HashTableTest, operator_subscript_read)
{
    Int32HashMap newmap;
    newmap.put(1, 5);
    capu::int32_t val = newmap[1];
    EXPECT_EQ(5, val);

    // non trivial object
    SomeHashMap newmap2;
    newmap2.put(1, 5);
    SomeClass val2 = newmap2[1];
    EXPECT_EQ(5u, val2.i);

    EXPECT_FALSE(newmap2.contains(5));

    // not existing non trivial object must return default constructed reference
    SomeClass& val3 = newmap2[5];
    EXPECT_EQ(0u, val3.i);

    // key must also be contained in the hash map now
    EXPECT_TRUE(newmap2.contains(5));

    // change val3 and test again
    val3.i = 42u;
    SomeClass val4 = newmap2[5];
    EXPECT_EQ(42u, val4.i);

    newmap2[7].i = 55u;
    EXPECT_EQ(55u, newmap2[7].i);
}
Esempio n. 2
0
TEST_F(HashTableTest, find)
{
    Int32HashMap newmap;
    EXPECT_EQ(newmap.end(), newmap.find(4));
    newmap.put(1, 5);
    EXPECT_EQ(5, (*newmap.find(1)).value);
}
Esempio n. 3
0
TEST_F(HashTableTest, TestClear)
{
    Int32HashMap newmap;

    newmap.put(1, 10);
    newmap.put(2, 20);
    newmap.put(3, 30);

    newmap.clear();
    EXPECT_EQ(static_cast<capu::uint32_t>(0), newmap.count());

    capu::status_t ret = 0;
    capu::int32_t value = newmap.at(1, &ret);
    EXPECT_EQ(capu::CAPU_ENOT_EXIST, ret);
    EXPECT_EQ(0, value);

    value = newmap.at(2, &ret);
    EXPECT_EQ(capu::CAPU_ENOT_EXIST, ret);
    EXPECT_EQ(0, value);

    value = newmap.at(3, &ret);
    EXPECT_EQ(capu::CAPU_ENOT_EXIST, ret);
    EXPECT_EQ(0, value);

    newmap.put(1, 10);
    value = newmap.at(1, &ret);
    EXPECT_EQ(capu::CAPU_OK, ret);
    EXPECT_EQ(10, value);
}
Esempio n. 4
0
TEST_F(HashTableTest, ForEach)
{
    Int32HashMap hashMap;

    hashMap.put(32,33);
    hashMap.put(43,44);
    hashMap.put(44,45);

    Int32HashMap someHashMap;

    capu_foreach(Int32HashMap, hashMap, iter)
    {
        someHashMap.put(iter->key, iter->value);
    }
Esempio n. 5
0
TEST_F(HashTableTest, TestWildRemoving)
{
    Int32HashMap newmap;

    for (int i = 0; i < 1000; i++)
    {
        newmap.put(i, i % 10);
    }

    // this will create a 'wild' chain of free elements
    // with free gaps of entries of the memory block of the map
    for (int i = 999; i >= 0; i -= 2)
    {
        newmap.remove(i);
    }

    // now fill up the gaps
    for (int i = 1; i < 1000; i += 2)
    {
        newmap.put(i, i % 10);
    }

    for (int i = 0; i < 1000; i += 2)
    {
        newmap.put(i, i % 10);
    }

    newmap.put(2000, 2000); // TODO how to check that everything worked?
    EXPECT_EQ(static_cast<capu::uint32_t>(1001), newmap.count());
}
Esempio n. 6
0
TEST_F(HashTableTest, TestRemove)
{
    Int32HashMap newmap;

    newmap.put(1, 10);
    newmap.put(2, 20);
    newmap.put(3, 30);
    EXPECT_EQ(3u, newmap.count());

    capu::status_t removeResult = newmap.remove(2);
    EXPECT_EQ(capu::CAPU_OK, removeResult);
    EXPECT_EQ(2u, newmap.count());

    EXPECT_EQ(0, newmap.at(2));

    capu::int32_t value;
    removeResult = newmap.remove(3, &value);
    EXPECT_EQ(capu::CAPU_OK, removeResult);
    EXPECT_EQ(1u, newmap.count());
    EXPECT_EQ(30, value);

    EXPECT_EQ(0, newmap.at(2));
}
Esempio n. 7
0
TEST_F(HashTableTest, TestRemove1)
{
    Int32HashMap newmap;

    newmap.put(1, 10);
    newmap.remove(1);
    newmap.put(2, 10);

    Int32HashMap::Iterator it = newmap.begin();
    while (it != newmap.end())
    {
        it++;
    }
}
Esempio n. 8
0
TEST_F(HashTableTest, TestCopyConstructor)
{
    Int32HashMap map1;
    map1.put(1, 10);
    map1.put(2, 20);
    map1.put(3, 30);

    Int32HashMap newmap = map1; // copy operation

    EXPECT_EQ(map1.count(), newmap.count());
    EXPECT_TRUE(newmap.contains(1));
    EXPECT_TRUE(newmap.contains(2));
    EXPECT_TRUE(newmap.contains(3));

    // Test remove
    map1.remove(1);
    newmap.remove(2);

    EXPECT_TRUE(newmap.contains(1));
    EXPECT_FALSE(map1.contains(1));
    EXPECT_TRUE(map1.contains(2));
    EXPECT_FALSE(newmap.contains(2));

    // Test put
    map1.put(10, 10);
    newmap.put(20, 20);
    EXPECT_TRUE(map1.contains(10));
    EXPECT_FALSE(newmap.contains(10));
    EXPECT_TRUE(newmap.contains(20));
    EXPECT_FALSE(map1.contains(20));

    // Test clear
    map1.clear();
    EXPECT_EQ(static_cast<capu::uint32_t>(0), map1.count());
    EXPECT_TRUE(newmap.contains(20));
}
Esempio n. 9
0
TEST_F(HashTableTest, TestAddGet)
{
    Int32HashMap newmap;
    const Int32HashMap& newConstMap(newmap);

    EXPECT_EQ(0u, newmap.count());

    capu::status_t returnCode = newmap.put(1, 10);
    EXPECT_EQ(capu::CAPU_OK, returnCode);

    returnCode = newmap.put(2, 20);
    EXPECT_EQ(capu::CAPU_OK, returnCode);

    returnCode = newmap.put(3, 30);
    EXPECT_EQ(capu::CAPU_OK, returnCode);

    EXPECT_EQ(3u, newmap.count());

    EXPECT_EQ(10, newConstMap.at(1, &returnCode));
    EXPECT_EQ(capu::CAPU_OK, returnCode);

    EXPECT_EQ(10, newmap.at(1, &returnCode));
    EXPECT_EQ(capu::CAPU_OK, returnCode);

    EXPECT_EQ(20, newmap.at(2, &returnCode));
    EXPECT_EQ(capu::CAPU_OK, returnCode);

    EXPECT_EQ(30, newmap.at(3, &returnCode));
    EXPECT_EQ(capu::CAPU_OK, returnCode);

    newmap.remove(1);

    newmap.at(1, &returnCode);
    EXPECT_EQ(capu::CAPU_ENOT_EXIST, returnCode);

    EXPECT_EQ(20, newmap.at(2, &returnCode));
    EXPECT_EQ(capu::CAPU_OK, returnCode);

    EXPECT_EQ(30, newmap.at(3, &returnCode));
    EXPECT_EQ(capu::CAPU_OK, returnCode);

    EXPECT_EQ(2u, newmap.count());

    newmap.remove(2);

    newmap.at(1, &returnCode);
    EXPECT_EQ(capu::CAPU_ENOT_EXIST, returnCode);

    newmap.at(2, &returnCode);
    EXPECT_EQ(capu::CAPU_ENOT_EXIST, returnCode);

    EXPECT_EQ(30, newmap.at(3, &returnCode));
    EXPECT_EQ(capu::CAPU_OK, returnCode);

    EXPECT_EQ(1u, newmap.count());

    newmap.remove(3);

    newmap.at(1, &returnCode);
    EXPECT_EQ(capu::CAPU_ENOT_EXIST, returnCode);

    newmap.at(2, &returnCode);
    EXPECT_EQ(capu::CAPU_ENOT_EXIST, returnCode);

    newmap.at(3, &returnCode);
    EXPECT_EQ(capu::CAPU_ENOT_EXIST, returnCode);

    EXPECT_EQ(0u, newmap.count());
}
Esempio n. 10
0
TEST_F(HashTableTest, IteratorRemove)
{
    Int32HashMap newmap;

    newmap.put(0, 12);
    newmap.put(3, 10);
    newmap.put(2, 11);

    for (Int32HashMap::Iterator iter = newmap.begin(); iter != newmap.end();)
    {
        newmap.remove(iter);
    }

    EXPECT_EQ(0u, newmap.count());
    capu::status_t ret = 0;

    newmap.at(0, &ret);
    EXPECT_EQ(capu::CAPU_ENOT_EXIST, ret);
    newmap.at(2, &ret);
    EXPECT_EQ(capu::CAPU_ENOT_EXIST, ret);
    newmap.at(3, &ret);
    EXPECT_EQ(capu::CAPU_ENOT_EXIST, ret);

    newmap.put(0, 12);
    newmap.put(3, 10);
    newmap.put(2, 11);

    Int32HashMap::Iterator iter2 = newmap.begin();
    capu::int32_t expectedValue = iter2->value;
    capu::int32_t oldValue = 0;
    newmap.remove(iter2, &oldValue);
    EXPECT_EQ(expectedValue, oldValue);

    while (iter2 != newmap.end())
    {
        newmap.remove(iter2);
    }

    EXPECT_EQ(0u, newmap.count());
}
Esempio n. 11
0
TEST_F(HashTableTest, TestContains)
{
    Int32HashMap newmap;
    EXPECT_FALSE(newmap.contains(1));
    EXPECT_FALSE(newmap.contains(2));
    EXPECT_FALSE(newmap.contains(3));

    newmap.put(1, 10);
    EXPECT_TRUE(newmap.contains(1));
    EXPECT_FALSE(newmap.contains(2));
    EXPECT_FALSE(newmap.contains(3));

    newmap.put(2, 20);
    EXPECT_TRUE(newmap.contains(1));
    EXPECT_TRUE(newmap.contains(2));
    EXPECT_FALSE(newmap.contains(3));

    newmap.put(3, 30);
    EXPECT_TRUE(newmap.contains(1));
    EXPECT_TRUE(newmap.contains(2));
    EXPECT_TRUE(newmap.contains(3));

    newmap.clear();
    EXPECT_FALSE(newmap.contains(1));
    EXPECT_FALSE(newmap.contains(2));
    EXPECT_FALSE(newmap.contains(3));
}