void testClear ()
  {
    map->put ((char*)"one", 1);

    CPPUNIT_ASSERT_EQUAL (map->empty (), false);

    map->clear ();

    CPPUNIT_ASSERT_EQUAL (map->empty (), true);
  }
Exemple #2
0
	const Element* Element::get(const String& symbol) {
		static HashMap<String, const Element*> elements;
		if (elements.empty()) {
			for (Index i = 0; i < ARRAY_LENGTH(ELEMENT_DATA); ++i) {
				elements[ELEMENT_DATA[i].symbol] = ELEMENT_DATA+i;
			}
			elements[ELEMENT_D.symbol] = &ELEMENT_D;
			elements[ELEMENT_T.symbol] = &ELEMENT_T;
		}
		HashMap<String, const Element*>::const_iterator it = elements.find(symbol);
		if (it != elements.end()) {
			return it->second;
		}
		else {
			return NULL;
		}
	}
static std::string testInit()
{
    PoolAllocator allocator(sizeof(HashMap<int,std::string>::Entry));
    StandardInitializer<std::string> initializer;
    StandardHash<int> hash;
    HashMap<int,std::string>* map;

    map = new HashMap<int,std::string>();
    if( !map->empty() or map->size() != 0 ) {
        return "Size not initialized to 0 (a).";
    }
    delete map;

    map = new HashMap<int,std::string>(100);
    if( !map->empty() or map->size() != 0 ) {
        return "Size not initialized to 0 (b).";
    }
    delete map;

    map = new HashMap<int,std::string>(100, allocator);
    if( !map->empty() or map->size() != 0 ) {
        return "Size not initialized to 0 (c).";
    }
    delete map;

    map = new HashMap<int,std::string>(100, allocator, initializer);
    if( !map->empty() or map->size() != 0 ) {
        return "Size not initialized to 0 (d).";
    }
    delete map;

    map = new HashMap<int,std::string>(100, allocator, initializer, hash);
    if( !map->empty() or map->size() != 0 ) {
        return "Size not initialized to 0 (d).";
    }
    delete map;

    map = new HashMap<int,std::string>(10, allocator, initializer, hash, 0.5);
    if( !map->empty() or map->size() != 0 ) {
        return "Size not initialized to 0 (e).";
    } else if( map->loadFactor() != 0.5 ) {
        //printf("%f\n", map->loadFactor());
        std::cout << map->loadFactor() << std::endl;
        return "LoadFactor not properly initialized.";
    }
    delete map;

    return "";
}
 void testEmpty ()
 {
   CPPUNIT_ASSERT_EQUAL (map->empty (), true);
   map->put ((char*)"key", 0);
   CPPUNIT_ASSERT_EQUAL (map->empty (), false);
 }