当前位置: 首页>>代码示例>>C++>>正文


C++ LinkedHashMap类代码示例

本文整理汇总了C++中LinkedHashMap的典型用法代码示例。如果您正苦于以下问题:C++ LinkedHashMap类的具体用法?C++ LinkedHashMap怎么用?C++ LinkedHashMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了LinkedHashMap类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: testContainsValue

void LinkedHashMapTest::testContainsValue() {

    LinkedHashMap<int, std::string> hashMap;

    hashMap.put(876, "test");

    CPPUNIT_ASSERT_MESSAGE("Returned false for valid value", hashMap.containsValue("test"));
    CPPUNIT_ASSERT_MESSAGE("Returned true for invalid valie", !hashMap.containsValue(""));
}
开发者ID:apache,项目名称:activemq-cpp,代码行数:9,代码来源:LinkedHashMapTest.cpp

示例2: TEST

TEST(LinkedHashmapTest, Contains)
{
  LinkedHashMap<string, int> map;
  map["foo"] = 1;
  map["bar"] = 2;
  ASSERT_TRUE(map.contains("foo"));
  ASSERT_TRUE(map.contains("bar"));
  ASSERT_FALSE(map.contains("caz"));
}
开发者ID:AsylumCorp,项目名称:mesos,代码行数:9,代码来源:linkedhashmap_tests.cpp

示例3: populateMap

void LinkedHashMapTest::testOrderedEntrySet() {

    int i;
    int size = 100;

    {
        LinkedHashMap<int, std::string> map;
        populateMap(map, size);

        Set<MapEntry<int, std::string> >& set = map.entrySet();
        Pointer< Iterator<MapEntry<int, std::string> > > iter(set.iterator());
        CPPUNIT_ASSERT_MESSAGE("Returned set of incorrect size 1", map.size() == set.size());
        for (i = 0; iter->hasNext(); i++) {
            MapEntry<int, std::string> entry = iter->next();
            int key = entry.getKey();
            CPPUNIT_ASSERT_MESSAGE("Returned incorrect entry set 1", key == i);
        }
    }

    LinkedHashMap<int, std::string> map2(200, .75f, true);
    populateMap(map2, size);

    Set<MapEntry<int, std::string> >& set = map2.entrySet();
    Pointer< Iterator<MapEntry<int, std::string> > > iter(set.iterator());
    CPPUNIT_ASSERT_MESSAGE("Returned set of incorrect size 2", map2.size() == set.size());
    for (i = 0; i < size && iter->hasNext(); i++) {
        MapEntry<int, std::string> entry = iter->next();
        int key = entry.getKey();
        CPPUNIT_ASSERT_MESSAGE("Returned incorrect entry set 2", key == i);
    }

    /* fetch the even numbered entries to affect traversal order */
    int p = 0;
    for (i = 0; i < size; i += 2) {
        std::string ii = map2.get(i);
        p = p + Integer::parseInt(ii);
    }
    CPPUNIT_ASSERT_EQUAL_MESSAGE("invalid sum of even numbers", 2450, p);

    set = map2.entrySet();
    iter.reset(set.iterator());
    CPPUNIT_ASSERT_MESSAGE("Returned set of incorrect size 3", map2.size() == set.size());
    for (i = 1; i < size && iter->hasNext(); i += 2) {
        MapEntry<int, std::string> entry = iter->next();
        int key = entry.getKey();
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Returned incorrect entry set 3", key, i);
    }
    for (i = 0; i < size && iter->hasNext(); i += 2) {
        MapEntry<int, std::string> entry = iter->next();
        int key = entry.getKey();
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Returned incorrect entry set 4", key, i);
    }
    CPPUNIT_ASSERT_MESSAGE("Entries left to iterate on", !iter->hasNext());
}
开发者ID:apache,项目名称:activemq-cpp,代码行数:54,代码来源:LinkedHashMapTest.cpp

示例4: testGet

void LinkedHashMapTest::testGet() {

    LinkedHashMap<int, std::string> hashMap;

    CPPUNIT_ASSERT_THROW_MESSAGE(
            "Should have thrown NoSuchElementException",
            hashMap.get(1),
            NoSuchElementException);
    hashMap.put(22, "HELLO");
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Get returned incorrect value for existing key",
                                 std::string("HELLO"), hashMap.get(22));
}
开发者ID:apache,项目名称:activemq-cpp,代码行数:12,代码来源:LinkedHashMapTest.cpp

示例5: iter

void LinkedHashMapTest::testOrderedValues() {

    int i;
    int size = 100;

    {
        LinkedHashMap<int, int> map;
        for (i = 0; i < size; i++) {
            map.put(i, i * 2);
        }

        Collection<int>& set = map.values();
        Pointer< Iterator<int> > iter(set.iterator());
        CPPUNIT_ASSERT_MESSAGE("Returned set of incorrect size 1", map.size() == set.size());
        for (i = 0; iter->hasNext(); i++) {
            int value = iter->next();
            CPPUNIT_ASSERT_EQUAL_MESSAGE("Returned incorrect values set 1", value, i * 2);
        }
    }

    LinkedHashMap<int, int> map2(200, .75f, true);
    for (i = 0; i < size; i++) {
        map2.put(i, i * 2);
    }

    Collection<int>& set = map2.values();
    Pointer< Iterator<int> > iter(set.iterator());
    CPPUNIT_ASSERT_MESSAGE("Returned set of incorrect size 2", map2.size() == set.size());
    for (i = 0; i < size && iter->hasNext(); i++) {
        int value = iter->next();
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Returned incorrect values set 2", value, i * 2);
    }

    /* fetch the even numbered entries to affect traversal order */
    int p = 0;
    for (i = 0; i < size; i += 2) {
        p = p + map2.get(i);
    }
    CPPUNIT_ASSERT_EQUAL_MESSAGE("invalid sum of even numbers", 2450 * 2, p);

    set = map2.values();
    iter.reset(set.iterator());
    CPPUNIT_ASSERT_MESSAGE("Returned set of incorrect size 3", map2.size() == set.size());
    for (i = 1; i < size && iter->hasNext(); i += 2) {
        int value = iter->next();
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Returned incorrect values set 3", value, i * 2);
    }
    for (i = 0; i < size && iter->hasNext(); i += 2) {
        int value = iter->next();
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Returned incorrect values set 4", value, i * 2);
    }
    CPPUNIT_ASSERT_MESSAGE("Entries left to iterate on", !iter->hasNext());
}
开发者ID:apache,项目名称:activemq-cpp,代码行数:53,代码来源:LinkedHashMapTest.cpp

示例6: hashMap

void LinkedHashMapTest::testConstructorMap() {

    LinkedHashMap<int, int> myMap;
    for (int counter = 0; counter < 125; counter++) {
        myMap.put(counter, counter);
    }

    LinkedHashMap<int, int> hashMap(myMap);
    for (int counter = 0; counter < 125; counter++) {
        CPPUNIT_ASSERT_MESSAGE("Failed to construct correct LinkedHashMap",
            myMap.get(counter) == hashMap.get(counter));
    }
}
开发者ID:apache,项目名称:activemq-cpp,代码行数:13,代码来源:LinkedHashMapTest.cpp

示例7: CPPUNIT_ASSERT_MESSAGE

void LinkedHashMapTest::testContainsKey() {

    LinkedHashMap<int, std::string> hashMap;

    hashMap.put(876, "test");

    CPPUNIT_ASSERT_MESSAGE("Returned false for valid key", hashMap.containsKey(876));
    CPPUNIT_ASSERT_MESSAGE("Returned true for invalid key", !hashMap.containsKey(1));

    LinkedHashMap<int, std::string> hashMap2;
    hashMap2.put(0, "test");
    CPPUNIT_ASSERT_MESSAGE("Failed with key", hashMap2.containsKey(0));
    CPPUNIT_ASSERT_MESSAGE("Failed with missing key matching hash", !hashMap2.containsKey(1));
}
开发者ID:apache,项目名称:activemq-cpp,代码行数:14,代码来源:LinkedHashMapTest.cpp

示例8: TEST

TEST(LinkedHashmapTest, Keys)
{
  LinkedHashMap<string, int> map;

  list<string> keys = {"foo", "bar", "food", "rad", "cat"};

  // Insert keys into the map.
  foreach (const string& key, keys) {
    map[key] = 1;
  }
  map["foo"] = 1; // Re-insert a key.

  // Ensure the keys returned are the same as insertion order.
  ASSERT_EQ(keys, map.keys());
}
开发者ID:albertleecn,项目名称:mesos,代码行数:15,代码来源:linkedhashmap_tests.cpp

示例9: testValues

void LinkedHashMapTest::testValues() {

    LinkedHashMap<int, std::string> hashMap;
    populateMap(hashMap);

    Collection<std::string>& c = hashMap.values();
    CPPUNIT_ASSERT_MESSAGE("Returned collection of incorrect size()", c.size() == hashMap.size());
    for (int i = 0; i < MAP_SIZE; i++) {
        CPPUNIT_ASSERT_MESSAGE("Returned collection does not contain all keys",
                               c.contains(Integer::toString(i)));
    }

    c.remove("10");
    CPPUNIT_ASSERT_MESSAGE("Removing from collection should alter Map",
                           !hashMap.containsKey(10));
}
开发者ID:apache,项目名称:activemq-cpp,代码行数:16,代码来源:LinkedHashMapTest.cpp

示例10: testIsEmpty

void LinkedHashMapTest::testIsEmpty() {

    LinkedHashMap<int, std::string> hashMap;

    CPPUNIT_ASSERT_MESSAGE("Returned false for new map", hashMap.isEmpty());
    hashMap.put(1, "1");
    CPPUNIT_ASSERT_MESSAGE("Returned true for non-empty", !hashMap.isEmpty());
    hashMap.clear();
    CPPUNIT_ASSERT_MESSAGE("Returned false for cleared map", hashMap.isEmpty());
}
开发者ID:apache,项目名称:activemq-cpp,代码行数:10,代码来源:LinkedHashMapTest.cpp

示例11: testEntrySet

void LinkedHashMapTest::testEntrySet() {

    LinkedHashMap<int, std::string> hashMap;

    for (int i = 0; i < 50; i++) {
        hashMap.put(i, Integer::toString(i));
    }

    Set<MapEntry<int, std::string> >& set = hashMap.entrySet();
    Pointer< Iterator<MapEntry<int, std::string> > > iterator(set.iterator());

    CPPUNIT_ASSERT_MESSAGE("Returned set of incorrect size", hashMap.size() == set.size());
    while (iterator->hasNext()) {
        MapEntry<int, std::string> entry = iterator->next();
        CPPUNIT_ASSERT_MESSAGE("Returned incorrect entry set",
                               hashMap.containsKey(entry.getKey()) && hashMap.containsValue(entry.getValue()));
    }

    iterator.reset(set.iterator());
    set.remove(iterator->next());
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Remove on set didn't take", 49, set.size());
}
开发者ID:apache,项目名称:activemq-cpp,代码行数:22,代码来源:LinkedHashMapTest.cpp

示例12: CPPUNIT_ASSERT_EQUAL_MESSAGE

void LinkedHashMapTest::testClear() {

    LinkedHashMap<int, std::string> hashMap;
    hashMap.put(1, "one");
    hashMap.put(3, "three");
    hashMap.put(2, "two");

    hashMap.clear();
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Clear failed to reset size", 0, hashMap.size());
    for (int i = 0; i < 125; i++) {
        CPPUNIT_ASSERT_THROW_MESSAGE(
            "Failed to clear all elements",
            hashMap.get(i),
            NoSuchElementException);
    }

    // Check clear on a large loaded map of Integer keys
    LinkedHashMap<int, std::string> map;
    for (int i = -32767; i < 32768; i++) {
        map.put(i, "foobar");
    }
    map.clear();
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Failed to reset size on large integer map", 0, map.size());
    for (int i = -32767; i < 32768; i++) {
        CPPUNIT_ASSERT_THROW_MESSAGE(
            "Failed to clear all elements",
            map.get(i),
            NoSuchElementException);
    }
}
开发者ID:apache,项目名称:activemq-cpp,代码行数:30,代码来源:LinkedHashMapTest.cpp

示例13: testConstructor

void LinkedHashMapTest::testConstructor() {

    LinkedHashMap<int, std::string> map;
    CPPUNIT_ASSERT(map.isEmpty());
    CPPUNIT_ASSERT(map.size() == 0);
}
开发者ID:apache,项目名称:activemq-cpp,代码行数:6,代码来源:LinkedHashMapTest.cpp

示例14: testSize

void LinkedHashMapTest::testSize() {
    LinkedHashMap<int, std::string> hashMap;
    populateMap(hashMap);

    CPPUNIT_ASSERT_MESSAGE("Returned incorrect size", hashMap.size() == MAP_SIZE);
}
开发者ID:apache,项目名称:activemq-cpp,代码行数:6,代码来源:LinkedHashMapTest.cpp


注:本文中的LinkedHashMap类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。