Main MRPT website > C++ reference for MRPT 1.9.9
ts_hash_map_unittest.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
11 #include <gtest/gtest.h>
12 
13 template <typename T>
15 {
16  T h1, h2;
17  mrpt::containers::reduced_hash("prueba1", h1);
18  mrpt::containers::reduced_hash("prueba2", h2);
19  EXPECT_NE(h1, h2);
20 }
21 
22 TEST(ts_hash_map, string_hash_u8) { simple_test_hash_string<uint8_t>(); }
23 TEST(ts_hash_map, string_hash_u16) { simple_test_hash_string<uint16_t>(); }
24 TEST(ts_hash_map, string_hash_u32) { simple_test_hash_string<uint32_t>(); }
25 TEST(ts_hash_map, string_hash_u64) { simple_test_hash_string<uint64_t>(); }
26 TEST(ts_hash_map, stdstring_key)
27 {
28  mrpt::containers::ts_hash_map<std::string, double> m;
29 
30  EXPECT_TRUE(m.empty());
31 
32  m["numero"] = 2.3;
33  EXPECT_FALSE(m.empty());
34  m.clear();
35  EXPECT_TRUE(m.empty());
36 
37  m["uno"] = 1.0;
38  m["dos"] = 2.0;
39  m["tres"] = 3.0;
40 
41  EXPECT_EQ(1.0, m["uno"]);
42  EXPECT_EQ(2.0, m["dos"]);
43  EXPECT_EQ(3.0, m["tres"]);
44 
45  m["tres"]++;
46  EXPECT_EQ(4.0, m["tres"])
47  << "Fail after ++ operator applied to reference [].";
48 
49  double num = .0;
50  for (const auto& e : m) num += e.second;
51  EXPECT_NEAR(num, 7.0, 1e-10)
52  << "Fail after visiting and summing all entries";
53 
54  {
55  const auto& it = m.find("pepe");
56  EXPECT_TRUE(it == m.end());
57  }
58 
59  {
60  const auto& it = m.find("uno");
61  EXPECT_TRUE(it->second == 1.0);
62  }
63 }
mrpt::containers::ts_hash_map
ts_hash_map()
< Default constructor *‍/
Definition: ts_hash_map.h:186
ts_hash_map.h
mrpt::containers::reduced_hash
void reduced_hash(const std::string &value, uint8_t &hash)
hash function used by ts_hash_map.
Definition: ts_hash_map.cpp:28
simple_test_hash_string
void simple_test_hash_string()
Definition: ts_hash_map_unittest.cpp:14
TEST
TEST(ts_hash_map, string_hash_u8)
Definition: ts_hash_map_unittest.cpp:22
num
GLuint GLuint num
Definition: glext.h:7278



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at mié 12 jul 2023 10:03:34 CEST