Ejemplo n.º 1
0
TEST(HashTableTest, expandKey) {
	
	HashTable<std::string,std::string> ht;
	char buf[10];
	std::string c;

	for(int i = 0; i < 100; i ++) 
	{
		sprintf(buf,"a%d",i);
		//ht.add(buf, "ab");
		ht[buf] = "ab";
		ht[buf] = "ac";
		c = ht[buf];
		std::cout << "buf:" << buf << ",value:" << ht[buf] << ",c:" << c << std::endl;
	}

	//std::cout << "11:" << ht["11"]<< std::endl;
	
	EXPECT_EQ(100UL,ht.count());
	
	ht.remove("a8");

	EXPECT_EQ(99UL,ht.count());
	//EXPECT_TRUE(ht["a13"] == "ac");
	EXPECT_TRUE(ht.containsKey("a13"));
	EXPECT_TRUE(ht.contains("a13","ac"));
	EXPECT_FALSE(ht.containsKey("a1012"));
	EXPECT_FALSE(ht.contains("a1123","ac"));
	EXPECT_FALSE(ht.contains("a12","ab"));

	for(int i = 0; i < 1000; i ++) 
	{
		sprintf(buf,"a%d",i);
		//ht.add(buf, "ab");
		ht[buf] = "ab";
		ht[buf] = "ac";
		c = ht[buf];
		std::cout << "buf:" << buf << ",value:" << ht[buf] << ",c:" << c << std::endl;
	}

	ht.remove("a18");

	EXPECT_EQ(999UL,ht.count());
	//EXPECT_TRUE(ht["a13"] == "ac");
	EXPECT_TRUE(ht.containsKey("a13"));
	EXPECT_TRUE(ht.contains("a13","ac"));
	EXPECT_TRUE(ht.containsKey("a112"));
	EXPECT_FALSE(ht.contains("a1203","ac"));
	
}
Ejemplo n.º 2
0
TEST(HashTableTest, IntKey)  {
	
	HashTable<uint,uint,IntHash> ht;
	
	EXPECT_EQ(0UL,ht.count());
	EXPECT_FALSE(ht.containsKey(1));
	ht.add(1,1);
	EXPECT_EQ(1UL,ht.count());
	EXPECT_TRUE(ht.containsKey(1));
	EXPECT_TRUE(ht.contains(1,1));
	ht[1] = 0;
	EXPECT_TRUE(ht[1] == 0U);
	ht.remove(1);
	EXPECT_EQ(0UL,ht.count());
}