/indra/newview/tests/llsimplestat_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 580 lines · 400 code · 103 blank · 77 comment · 118 complexity · 61d79e18df3bc0bb77a2b327fbacbe31 MD5 · raw file

  1. /**
  2. * @file llsimplestats_test.cpp
  3. * @date 2010-10-22
  4. * @brief Test cases for some of llsimplestat.h
  5. *
  6. * $LicenseInfo:firstyear=2010&license=viewerlgpl$
  7. * Second Life Viewer Source Code
  8. * Copyright (C) 2010, Linden Research, Inc.
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation;
  13. * version 2.1 of the License only.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  25. * $/LicenseInfo$
  26. */
  27. #include "linden_common.h"
  28. #include <tut/tut.hpp>
  29. #include "lltut.h"
  30. #include "../llsimplestat.h"
  31. #include "llsd.h"
  32. #include "llmath.h"
  33. // @brief Used as a pointer cast type to get access to LLSimpleStatCounter
  34. class TutStatCounter: public LLSimpleStatCounter
  35. {
  36. public:
  37. TutStatCounter(); // Not defined
  38. ~TutStatCounter(); // Not defined
  39. void operator=(const TutStatCounter &); // Not defined
  40. void setRawCount(U32 c) { mCount = c; }
  41. U32 getRawCount() const { return mCount; }
  42. };
  43. namespace tut
  44. {
  45. struct stat_counter_index
  46. {};
  47. typedef test_group<stat_counter_index> stat_counter_index_t;
  48. typedef stat_counter_index_t::object stat_counter_index_object_t;
  49. tut::stat_counter_index_t tut_stat_counter_index("stat_counter_test");
  50. // Testing LLSimpleStatCounter's external interface
  51. template<> template<>
  52. void stat_counter_index_object_t::test<1>()
  53. {
  54. LLSimpleStatCounter c1;
  55. ensure("Initialized counter is zero", (0 == c1.getCount()));
  56. ensure("Counter increment return is 1", (1 == ++c1));
  57. ensure("Counter increment return is 2", (2 == ++c1));
  58. ensure("Current counter is 2", (2 == c1.getCount()));
  59. c1.reset();
  60. ensure("Counter is 0 after reset", (0 == c1.getCount()));
  61. ensure("Counter increment return is 1", (1 == ++c1));
  62. }
  63. // Testing LLSimpleStatCounter's internal state
  64. template<> template<>
  65. void stat_counter_index_object_t::test<2>()
  66. {
  67. LLSimpleStatCounter c1;
  68. TutStatCounter * tc1 = (TutStatCounter *) &c1;
  69. ensure("Initialized private counter is zero", (0 == tc1->getRawCount()));
  70. ++c1;
  71. ++c1;
  72. ensure("Current private counter is 2", (2 == tc1->getRawCount()));
  73. c1.reset();
  74. ensure("Raw counter is 0 after reset", (0 == tc1->getRawCount()));
  75. }
  76. // Testing LLSimpleStatCounter's wrapping behavior
  77. template<> template<>
  78. void stat_counter_index_object_t::test<3>()
  79. {
  80. LLSimpleStatCounter c1;
  81. TutStatCounter * tc1 = (TutStatCounter *) &c1;
  82. tc1->setRawCount(U32_MAX);
  83. ensure("Initialized private counter is zero", (U32_MAX == c1.getCount()));
  84. ensure("Increment of max value wraps to 0", (0 == ++c1));
  85. }
  86. // Testing LLSimpleStatMMM's external behavior
  87. template<> template<>
  88. void stat_counter_index_object_t::test<4>()
  89. {
  90. LLSimpleStatMMM<> m1;
  91. typedef LLSimpleStatMMM<>::Value lcl_float;
  92. lcl_float zero(0);
  93. // Freshly-constructed
  94. ensure("Constructed MMM<> has 0 count", (0 == m1.getCount()));
  95. ensure("Constructed MMM<> has 0 min", (zero == m1.getMin()));
  96. ensure("Constructed MMM<> has 0 max", (zero == m1.getMax()));
  97. ensure("Constructed MMM<> has 0 mean no div-by-zero", (zero == m1.getMean()));
  98. // Single insert
  99. m1.record(1.0);
  100. ensure("Single insert MMM<> has 1 count", (1 == m1.getCount()));
  101. ensure("Single insert MMM<> has 1.0 min", (1.0 == m1.getMin()));
  102. ensure("Single insert MMM<> has 1.0 max", (1.0 == m1.getMax()));
  103. ensure("Single insert MMM<> has 1.0 mean", (1.0 == m1.getMean()));
  104. // Second insert
  105. m1.record(3.0);
  106. ensure("2nd insert MMM<> has 2 count", (2 == m1.getCount()));
  107. ensure("2nd insert MMM<> has 1.0 min", (1.0 == m1.getMin()));
  108. ensure("2nd insert MMM<> has 3.0 max", (3.0 == m1.getMax()));
  109. ensure_approximately_equals("2nd insert MMM<> has 2.0 mean", m1.getMean(), lcl_float(2.0), 1);
  110. // Third insert
  111. m1.record(5.0);
  112. ensure("3rd insert MMM<> has 3 count", (3 == m1.getCount()));
  113. ensure("3rd insert MMM<> has 1.0 min", (1.0 == m1.getMin()));
  114. ensure("3rd insert MMM<> has 5.0 max", (5.0 == m1.getMax()));
  115. ensure_approximately_equals("3rd insert MMM<> has 3.0 mean", m1.getMean(), lcl_float(3.0), 1);
  116. // Fourth insert
  117. m1.record(1000000.0);
  118. ensure("4th insert MMM<> has 4 count", (4 == m1.getCount()));
  119. ensure("4th insert MMM<> has 1.0 min", (1.0 == m1.getMin()));
  120. ensure("4th insert MMM<> has 100000.0 max", (1000000.0 == m1.getMax()));
  121. ensure_approximately_equals("4th insert MMM<> has 250002.0 mean", m1.getMean(), lcl_float(250002.0), 1);
  122. // Reset
  123. m1.reset();
  124. ensure("Reset MMM<> has 0 count", (0 == m1.getCount()));
  125. ensure("Reset MMM<> has 0 min", (zero == m1.getMin()));
  126. ensure("Reset MMM<> has 0 max", (zero == m1.getMax()));
  127. ensure("Reset MMM<> has 0 mean no div-by-zero", (zero == m1.getMean()));
  128. }
  129. // Testing LLSimpleStatMMM's response to large values
  130. template<> template<>
  131. void stat_counter_index_object_t::test<5>()
  132. {
  133. LLSimpleStatMMM<> m1;
  134. typedef LLSimpleStatMMM<>::Value lcl_float;
  135. lcl_float zero(0);
  136. // Insert overflowing values
  137. const lcl_float bignum(F32_MAX / 2);
  138. m1.record(bignum);
  139. m1.record(bignum);
  140. m1.record(bignum);
  141. m1.record(bignum);
  142. m1.record(bignum);
  143. m1.record(bignum);
  144. m1.record(bignum);
  145. m1.record(zero);
  146. ensure("Overflowed MMM<> has 8 count", (8 == m1.getCount()));
  147. ensure("Overflowed MMM<> has 0 min", (zero == m1.getMin()));
  148. ensure("Overflowed MMM<> has huge max", (bignum == m1.getMax()));
  149. ensure("Overflowed MMM<> has fetchable mean", (1.0 == m1.getMean() || true));
  150. // We should be infinte but not interested in proving the IEEE standard here.
  151. LLSD sd1(m1.getMean());
  152. // std::cout << "Thingy: " << m1.getMean() << " and as LLSD: " << sd1 << std::endl;
  153. ensure("Overflowed MMM<> produces LLSDable Real", (sd1.isReal()));
  154. }
  155. // Testing LLSimpleStatMMM<F32>'s external behavior
  156. template<> template<>
  157. void stat_counter_index_object_t::test<6>()
  158. {
  159. LLSimpleStatMMM<F32> m1;
  160. typedef LLSimpleStatMMM<F32>::Value lcl_float;
  161. lcl_float zero(0);
  162. // Freshly-constructed
  163. ensure("Constructed MMM<F32> has 0 count", (0 == m1.getCount()));
  164. ensure("Constructed MMM<F32> has 0 min", (zero == m1.getMin()));
  165. ensure("Constructed MMM<F32> has 0 max", (zero == m1.getMax()));
  166. ensure("Constructed MMM<F32> has 0 mean no div-by-zero", (zero == m1.getMean()));
  167. // Single insert
  168. m1.record(1.0);
  169. ensure("Single insert MMM<F32> has 1 count", (1 == m1.getCount()));
  170. ensure("Single insert MMM<F32> has 1.0 min", (1.0 == m1.getMin()));
  171. ensure("Single insert MMM<F32> has 1.0 max", (1.0 == m1.getMax()));
  172. ensure("Single insert MMM<F32> has 1.0 mean", (1.0 == m1.getMean()));
  173. // Second insert
  174. m1.record(3.0);
  175. ensure("2nd insert MMM<F32> has 2 count", (2 == m1.getCount()));
  176. ensure("2nd insert MMM<F32> has 1.0 min", (1.0 == m1.getMin()));
  177. ensure("2nd insert MMM<F32> has 3.0 max", (3.0 == m1.getMax()));
  178. ensure_approximately_equals("2nd insert MMM<F32> has 2.0 mean", m1.getMean(), lcl_float(2.0), 1);
  179. // Third insert
  180. m1.record(5.0);
  181. ensure("3rd insert MMM<F32> has 3 count", (3 == m1.getCount()));
  182. ensure("3rd insert MMM<F32> has 1.0 min", (1.0 == m1.getMin()));
  183. ensure("3rd insert MMM<F32> has 5.0 max", (5.0 == m1.getMax()));
  184. ensure_approximately_equals("3rd insert MMM<F32> has 3.0 mean", m1.getMean(), lcl_float(3.0), 1);
  185. // Fourth insert
  186. m1.record(1000000.0);
  187. ensure("4th insert MMM<F32> has 4 count", (4 == m1.getCount()));
  188. ensure("4th insert MMM<F32> has 1.0 min", (1.0 == m1.getMin()));
  189. ensure("4th insert MMM<F32> has 1000000.0 max", (1000000.0 == m1.getMax()));
  190. ensure_approximately_equals("4th insert MMM<F32> has 250002.0 mean", m1.getMean(), lcl_float(250002.0), 1);
  191. // Reset
  192. m1.reset();
  193. ensure("Reset MMM<F32> has 0 count", (0 == m1.getCount()));
  194. ensure("Reset MMM<F32> has 0 min", (zero == m1.getMin()));
  195. ensure("Reset MMM<F32> has 0 max", (zero == m1.getMax()));
  196. ensure("Reset MMM<F32> has 0 mean no div-by-zero", (zero == m1.getMean()));
  197. }
  198. // Testing LLSimpleStatMMM's response to large values
  199. template<> template<>
  200. void stat_counter_index_object_t::test<7>()
  201. {
  202. LLSimpleStatMMM<F32> m1;
  203. typedef LLSimpleStatMMM<F32>::Value lcl_float;
  204. lcl_float zero(0);
  205. // Insert overflowing values
  206. const lcl_float bignum(F32_MAX / 2);
  207. m1.record(bignum);
  208. m1.record(bignum);
  209. m1.record(bignum);
  210. m1.record(bignum);
  211. m1.record(bignum);
  212. m1.record(bignum);
  213. m1.record(bignum);
  214. m1.record(zero);
  215. ensure("Overflowed MMM<F32> has 8 count", (8 == m1.getCount()));
  216. ensure("Overflowed MMM<F32> has 0 min", (zero == m1.getMin()));
  217. ensure("Overflowed MMM<F32> has huge max", (bignum == m1.getMax()));
  218. ensure("Overflowed MMM<F32> has fetchable mean", (1.0 == m1.getMean() || true));
  219. // We should be infinte but not interested in proving the IEEE standard here.
  220. LLSD sd1(m1.getMean());
  221. // std::cout << "Thingy: " << m1.getMean() << " and as LLSD: " << sd1 << std::endl;
  222. ensure("Overflowed MMM<F32> produces LLSDable Real", (sd1.isReal()));
  223. }
  224. // Testing LLSimpleStatMMM<F64>'s external behavior
  225. template<> template<>
  226. void stat_counter_index_object_t::test<8>()
  227. {
  228. LLSimpleStatMMM<F64> m1;
  229. typedef LLSimpleStatMMM<F64>::Value lcl_float;
  230. lcl_float zero(0);
  231. // Freshly-constructed
  232. ensure("Constructed MMM<F64> has 0 count", (0 == m1.getCount()));
  233. ensure("Constructed MMM<F64> has 0 min", (zero == m1.getMin()));
  234. ensure("Constructed MMM<F64> has 0 max", (zero == m1.getMax()));
  235. ensure("Constructed MMM<F64> has 0 mean no div-by-zero", (zero == m1.getMean()));
  236. // Single insert
  237. m1.record(1.0);
  238. ensure("Single insert MMM<F64> has 1 count", (1 == m1.getCount()));
  239. ensure("Single insert MMM<F64> has 1.0 min", (1.0 == m1.getMin()));
  240. ensure("Single insert MMM<F64> has 1.0 max", (1.0 == m1.getMax()));
  241. ensure("Single insert MMM<F64> has 1.0 mean", (1.0 == m1.getMean()));
  242. // Second insert
  243. m1.record(3.0);
  244. ensure("2nd insert MMM<F64> has 2 count", (2 == m1.getCount()));
  245. ensure("2nd insert MMM<F64> has 1.0 min", (1.0 == m1.getMin()));
  246. ensure("2nd insert MMM<F64> has 3.0 max", (3.0 == m1.getMax()));
  247. ensure_approximately_equals("2nd insert MMM<F64> has 2.0 mean", m1.getMean(), lcl_float(2.0), 1);
  248. // Third insert
  249. m1.record(5.0);
  250. ensure("3rd insert MMM<F64> has 3 count", (3 == m1.getCount()));
  251. ensure("3rd insert MMM<F64> has 1.0 min", (1.0 == m1.getMin()));
  252. ensure("3rd insert MMM<F64> has 5.0 max", (5.0 == m1.getMax()));
  253. ensure_approximately_equals("3rd insert MMM<F64> has 3.0 mean", m1.getMean(), lcl_float(3.0), 1);
  254. // Fourth insert
  255. m1.record(1000000.0);
  256. ensure("4th insert MMM<F64> has 4 count", (4 == m1.getCount()));
  257. ensure("4th insert MMM<F64> has 1.0 min", (1.0 == m1.getMin()));
  258. ensure("4th insert MMM<F64> has 1000000.0 max", (1000000.0 == m1.getMax()));
  259. ensure_approximately_equals("4th insert MMM<F64> has 250002.0 mean", m1.getMean(), lcl_float(250002.0), 1);
  260. // Reset
  261. m1.reset();
  262. ensure("Reset MMM<F64> has 0 count", (0 == m1.getCount()));
  263. ensure("Reset MMM<F64> has 0 min", (zero == m1.getMin()));
  264. ensure("Reset MMM<F64> has 0 max", (zero == m1.getMax()));
  265. ensure("Reset MMM<F64> has 0 mean no div-by-zero", (zero == m1.getMean()));
  266. }
  267. // Testing LLSimpleStatMMM's response to large values
  268. template<> template<>
  269. void stat_counter_index_object_t::test<9>()
  270. {
  271. LLSimpleStatMMM<F64> m1;
  272. typedef LLSimpleStatMMM<F64>::Value lcl_float;
  273. lcl_float zero(0);
  274. // Insert overflowing values
  275. const lcl_float bignum(F64_MAX / 2);
  276. m1.record(bignum);
  277. m1.record(bignum);
  278. m1.record(bignum);
  279. m1.record(bignum);
  280. m1.record(bignum);
  281. m1.record(bignum);
  282. m1.record(bignum);
  283. m1.record(zero);
  284. ensure("Overflowed MMM<F64> has 8 count", (8 == m1.getCount()));
  285. ensure("Overflowed MMM<F64> has 0 min", (zero == m1.getMin()));
  286. ensure("Overflowed MMM<F64> has huge max", (bignum == m1.getMax()));
  287. ensure("Overflowed MMM<F64> has fetchable mean", (1.0 == m1.getMean() || true));
  288. // We should be infinte but not interested in proving the IEEE standard here.
  289. LLSD sd1(m1.getMean());
  290. // std::cout << "Thingy: " << m1.getMean() << " and as LLSD: " << sd1 << std::endl;
  291. ensure("Overflowed MMM<F64> produces LLSDable Real", (sd1.isReal()));
  292. }
  293. // Testing LLSimpleStatMMM<U64>'s external behavior
  294. template<> template<>
  295. void stat_counter_index_object_t::test<10>()
  296. {
  297. LLSimpleStatMMM<U64> m1;
  298. typedef LLSimpleStatMMM<U64>::Value lcl_int;
  299. lcl_int zero(0);
  300. // Freshly-constructed
  301. ensure("Constructed MMM<U64> has 0 count", (0 == m1.getCount()));
  302. ensure("Constructed MMM<U64> has 0 min", (zero == m1.getMin()));
  303. ensure("Constructed MMM<U64> has 0 max", (zero == m1.getMax()));
  304. ensure("Constructed MMM<U64> has 0 mean no div-by-zero", (zero == m1.getMean()));
  305. // Single insert
  306. m1.record(1);
  307. ensure("Single insert MMM<U64> has 1 count", (1 == m1.getCount()));
  308. ensure("Single insert MMM<U64> has 1 min", (1 == m1.getMin()));
  309. ensure("Single insert MMM<U64> has 1 max", (1 == m1.getMax()));
  310. ensure("Single insert MMM<U64> has 1 mean", (1 == m1.getMean()));
  311. // Second insert
  312. m1.record(3);
  313. ensure("2nd insert MMM<U64> has 2 count", (2 == m1.getCount()));
  314. ensure("2nd insert MMM<U64> has 1 min", (1 == m1.getMin()));
  315. ensure("2nd insert MMM<U64> has 3 max", (3 == m1.getMax()));
  316. ensure("2nd insert MMM<U64> has 2 mean", (2 == m1.getMean()));
  317. // Third insert
  318. m1.record(5);
  319. ensure("3rd insert MMM<U64> has 3 count", (3 == m1.getCount()));
  320. ensure("3rd insert MMM<U64> has 1 min", (1 == m1.getMin()));
  321. ensure("3rd insert MMM<U64> has 5 max", (5 == m1.getMax()));
  322. ensure("3rd insert MMM<U64> has 3 mean", (3 == m1.getMean()));
  323. // Fourth insert
  324. m1.record(U64L(1000000000000));
  325. ensure("4th insert MMM<U64> has 4 count", (4 == m1.getCount()));
  326. ensure("4th insert MMM<U64> has 1 min", (1 == m1.getMin()));
  327. ensure("4th insert MMM<U64> has 1000000000000ULL max", (U64L(1000000000000) == m1.getMax()));
  328. ensure("4th insert MMM<U64> has 250000000002ULL mean", (U64L( 250000000002) == m1.getMean()));
  329. // Reset
  330. m1.reset();
  331. ensure("Reset MMM<U64> has 0 count", (0 == m1.getCount()));
  332. ensure("Reset MMM<U64> has 0 min", (zero == m1.getMin()));
  333. ensure("Reset MMM<U64> has 0 max", (zero == m1.getMax()));
  334. ensure("Reset MMM<U64> has 0 mean no div-by-zero", (zero == m1.getMean()));
  335. }
  336. // Testing LLSimpleStatMMM's response to large values
  337. template<> template<>
  338. void stat_counter_index_object_t::test<11>()
  339. {
  340. LLSimpleStatMMM<U64> m1;
  341. typedef LLSimpleStatMMM<U64>::Value lcl_int;
  342. lcl_int zero(0);
  343. // Insert overflowing values
  344. const lcl_int bignum(U64L(0xffffffffffffffff) / 2);
  345. m1.record(bignum);
  346. m1.record(bignum);
  347. m1.record(bignum);
  348. m1.record(bignum);
  349. m1.record(bignum);
  350. m1.record(bignum);
  351. m1.record(bignum);
  352. m1.record(zero);
  353. ensure("Overflowed MMM<U64> has 8 count", (8 == m1.getCount()));
  354. ensure("Overflowed MMM<U64> has 0 min", (zero == m1.getMin()));
  355. ensure("Overflowed MMM<U64> has huge max", (bignum == m1.getMax()));
  356. ensure("Overflowed MMM<U64> has fetchable mean", (zero == m1.getMean() || true));
  357. }
  358. // Testing LLSimpleStatCounter's merge() method
  359. template<> template<>
  360. void stat_counter_index_object_t::test<12>()
  361. {
  362. LLSimpleStatCounter c1;
  363. LLSimpleStatCounter c2;
  364. ++c1;
  365. ++c1;
  366. ++c1;
  367. ++c1;
  368. ++c2;
  369. ++c2;
  370. c2.merge(c1);
  371. ensure_equals("4 merged into 2 results in 6", 6, c2.getCount());
  372. ensure_equals("Source of merge is undamaged", 4, c1.getCount());
  373. }
  374. // Testing LLSimpleStatMMM's merge() method
  375. template<> template<>
  376. void stat_counter_index_object_t::test<13>()
  377. {
  378. LLSimpleStatMMM<> m1;
  379. LLSimpleStatMMM<> m2;
  380. m1.record(3.5);
  381. m1.record(4.5);
  382. m1.record(5.5);
  383. m1.record(6.5);
  384. m2.record(5.0);
  385. m2.record(7.0);
  386. m2.record(9.0);
  387. m2.merge(m1);
  388. ensure_equals("Count after merge (p1)", 7, m2.getCount());
  389. ensure_approximately_equals("Min after merge (p1)", F32(3.5), m2.getMin(), 22);
  390. ensure_approximately_equals("Max after merge (p1)", F32(9.0), m2.getMax(), 22);
  391. ensure_approximately_equals("Mean after merge (p1)", F32(41.000/7.000), m2.getMean(), 22);
  392. ensure_equals("Source count of merge is undamaged (p1)", 4, m1.getCount());
  393. ensure_approximately_equals("Source min of merge is undamaged (p1)", F32(3.5), m1.getMin(), 22);
  394. ensure_approximately_equals("Source max of merge is undamaged (p1)", F32(6.5), m1.getMax(), 22);
  395. ensure_approximately_equals("Source mean of merge is undamaged (p1)", F32(5.0), m1.getMean(), 22);
  396. m2.reset();
  397. m2.record(-22.0);
  398. m2.record(-1.0);
  399. m2.record(30.0);
  400. m2.merge(m1);
  401. ensure_equals("Count after merge (p2)", 7, m2.getCount());
  402. ensure_approximately_equals("Min after merge (p2)", F32(-22.0), m2.getMin(), 22);
  403. ensure_approximately_equals("Max after merge (p2)", F32(30.0), m2.getMax(), 22);
  404. ensure_approximately_equals("Mean after merge (p2)", F32(27.000/7.000), m2.getMean(), 22);
  405. }
  406. // Testing LLSimpleStatMMM's merge() method when src contributes nothing
  407. template<> template<>
  408. void stat_counter_index_object_t::test<14>()
  409. {
  410. LLSimpleStatMMM<> m1;
  411. LLSimpleStatMMM<> m2;
  412. m2.record(5.0);
  413. m2.record(7.0);
  414. m2.record(9.0);
  415. m2.merge(m1);
  416. ensure_equals("Count after merge (p1)", 3, m2.getCount());
  417. ensure_approximately_equals("Min after merge (p1)", F32(5.0), m2.getMin(), 22);
  418. ensure_approximately_equals("Max after merge (p1)", F32(9.0), m2.getMax(), 22);
  419. ensure_approximately_equals("Mean after merge (p1)", F32(7.000), m2.getMean(), 22);
  420. ensure_equals("Source count of merge is undamaged (p1)", 0, m1.getCount());
  421. ensure_approximately_equals("Source min of merge is undamaged (p1)", F32(0), m1.getMin(), 22);
  422. ensure_approximately_equals("Source max of merge is undamaged (p1)", F32(0), m1.getMax(), 22);
  423. ensure_approximately_equals("Source mean of merge is undamaged (p1)", F32(0), m1.getMean(), 22);
  424. m2.reset();
  425. m2.record(-22.0);
  426. m2.record(-1.0);
  427. m2.merge(m1);
  428. ensure_equals("Count after merge (p2)", 2, m2.getCount());
  429. ensure_approximately_equals("Min after merge (p2)", F32(-22.0), m2.getMin(), 22);
  430. ensure_approximately_equals("Max after merge (p2)", F32(-1.0), m2.getMax(), 22);
  431. ensure_approximately_equals("Mean after merge (p2)", F32(-11.5), m2.getMean(), 22);
  432. }
  433. // Testing LLSimpleStatMMM's merge() method when dst contributes nothing
  434. template<> template<>
  435. void stat_counter_index_object_t::test<15>()
  436. {
  437. LLSimpleStatMMM<> m1;
  438. LLSimpleStatMMM<> m2;
  439. m1.record(5.0);
  440. m1.record(7.0);
  441. m1.record(9.0);
  442. m2.merge(m1);
  443. ensure_equals("Count after merge (p1)", 3, m2.getCount());
  444. ensure_approximately_equals("Min after merge (p1)", F32(5.0), m2.getMin(), 22);
  445. ensure_approximately_equals("Max after merge (p1)", F32(9.0), m2.getMax(), 22);
  446. ensure_approximately_equals("Mean after merge (p1)", F32(7.000), m2.getMean(), 22);
  447. ensure_equals("Source count of merge is undamaged (p1)", 3, m1.getCount());
  448. ensure_approximately_equals("Source min of merge is undamaged (p1)", F32(5.0), m1.getMin(), 22);
  449. ensure_approximately_equals("Source max of merge is undamaged (p1)", F32(9.0), m1.getMax(), 22);
  450. ensure_approximately_equals("Source mean of merge is undamaged (p1)", F32(7.0), m1.getMean(), 22);
  451. m1.reset();
  452. m2.reset();
  453. m1.record(-22.0);
  454. m1.record(-1.0);
  455. m2.merge(m1);
  456. ensure_equals("Count after merge (p2)", 2, m2.getCount());
  457. ensure_approximately_equals("Min after merge (p2)", F32(-22.0), m2.getMin(), 22);
  458. ensure_approximately_equals("Max after merge (p2)", F32(-1.0), m2.getMax(), 22);
  459. ensure_approximately_equals("Mean after merge (p2)", F32(-11.5), m2.getMean(), 22);
  460. }
  461. // Testing LLSimpleStatMMM's merge() method when neither dst nor src contributes
  462. template<> template<>
  463. void stat_counter_index_object_t::test<16>()
  464. {
  465. LLSimpleStatMMM<> m1;
  466. LLSimpleStatMMM<> m2;
  467. m2.merge(m1);
  468. ensure_equals("Count after merge (p1)", 0, m2.getCount());
  469. ensure_approximately_equals("Min after merge (p1)", F32(0), m2.getMin(), 22);
  470. ensure_approximately_equals("Max after merge (p1)", F32(0), m2.getMax(), 22);
  471. ensure_approximately_equals("Mean after merge (p1)", F32(0), m2.getMean(), 22);
  472. ensure_equals("Source count of merge is undamaged (p1)", 0, m1.getCount());
  473. ensure_approximately_equals("Source min of merge is undamaged (p1)", F32(0), m1.getMin(), 22);
  474. ensure_approximately_equals("Source max of merge is undamaged (p1)", F32(0), m1.getMax(), 22);
  475. ensure_approximately_equals("Source mean of merge is undamaged (p1)", F32(0), m1.getMean(), 22);
  476. }
  477. }