Example #1
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());
}
Example #2
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);
}
Example #3
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());
}
Example #4
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));
}
Example #5
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));
}
Example #6
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());
}