MCPcopy Create free account
hub / github.com/apache/impala / TEST

Function TEST

be/src/util/fixed-size-hash-table-test.cc:26–78  ·  view source on GitHub ↗

Basic test for all operations.

Source from the content-addressed store, hash-verified

24
25/// Basic test for all operations.
26TEST(FixedSizeHash, TestAllOperations) {
27 for (int seed = 0; seed < 100; ++seed) {
28 // Allocate large enough to just fit keys.
29 // Try multiple hash seeds so that we will get collisions.
30 FixedSizeHashTable<void*, int> tbl;
31 EXPECT_TRUE(tbl.Init(4, seed).ok());
32 void* k1 = (void*)1;
33 void* k2 = (void*)2;
34 void* k3 = (void*)3;
35 int v1 = 4;
36 int v2 = 5;
37 int v3 = 6;
38 int result;
39 const int* result_ptr;
40
41 // Table should be initially empty.
42 EXPECT_FALSE(tbl.Find(k1, &result));
43 EXPECT_FALSE(tbl.Find(k2, &result));
44 EXPECT_FALSE(tbl.Find(k3, &result));
45 EXPECT_EQ(0, tbl.size());
46 tbl.Insert(k1, v1);
47 tbl.Insert(k2, v2);
48 tbl.Insert(k3, v3);
49 EXPECT_EQ(3, tbl.size());
50 EXPECT_TRUE(tbl.Find(k1, &result));
51 EXPECT_EQ(v1, result);
52 EXPECT_TRUE(tbl.Find(k2, &result));
53 EXPECT_EQ(v2, result);
54 EXPECT_TRUE(tbl.Find(k3, &result));
55 EXPECT_EQ(v3, result);
56 // Exercise conditional insertion functions.
57 EXPECT_FALSE(tbl.InsertIfNotPresent(k1, v2));
58 EXPECT_EQ(v1, *tbl.FindOrInsert(k1, v2));
59 EXPECT_EQ(v3, result);
60 EXPECT_EQ(3, tbl.size());
61 // Check that table is cleared correctly.
62 tbl.Clear();
63 EXPECT_EQ(0, tbl.size());
64 EXPECT_FALSE(tbl.Find(k1, &result));
65 EXPECT_FALSE(tbl.Find(k2, &result));
66 EXPECT_FALSE(tbl.Find(k3, &result));
67 // Exercise conditional insertion more.
68 EXPECT_TRUE(tbl.InsertIfNotPresent(k1, v2));
69 EXPECT_TRUE(tbl.Find(k1, &result));
70 EXPECT_EQ(v2, result);
71 EXPECT_EQ(1, tbl.size());
72 result_ptr = tbl.FindOrInsert(k2, v3);
73 EXPECT_EQ(v3, *result_ptr);
74 EXPECT_TRUE(tbl.Find(k2, &result));
75 EXPECT_EQ(v3, result);
76 EXPECT_EQ(2, tbl.size());
77 }
78}
79
80}
81

Callers

nothing calls this directly

Calls 8

InsertIfNotPresentMethod · 0.80
FindOrInsertMethod · 0.80
okMethod · 0.45
InitMethod · 0.45
FindMethod · 0.45
sizeMethod · 0.45
InsertMethod · 0.45
ClearMethod · 0.45

Tested by

no test coverage detected