Main MRPT website > C++ reference for MRPT 1.5.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-2017, 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 
10 #include <mrpt/utils/ts_hash_map.h>
11 #include <gtest/gtest.h>
12 
13 template <typename T>
15 {
16  T h1, h2;
17  mrpt::utils::reduced_hash("prueba1", h1);
18  mrpt::utils::reduced_hash("prueba2", h2);
19  EXPECT_NE(h1, h2);
20 }
21 
22 TEST(ts_hash_map, string_hash_u8) {
23  simple_test_hash_string<uint8_t>();
24 }
25 TEST(ts_hash_map, string_hash_u16) {
26  simple_test_hash_string<uint16_t>();
27 }
28 TEST(ts_hash_map, string_hash_u32) {
29  simple_test_hash_string<uint32_t>();
30 }
31 TEST(ts_hash_map, string_hash_u64) {
32  simple_test_hash_string<uint64_t>();
33 }
34 
35 
36 TEST(ts_hash_map, stdstring_key)
37 {
38  mrpt::utils::ts_hash_map<std::string, double> m;
39 
40  EXPECT_TRUE(m.empty());
41 
42  m["numero"] = 2.3;
43  EXPECT_FALSE(m.empty());
44  m.clear();
45  EXPECT_TRUE(m.empty());
46 
47  m["uno"] = 1.0;
48  m["dos"] = 2.0;
49  m["tres"] = 3.0;
50 
51  EXPECT_EQ(1.0, m["uno"]);
52  EXPECT_EQ(2.0, m["dos"]);
53  EXPECT_EQ(3.0, m["tres"]);
54 
55  m["tres"]++;
56  EXPECT_EQ(4.0, m["tres"]) << "Fail after ++ operator applied to reference [].";
57 
58  double num = .0;
59  for (const auto &e : m)
60  num += e.second;
61  EXPECT_NEAR(num, 7.0, 1e-10) << "Fail after visiting and summing all entries";
62 
63  {
64  const auto &it = m.find("pepe");
65  EXPECT_TRUE(it == m.end());
66  }
67 
68  {
69  const auto &it = m.find("uno");
70  EXPECT_TRUE( it->second==1.0 );
71  }
72 }
73 
void simple_test_hash_string()
ts_hash_map()
< Default constructor */
Definition: ts_hash_map.h:109
TEST(ts_hash_map, string_hash_u8)
GLuint GLuint num
Definition: glext.h:6303
void BASE_IMPEXP reduced_hash(const std::string &value, uint8_t &hash)
hash function used by ts_hash_map. Uses dbj2 method
Definition: ts_hash_map.cpp:27



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020