Skip to content

Commit

Permalink
add tests to check if key exists
Browse files Browse the repository at this point in the history
  • Loading branch information
btjm123 committed Aug 9, 2024
1 parent 9883cdf commit c3f6e9d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/ChainingHashMap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,17 @@ TEST(ChainingHashMap, Resize)
map[7] = 70;
map[8] = 80;
EXPECT_EQ(map.getBucketCount(), 16);
}

// Test for existence of key
TEST(ChainingHashMap, ExistenceOfKey)
{
benn::ChainingHashMap<int, int> map;

EXPECT_EQ(map.count(0), 0);
map[0] = 10;

EXPECT_EQ(map.count(0), 1);
EXPECT_EQ(map.count(1), 0);
EXPECT_EQ(map.count(10), 0);
}
13 changes: 13 additions & 0 deletions tests/OpenAddressingHashMap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,17 @@ TEST(OpenAddressingHashMap, Resize)
map[7] = 70;
map[8] = 80;
EXPECT_EQ(map.getBucketCount(), 16);
}

// Test for existence of key
TEST(OpenAddressingHashMap, ExistenceOfKey)
{
benn::OpenAddressingHashMap<int, int> map;

EXPECT_EQ(map.count(0), 0);
map[0] = 10;

EXPECT_EQ(map.count(0), 1);
EXPECT_EQ(map.count(1), 0);
EXPECT_EQ(map.count(10), 0);
}

0 comments on commit c3f6e9d

Please sign in to comment.