Skip to content

Commit

Permalink
contains
Browse files Browse the repository at this point in the history
  • Loading branch information
jkalias committed Sep 24, 2023
1 parent d70521c commit 12b4d80
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
26 changes: 13 additions & 13 deletions include/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -550,19 +550,19 @@ class map
{
return m_map.empty();
}
//
//
// // Returns true if the key is present in the set, otherwise false
// //
// // example:
// // const fcpp::set<int> numbers({1, 4, 2});
// // numbers.contains(1); // true
// // numbers.contains(15); // false
// [[nodiscard]] bool contains(const TKey& key) const
// {
// return m_map.count(key) != 0;
// }
//


// Returns true if the key is present in the map, otherwise false
//
// example:
// const fcpp::map<std::string, int> persons({{"jake", 32}, {"mary", 26}, {"david", 40}});
// persons.contains("jake"); // true
// persons.contains("bob"); // false
[[nodiscard]] bool contains(const TKey& key) const
{
return m_map.find(key) != end();
}

// Returns the size of the map (how many elements it contains, it may be different from its capacity)
[[nodiscard]] size_t size() const
{
Expand Down
14 changes: 7 additions & 7 deletions tests/map_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -478,13 +478,13 @@ TEST(MapTest, IsEmpty)
EXPECT_TRUE(empty_map.is_empty());
}

//TEST(MapTest, Contains)
//{
// const set<int> numbers({1, 4, 2});
// EXPECT_TRUE(numbers.contains(1));
// EXPECT_FALSE(numbers.contains(15));
//}
//
TEST(MapTest, Contains)
{
const map<std::string, int> persons({{"jake", 32}, {"mary", 26}, {"david", 40}});
EXPECT_TRUE(persons.contains("jake"));
EXPECT_FALSE(persons.contains("bob"));
}

//TEST(MapTest, EqualityOperator)
//{
// const set<int> set1(std::set<int>({1, 2, 3}));
Expand Down

0 comments on commit 12b4d80

Please sign in to comment.