PageRenderTime 61ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/Test/Analyst/BasicDecimal.php

https://github.com/codeactual/hashmark
PHP | 1161 lines | 714 code | 164 blank | 283 comment | 14 complexity | af6e336a6971055572b688e8cb79afb7 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. // vim: fenc=utf-8:ft=php:ai:si:ts=4:sw=4:et:
  3. /**
  4. * Hashmark_TestCase_Analyst_BasicDecimal
  5. *
  6. * @filesource
  7. * @copyright Copyright (c) 2008-2011 David Smith
  8. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  9. * @package Hashmark-Test
  10. * @subpackage Hashmark_Analyst_BasicDecimal
  11. * @version $Id$
  12. */
  13. /**
  14. * - All test dates are in UTC.
  15. *
  16. * @package Hashmark-Test
  17. * @subpackage Hashmark_Analyst_BasicDecimal
  18. */
  19. class Hashmark_TestCase_Analyst_BasicDecimal extends Hashmark_TestCase
  20. {
  21. /**
  22. * @var Hashmark_Analyst_BasicDecimal Fixture instance.
  23. */
  24. protected $_analyst;
  25. /**
  26. * @var Hashmark_Partition Fixture instance.
  27. */
  28. protected $_partition;
  29. /**
  30. * @var Hashmark_Core Fixture instance.
  31. */
  32. protected $_core;
  33. /**
  34. * @var Array Tested subset of Hashmark_Analyst_BasicDecimal:$_aggFunctions.
  35. */
  36. protected static $_aggFunctions = array('AVG', 'SUM', 'MAX', 'MIN');
  37. /**
  38. * Resources needed for most tests.
  39. *
  40. * @return void
  41. */
  42. protected function setUp()
  43. {
  44. parent::setUp();
  45. $partition = Hashmark::getModule('Partition', '', $this->_db);
  46. $this->_analyst = Hashmark::getModule('Analyst', 'BasicDecimal', $this->_db, $partition);
  47. $this->_partition = Hashmark::getModule('Partition', '', $this->_db);
  48. $this->_core = Hashmark::getModule('Core', '', $this->_db);
  49. }
  50. /**
  51. * Public acess to $_aggFunctions.
  52. *
  53. * @return Array
  54. */
  55. public static function getAggFunctions()
  56. {
  57. return self::$_aggFunctions;
  58. }
  59. /**
  60. * Quads: sample DATETIME; sample value; placeholder for matching
  61. * provideValuesAt*() format; boolean true if within date range (inclusive).
  62. *
  63. * - Uses these range boundaries:
  64. * 2008-11-01 01:45:59
  65. * 2009-04-30 01:45:59
  66. * - Distinct and full group AVG/SUM/COUNT for interval groups should differ at least once.
  67. *
  68. * @return Array Test method argument sets.
  69. */
  70. public static function provideValuesSamples()
  71. {
  72. static $data;
  73. if (!$data) {
  74. $data = array();
  75. $data[] = array('2002-07-07 00:00:00', '1000000000000000.0103', null, false);
  76. $data[] = array('2005-05-21 00:00:00', '1000000000000000.9989', null, false);
  77. $data[] = array('2008-10-30 00:00:00', '1000000000000000.3968', null, false);
  78. $data[] = array('2008-11-15 00:00:00', '1000000000000000.1724', null, true);
  79. $data[] = array('2008-11-30 00:00:00', '1000000000000000.6735', null, true);
  80. $data[] = array('2008-12-07 00:00:00', '1000000000000000.1697', null, true);
  81. $data[] = array('2008-12-15 00:00:00', '1000000000000000.3857', null, true);
  82. $data[] = array('2008-12-31 00:00:00', '-1000000000000000.2968', null, true);
  83. $data[] = array('2009-01-01 00:00:00', '1000000000000000.7870', null, true);
  84. $data[] = array('2009-01-15 00:00:00', '1000000000000000.9788', null, true);
  85. $data[] = array('2009-01-31 00:00:00', '1000000000000000.1697', null, true);
  86. $data[] = array('2009-02-01 00:00:00', '1000000000000000.3886', null, true);
  87. $data[] = array('2009-02-14 00:00:00', '-1000000000000000.1970', null, true);
  88. $data[] = array('2009-02-21 00:00:00', '1000000000000000.9788', null, true);
  89. $data[] = array('2009-02-28 00:00:00', '1000000000000000.8564', null, true);
  90. $data[] = array('2009-03-01 00:00:00', '1000000000000000.5109', null, true);
  91. $data[] = array('2009-03-15 00:00:00', '1000000000000000.6109', null, true);
  92. $data[] = array('2009-03-31 00:00:00', '-1000000000000000.1909', null, true);
  93. $data[] = array('2009-04-15 00:00:00', '1000000000000000.5109', null, true);
  94. $data[] = array('2009-04-30 00:00:00', '1000000000000000.5442', null, true);
  95. $data[] = array('2009-05-01 00:00:00', '1000000000000000.5224', null, false);
  96. $data[] = array('2009-07-14 00:00:00', '1000000000000000.2955', null, false);
  97. $data[] = array('2010-12-14 00:00:00', '1000000000000000.2955', null, false);
  98. }
  99. return $data;
  100. }
  101. /**
  102. * Quads: sample DATETIME; sample value; boolean true if most recent value in interval;
  103. * boolean true if within date range (inclusive).
  104. *
  105. * - Uses these range boundaries:
  106. * 2009-06-04 01:45:59
  107. * 2009-06-04 06:45:59
  108. * - Group aggregates consider all values in an interval, not just
  109. * those expected in at-interval sets.
  110. * - Distinct and full group AVG/SUM/COUNT for interval groups should differ at least once.
  111. *
  112. * @return Array Test method argument sets.
  113. */
  114. public static function provideValuesAtIntervalHourSamples()
  115. {
  116. static $data;
  117. if (!$data) {
  118. $data = array();
  119. $data[] = array('2009-06-04 00:00:00', '1000000000000000.4000', false, false);
  120. $data[] = array('2009-06-04 01:30:00', '1000000000000000.5210', false, false);
  121. $data[] = array('2009-06-04 01:50:00', '1000000000000000.6000', true, true);
  122. $data[] = array('2009-06-04 02:00:00', '-1000000000000000.7900', false, true);
  123. $data[] = array('2009-06-04 02:30:00', '1000000000000000.8500', false, true);
  124. $data[] = array('2009-06-04 02:40:00', '1000000000000000.9030', false, true);
  125. $data[] = array('2009-06-04 02:45:00', '1000000000000000.9030', true, true);
  126. $data[] = array('2009-06-04 03:00:00', '1000000000000000.8030', false, true);
  127. $data[] = array('2009-06-04 03:30:00', '1000000000000000.7030', false, true);
  128. $data[] = array('2009-06-04 03:45:00', '-1000000000000000.6030', true, true);
  129. $data[] = array('2009-06-04 04:00:00', '1000000000000000.5932', false, true);
  130. $data[] = array('2009-06-04 04:30:00', '1000000000000000.4000', false, true);
  131. $data[] = array('2009-06-04 04:45:00', '1000000000000000.3000', true, true);
  132. $data[] = array('2009-06-04 05:00:00', '1000000000000000.2030', false, true);
  133. $data[] = array('2009-06-04 05:30:00', '1000000000000000.1210', false, true);
  134. $data[] = array('2009-06-04 05:35:00', '1000000000000000.1210', false, true);
  135. $data[] = array('2009-06-04 05:45:00', '1000000000000000.2000', true, true);
  136. $data[] = array('2009-06-04 06:00:00', '1000000000000000.3900', false, true);
  137. $data[] = array('2009-06-04 06:30:00', '-1000000000000000.4000', false, true);
  138. $data[] = array('2009-06-04 06:45:00', '1000000000000000.5030', true, true);
  139. $data[] = array('2009-06-04 07:00:00', '1000000000000000.6900', false, false);
  140. }
  141. return $data;
  142. }
  143. /**
  144. * Quads: sample DATETIME; sample value; boolean true if most recent value in interval;
  145. * boolean true if within date range (inclusive).
  146. *
  147. * - Uses these range boundaries:
  148. * 2009-06-04 01:45:59
  149. * 2009-06-11 01:45:59
  150. * - Group aggregates consider all values in an interval, not just
  151. * those expected in at-interval sets.
  152. * - Distinct and full group AVG/SUM/COUNT for interval groups should differ at least once.
  153. *
  154. * @return Array Test method argument sets.
  155. */
  156. public static function provideValuesAtIntervalDaySamples()
  157. {
  158. static $data;
  159. if (!$data) {
  160. $data = array();
  161. $data[] = array('2009-06-03 00:00:00', '1000000000000000.3432', false, false);
  162. $data[] = array('2009-06-04 00:00:00', '1000000000000000.4000', false, false);
  163. $data[] = array('2009-06-04 11:00:00', '1000000000000000.5210', false, true);
  164. $data[] = array('2009-06-04 22:00:00', '1000000000000000.1946', true, true);
  165. $data[] = array('2009-06-05 00:00:00', '1000000000000000.7904', false, true);
  166. $data[] = array('2009-06-05 11:00:00', '1000000000000000.8553', false, true);
  167. $data[] = array('2009-06-05 22:00:00', '1000000000000000.9365', true, true);
  168. $data[] = array('2009-06-06 00:00:00', '1000000000000000.5377', false, true);
  169. $data[] = array('2009-06-06 11:00:00', '1000000000000000.4089', false, true);
  170. $data[] = array('2009-06-06 22:00:00', '1000000000000000.3397', true, true);
  171. $data[] = array('2009-06-07 00:00:00', '1000000000000000.9184', false, true);
  172. $data[] = array('2009-06-07 05:00:00', '1000000000000000.2000', false, true);
  173. $data[] = array('2009-06-07 11:00:00', '1000000000000000.3224', false, true);
  174. $data[] = array('2009-06-07 22:00:00', '1000000000000000.2000', true, true);
  175. $data[] = array('2009-06-08 00:00:00', '-1000000000000000.0549', false, true);
  176. $data[] = array('2009-06-08 11:00:00', '1000000000000000.5947', false, true);
  177. $data[] = array('2009-06-08 22:00:00', '1000000000000000.9635', true, true);
  178. $data[] = array('2009-06-09 00:00:00', '1000000000000000.3720', false, true);
  179. $data[] = array('2009-06-09 11:00:00', '1000000000000000.2027', false, true);
  180. $data[] = array('2009-06-09 22:00:00', '1000000000000000.1946', true, true);
  181. $data[] = array('2009-06-10 00:00:00', '1000000000000000.9821', false, true);
  182. $data[] = array('2009-06-10 11:00:00', '1000000000000000.3701', false, true);
  183. $data[] = array('2009-06-10 22:00:00', '-1000000000000000.4504', true, true);
  184. $data[] = array('2009-06-11 00:00:00', '1000000000000000.5030', false, true);
  185. $data[] = array('2009-06-11 00:30:00', '1000000000000000.6810', false, true);
  186. $data[] = array('2009-06-11 01:00:00', '1000000000000000.6810', true, true);
  187. $data[] = array('2009-06-12 03:00:00', '1000000000000000.8604', false, false);
  188. }
  189. return $data;
  190. }
  191. /**
  192. * Quads: sample DATETIME; sample value; boolean true if most recent value in interval;
  193. * boolean true if within date range (inclusive).
  194. *
  195. * - Uses these range boundaries:
  196. * 2009-05-31 01:45:59
  197. * 2009-07-12 01:45:59
  198. * - Group aggregates consider all values in an interval, not just
  199. * those expected in at-interval sets.
  200. * - Distinct and full group AVG/SUM/COUNT for interval groups should differ at least once.
  201. *
  202. * @return Array Test method argument sets.
  203. */
  204. public static function provideValuesAtIntervalWeekSamples()
  205. {
  206. static $data;
  207. if (!$data) {
  208. $data = array();
  209. $data[] = array('2008-05-30 03:45:00', '1000000000000000.1332', false, false);
  210. $data[] = array('2009-06-03 03:14:21', '-1000000000000000.8809', false, true);
  211. $data[] = array('2009-06-06 03:36:59', '1000000000000000.9634', false, true);
  212. $data[] = array('2009-06-06 03:37:59', '1000000000000000.8231', false, true);
  213. $data[] = array('2009-06-07 03:37:59', '1000000000000000.7530', true, true);
  214. $data[] = array('2009-06-10 03:44:59', '1000000000000000.6330', false, true);
  215. $data[] = array('2009-06-11 03:44:59', '1000000000000000.6330', false, true);
  216. $data[] = array('2009-06-13 03:45:01', '1000000000000000.5831', false, true);
  217. $data[] = array('2009-06-13 21:01:01', '1000000000000000.4604', false, true);
  218. $data[] = array('2009-06-14 03:01:01', '-1000000000000000.0618', true, true);
  219. $data[] = array('2009-06-17 04:01:01', '1000000000000000.1103', false, true);
  220. $data[] = array('2009-06-20 01:01:01', '1000000000000000.6207', false, true);
  221. $data[] = array('2009-06-20 04:00:00', '1000000000000000.3006', false, true);
  222. $data[] = array('2009-06-21 10:30:07', '1000000000000000.2206', true, true);
  223. $data[] = array('2009-06-24 10:42:07', '1000000000000000.3028', false, true);
  224. $data[] = array('2009-06-25 09:45:10', '1000000000000000.7600', false, true);
  225. $data[] = array('2009-06-27 02:01:01', '1000000000000000.4705', false, true);
  226. $data[] = array('2009-06-27 09:45:10', '1000000000000000.7600', false, true);
  227. $data[] = array('2009-06-28 01:45:20', '1000000000000000.5101', true, true);
  228. $data[] = array('2009-07-01 20:14:32', '-1000000000000000.0310', false, true);
  229. $data[] = array('2009-07-05 00:00:00', '1000000000000000.7300', false, true);
  230. $data[] = array('2009-07-05 01:30:00', '1000000000000000.4513', true, true);
  231. $data[] = array('2009-07-08 01:30:00', '1000000000000000.5516', false, true);
  232. $data[] = array('2009-07-11 01:25:00', '1000000000000000.5516', false, true);
  233. $data[] = array('2009-07-12 01:30:00', '1000000000000000.4412', true, true);
  234. $data[] = array('2009-08-16 01:30:00', '1000000000000000.3118', false, false);
  235. $data[] = array('2010-07-05 00:00:00', '1000000000000000.1009', false, false);
  236. }
  237. return $data;
  238. }
  239. /**
  240. * Quads: sample DATETIME; sample value; boolean true if most recent value in interval;
  241. * boolean true if within date range (inclusive).
  242. *
  243. * - Uses these range boundaries:
  244. * 2009-01-01 01:45:59
  245. * 2009-06-30 01:45:59
  246. * - Group aggregates consider all values in an interval, not just
  247. * those expected in at-interval sets.
  248. * - Distinct and full group AVG/SUM/COUNT for interval groups should differ at least once.
  249. *
  250. * @return Array Test method argument sets.
  251. */
  252. public static function provideValuesAtIntervalMonthSamples()
  253. {
  254. static $data;
  255. if (!$data) {
  256. $data = array();
  257. $data[] = array('2008-12-31 23:45:01', '1000000000000000.5932', false, false);
  258. $data[] = array('2009-01-01 03:37:59', '1000000000000000.7030', false, true);
  259. $data[] = array('2009-01-15 03:44:59', '1000000000000000.6030', false, true);
  260. $data[] = array('2009-01-31 03:45:00', '-1000000000000000.1932', false, true);
  261. $data[] = array('2009-01-31 09:45:00', '-1000000000000000.1932', true, true);
  262. $data[] = array('2009-02-01 00:00:00', '1000000000000000.2000', false, true);
  263. $data[] = array('2009-02-07 03:36:59', '1000000000000000.9030', false, true);
  264. $data[] = array('2009-02-15 03:14:21', '1000000000000000.8500', false, true);
  265. $data[] = array('2009-02-28 03:36:59', '1000000000000000.9030', false, true);
  266. $data[] = array('2009-02-28 03:37:59', '1000000000000000.8030', true, true);
  267. $data[] = array('2009-03-01 03:37:59', '1000000000000000.7030', false, true);
  268. $data[] = array('2009-03-15 03:44:59', '1000000000000000.6030', false, true);
  269. $data[] = array('2009-03-31 03:45:01', '1000000000000000.5932', false, true);
  270. $data[] = array('2009-03-31 21:01:01', '-1000000000000000.6210', true, true);
  271. $data[] = array('2009-04-01 03:01:01', '1000000000000000.9213', false, true);
  272. $data[] = array('2009-04-15 04:01:01', '1000000000000000.8500', false, true);
  273. $data[] = array('2009-04-30 01:01:01', '1000000000000000.4000', false, true);
  274. $data[] = array('2009-04-30 04:00:00', '1000000000000000.3020', true, true);
  275. $data[] = array('2009-05-01 10:30:07', '1000000000000000.2400', false, true);
  276. $data[] = array('2009-05-15 10:42:07', '-1000000000000000.3400', false, true);
  277. $data[] = array('2009-05-31 02:01:01', '1000000000000000.4000', false, true);
  278. $data[] = array('2009-05-31 09:45:10', '1000000000000000.4400', true, true);
  279. $data[] = array('2009-06-01 01:45:20', '1000000000000000.5400', false, true);
  280. $data[] = array('2009-06-07 01:30:00', '1000000000000000.9213', false, true);
  281. $data[] = array('2009-06-15 20:14:32', '-1000000000000000.6210', false, true);
  282. $data[] = array('2009-06-30 00:00:00', '1000000000000000.7000', false, true);
  283. $data[] = array('2009-06-30 01:30:00', '1000000000000000.9213', true, true);
  284. $data[] = array('2009-06-30 11:42:00', '1000000000000000.9213', false, false);
  285. $data[] = array('2009-07-01 00:00:00', '1000000000000000.9000', false, false);
  286. }
  287. return $data;
  288. }
  289. /**
  290. * Quads: sample DATETIME; sample value; boolean true if most recent value in interval;
  291. * boolean true if within date range (inclusive).
  292. *
  293. * - Uses these range boundaries:
  294. * 2009-01-01 01:45:59
  295. * 2012-12-31 01:45:59
  296. * - Group aggregates consider all values in an interval, not just
  297. * those expected in at-interval sets.
  298. * - Distinct and full group AVG/SUM/COUNT for interval groups should differ at least once.
  299. *
  300. * @return Array Test method argument sets.
  301. */
  302. public static function provideValuesAtIntervalYearSamples()
  303. {
  304. static $data;
  305. if (!$data) {
  306. $data = array();
  307. $data[] = array('2008-12-31 23:45:01', '1000000000000000.5932', false, false);
  308. $data[] = array('2009-01-01 04:01:01', '1000000000000000.8500', false, true);
  309. $data[] = array('2009-06-01 01:01:01', '1000000000000000.4907', false, true);
  310. $data[] = array('2009-12-31 04:00:00', '1000000000000000.3020', false, true);
  311. $data[] = array('2009-12-31 05:00:00', '1000000000000000.6355', true, true);
  312. $data[] = array('2010-01-01 10:30:07', '1000000000000000.2400', false, true);
  313. $data[] = array('2010-06-01 10:42:07', '1000000000000000.3451', false, true);
  314. $data[] = array('2010-09-01 10:30:07', '1000000000000000.2400', false, true);
  315. $data[] = array('2010-12-31 02:01:01', '1000000000000000.7182', false, true);
  316. $data[] = array('2010-12-31 03:01:01', '-1000000000000000.3712', true, true);
  317. $data[] = array('2011-01-01 09:45:10', '1000000000000000.4407', false, true);
  318. $data[] = array('2011-06-01 01:45:20', '1000000000000000.5404', false, true);
  319. $data[] = array('2011-12-31 20:14:32', '1000000000000000.6210', false, true);
  320. $data[] = array('2011-12-31 21:14:32', '-1000000000000000.9123', true, true);
  321. $data[] = array('2012-01-01 00:00:00', '1000000000000000.7001', false, true);
  322. $data[] = array('2012-06-01 01:30:00', '1000000000000000.9213', false, true);
  323. $data[] = array('2012-12-31 00:42:00', '-1000000000000000.8577', false, true);
  324. $data[] = array('2012-12-31 01:27:00', '1000000000000000.9213', true, true);
  325. $data[] = array('2013-01-01 00:00:00', '1000000000000000.1992', false, false);
  326. }
  327. return $data;
  328. }
  329. /**
  330. * Returns samples, and associated fields like data range,
  331. * from provide*() methods like provideValuesAtIntervalHourSamples().
  332. *
  333. * - Does not use @dataProvider format.
  334. *
  335. * @param string $name Provider method name.
  336. * @return Array If $name is empty, all sample data; otherwise
  337. * only the named section.
  338. */
  339. public static function provideFullSamplesData($name = '')
  340. {
  341. static $data;
  342. if (!$data) {
  343. $data = array();
  344. $data['provideValuesSamples'] = array('samples' => self::provideValuesSamples(),
  345. 'rangeStart' => '2008-11-01 01:45:59',
  346. 'rangeEnd' => '2009-04-30 01:45:59');
  347. $data['provideValuesAtIntervalHourSamples'] = array('interval' => 'h',
  348. 'samples' => self::provideValuesAtIntervalHourSamples(),
  349. 'rangeStart' => '2009-06-04 01:45:59',
  350. 'rangeEnd' => '2009-06-04 06:45:59');
  351. $data['provideValuesAtIntervalDaySamples'] = array('interval' => 'd',
  352. 'samples' => self::provideValuesAtIntervalDaySamples(),
  353. 'rangeStart' => '2009-06-04 01:45:59',
  354. 'rangeEnd' => '2009-06-11 01:45:59');
  355. $data['provideValuesAtIntervalWeekSamples'] = array('interval' => 'w',
  356. 'samples' => self::provideValuesAtIntervalWeekSamples(),
  357. 'rangeStart' => '2009-05-31 01:45:59',
  358. 'rangeEnd' => '2009-07-12 01:45:59');
  359. $data['provideValuesAtIntervalMonthSamples'] = array('interval' => 'm',
  360. 'samples' => self::provideValuesAtIntervalMonthSamples(),
  361. 'rangeStart' => '2009-01-01 01:45:59',
  362. 'rangeEnd' => '2009-06-30 01:45:59');
  363. $data['provideValuesAtIntervalYearSamples'] = array('interval' => 'y',
  364. 'samples' => self::provideValuesAtIntervalYearSamples(),
  365. 'rangeStart' => '2009-01-01 01:45:59',
  366. 'rangeEnd' => '2012-12-31 01:45:59');
  367. }
  368. if (!$name) {
  369. return $data;
  370. }
  371. if (isset($data[$name])) {
  372. return $data[$name];
  373. }
  374. return false;
  375. }
  376. /**
  377. * Return expected aggregate/change/moving/etc. values based on samples
  378. * from provideValuesSamples(), provideValuesSamplesAtInterval*, etc.
  379. *
  380. * - Does not use @dataProvider format.
  381. *
  382. * @param string $name Name of section in provider.php data.
  383. * @return Array If $name is empty, all provider.php data; otherwise
  384. * only the named section.
  385. * @see Test/BasicDecimal/Tool/ scripts for recalculating expected values.
  386. */
  387. public static function provideExpectedValues($name = '')
  388. {
  389. static $expProviders;
  390. if (!$expProviders) {
  391. require_once HASHMARK_ROOT_DIR . '/Test/Analyst/BasicDecimal/Data/provider.php';
  392. }
  393. if (!$name) {
  394. return $expProviders;
  395. }
  396. if (isset($expProviders[$name])) {
  397. return $expProviders[$name];
  398. }
  399. return false;
  400. }
  401. /**
  402. * @test
  403. * @group BasicDecimal
  404. * @group hasGeneratedProviderData
  405. */
  406. public function hasGeneratedProviderData()
  407. {
  408. $this->assertTrue(is_readable(HASHMARK_ROOT_DIR . '/Test/Analyst/BasicDecimal/Data/provider.php'),
  409. 'Generate data: php -f Test/Analyst/BasicDecimal/Tool/writeProviderData.php');
  410. }
  411. /**
  412. * @test
  413. * @group Analyst
  414. * @group BasicDecimal
  415. * @group throwsOnMissingSql
  416. * @group query
  417. */
  418. public function throwsOnMissingSql()
  419. {
  420. $thrown = false;
  421. $values = array();
  422. foreach (array('', array(), 1) as $sql) {
  423. try {
  424. $this->_analyst->multiQuery($sql, $values);
  425. } catch (Exception $e) {
  426. $thrown = true;
  427. }
  428. $this->assertTrue($thrown);
  429. }
  430. }
  431. /**
  432. * @test
  433. * @group BasicDecimal
  434. * @group findsValues
  435. * @group values
  436. * @group decimal
  437. * @group createScalar
  438. * @group createSample
  439. */
  440. public function findsValues()
  441. {
  442. $scalarFields = array('name' => self::randomString(), 'type' => 'decimal');
  443. $scalarId = $this->_core->createScalar($scalarFields);
  444. $sampleProvider = self::provideFullSamplesData('provideValuesSamples');
  445. $this->assertFalse(empty($sampleProvider));
  446. $expValues = array();
  447. foreach ($sampleProvider['samples'] as $sample) {
  448. list($end, $value, , $isInRange) = $sample;
  449. if ($isInRange) {
  450. $expValues[$end] = $value;
  451. }
  452. $this->_partition->createSample($scalarId, $value, $end);
  453. }
  454. $actValues = $this->_analyst->values($scalarId, 50, $sampleProvider['rangeStart'], $sampleProvider['rangeEnd']);
  455. $this->assertEquals(count($expValues), count($actValues));
  456. foreach ($actValues as $actual) {
  457. $this->assertDecimalEquals($expValues[$actual['x']], $actual['y']);
  458. }
  459. }
  460. /**
  461. * @test
  462. * @group BasicDecimal
  463. * @group findsValuesAtInterval
  464. * @group valuesAtInterval
  465. * @group decimal
  466. * @group createScalar
  467. * @group createSample
  468. */
  469. public function findsValuesAtInterval()
  470. {
  471. $intervalProviders = array(self::provideFullSamplesData('provideValuesAtIntervalHourSamples'),
  472. self::provideFullSamplesData('provideValuesAtIntervalDaySamples'),
  473. self::provideFullSamplesData('provideValuesAtIntervalWeekSamples'),
  474. self::provideFullSamplesData('provideValuesAtIntervalMonthSamples'),
  475. self::provideFullSamplesData('provideValuesAtIntervalHourSamples'));
  476. foreach ($intervalProviders as $sampleProvider) {
  477. $this->assertFalse(empty($sampleProvider));
  478. $sampleSets = array($sampleProvider['samples'], array_reverse($sampleProvider['samples']));
  479. foreach ($sampleSets as $samples) {
  480. $scalarFields = array('name' => self::randomString(), 'type' => 'decimal');
  481. $scalarId = $this->_core->createScalar($scalarFields);
  482. $expValues = array();
  483. foreach ($samples as $sample) {
  484. list($end, $value, $isMostRecentInInterval) = $sample;
  485. if ($isMostRecentInInterval) {
  486. $expValues[$end] = $value;
  487. }
  488. $this->_partition->createSample($scalarId, $value, $end);
  489. }
  490. $actValues = $this->_analyst->valuesAtInterval($scalarId, 50, $sampleProvider['rangeStart'], $sampleProvider['rangeEnd'], $sampleProvider['interval']);
  491. $errorMsg = "int={$sampleProvider['interval']}";
  492. $this->assertEquals(count($expValues), count($actValues), $errorMsg);
  493. foreach ($actValues as $actual) {
  494. $this->assertDecimalEquals($expValues[$actual['x']], $actual['y'], $errorMsg . " x={$actual['x']}");
  495. }
  496. }
  497. }
  498. }
  499. /**
  500. * @test
  501. * @group BasicDecimal
  502. * @group findsValuesAgg
  503. * @group valuesAgg
  504. * @group decimal
  505. * @group createScalar
  506. * @group createSample
  507. */
  508. public function findsValuesAgg()
  509. {
  510. $scalarFields = array('name' => self::randomString(), 'type' => 'decimal');
  511. $scalarId = $this->_core->createScalar($scalarFields);
  512. $sampleProvider = self::provideFullSamplesData('provideValuesSamples');
  513. $this->assertFalse(empty($sampleProvider));
  514. $expValues = self::provideExpectedValues('provideValuesAgg');
  515. $this->assertFalse(empty($expValues));
  516. foreach ($sampleProvider['samples'] as $sample) {
  517. list($end, $value) = $sample;
  518. $this->_partition->createSample($scalarId, $value, $end);
  519. }
  520. foreach (self::$_aggFunctions as $aggFunc) {
  521. $errorMsg = "val=ALL f={$aggFunc}";
  522. $actual = $this->_analyst->valuesAgg($scalarId, $sampleProvider['rangeStart'], $sampleProvider['rangeEnd'], $aggFunc, false);
  523. $this->assertDecimalEquals($expValues['ALL'][$aggFunc], $actual, $errorMsg);
  524. $errorMsg = "val=DIS f={$aggFunc}";
  525. $actual = $this->_analyst->valuesAgg($scalarId, $sampleProvider['rangeStart'], $sampleProvider['rangeEnd'], $aggFunc, true);
  526. $this->assertDecimalEquals($expValues['DIS'][$aggFunc], $actual, $errorMsg);
  527. }
  528. }
  529. /**
  530. * @test
  531. * @group BasicDecimal
  532. * @group findsValuesAggAtInterval
  533. * @group valuesAggAtInterval
  534. * @group decimal
  535. * @group createScalar
  536. * @group createSample
  537. */
  538. public function findsValuesAggAtInterval()
  539. {
  540. $allSampleProviders = self::provideFullSamplesData();
  541. $this->assertFalse(empty($allSampleProviders));
  542. $expProvider = self::provideExpectedValues('provideValuesAggAtInterval');
  543. $this->assertFalse(empty($expProvider));
  544. foreach ($expProvider as $sampleProviderName => $expValues) {
  545. $sampleProvider = $allSampleProviders[$sampleProviderName];
  546. $this->assertFalse(empty($sampleProvider));
  547. $expCount = count($expValues['ALL']['AVG']);
  548. $expDistinctCount = count($expValues['DIS']['AVG']);
  549. $sampleSets = array($sampleProvider['samples'], array_reverse($sampleProvider['samples']));
  550. foreach ($sampleSets as $samples) {
  551. $scalarFields = array('name' => self::randomString(), 'type' => 'decimal');
  552. $scalarId = $this->_core->createScalar($scalarFields);
  553. foreach ($samples as $sample) {
  554. list($end, $value) = $sample;
  555. $this->_partition->createSample($scalarId, $value, $end);
  556. }
  557. foreach (self::$_aggFunctions as $aggFunc) {
  558. $errorMsg = "data={$sampleProviderName} val=ALL f={$aggFunc} int={$sampleProvider['interval']}";
  559. $actValues = $this->_analyst->valuesAggAtInterval($scalarId, $sampleProvider['rangeStart'], $sampleProvider['rangeEnd'], $sampleProvider['interval'], $aggFunc, false);
  560. $this->assertEquals($expCount, count($actValues), $errorMsg);
  561. foreach ($actValues as $actual) {
  562. $this->assertDecimalEquals($expValues['ALL'][$aggFunc][$actual['x']], $actual['y'], $errorMsg . " x={$actual['x']}");
  563. }
  564. $errorMsg = "data={$sampleProviderName} val=DIS f={$aggFunc} int={$sampleProvider['interval']}";
  565. $actValues = $this->_analyst->valuesAggAtInterval($scalarId, $sampleProvider['rangeStart'], $sampleProvider['rangeEnd'], $sampleProvider['interval'], $aggFunc, true);
  566. $this->assertEquals($expDistinctCount, count($actValues), $errorMsg);
  567. foreach ($actValues as $actual) {
  568. $this->assertDecimalEquals($expValues['DIS'][$aggFunc][$actual['x']], $actual['y'], $errorMsg . " x={$actual['x']}");
  569. }
  570. }
  571. }
  572. }
  573. }
  574. /**
  575. * @test
  576. * @group BasicDecimal
  577. * @group findsValuesNestedAggsAtInterval
  578. * @group valuesNestedAggAtInterval
  579. * @group decimal
  580. * @group createScalar
  581. * @group createSample
  582. */
  583. public function findsValuesNestedAggsAtInterval()
  584. {
  585. $allSampleProviders = self::provideFullSamplesData();
  586. $this->assertFalse(empty($allSampleProviders));
  587. $expProvider = self::provideExpectedValues('provideValuesNestedAggAtInterval');
  588. $this->assertFalse(empty($expProvider));
  589. foreach ($expProvider as $sampleProviderName => $expValues) {
  590. $sampleProvider = $allSampleProviders[$sampleProviderName];
  591. $this->assertFalse(empty($sampleProvider));
  592. $scalarFields = array('name' => self::randomString(), 'type' => 'decimal');
  593. $scalarId = $this->_core->createScalar($scalarFields);
  594. foreach ($sampleProvider['samples'] as $sample) {
  595. list($end, $value) = $sample;
  596. $this->_partition->createSample($scalarId, $value, $end);
  597. }
  598. foreach (self::$_aggFunctions as $aggFuncOuter) {
  599. foreach (self::$_aggFunctions as $aggFuncInner) {
  600. $errorMsg = "data={$sampleProviderName} val=ALL func={$aggFuncOuter}({$aggFuncInner}) int={$sampleProvider['interval']}";
  601. $actualAgg = $this->_analyst->valuesNestedAggAtInterval($scalarId, $sampleProvider['rangeStart'], $sampleProvider['rangeEnd'], $sampleProvider['interval'], $aggFuncOuter, false, $aggFuncInner, false);
  602. $this->assertDecimalEquals($expValues['ALL'][$aggFuncOuter][$aggFuncInner], $actualAgg, $errorMsg);
  603. $errorMsg = "data={$sampleProviderName} val=DIS_INNER func={$aggFuncOuter}({$aggFuncInner}) int={$sampleProvider['interval']}";
  604. $actualAgg = $this->_analyst->valuesNestedAggAtInterval($scalarId, $sampleProvider['rangeStart'], $sampleProvider['rangeEnd'], $sampleProvider['interval'], $aggFuncOuter, false, $aggFuncInner, true);
  605. $this->assertDecimalEquals($expValues['DIS_INNER'][$aggFuncOuter][$aggFuncInner], $actualAgg, $errorMsg);
  606. $errorMsg = "data={$sampleProviderName} val=DIS_OUTER func={$aggFuncOuter}({$aggFuncInner}) int={$sampleProvider['interval']}";
  607. $actualAgg = $this->_analyst->valuesNestedAggAtInterval($scalarId, $sampleProvider['rangeStart'], $sampleProvider['rangeEnd'], $sampleProvider['interval'], $aggFuncOuter, true, $aggFuncInner, false);
  608. $this->assertDecimalEquals($expValues['DIS_OUTER'][$aggFuncOuter][$aggFuncInner], $actualAgg, $errorMsg);
  609. $errorMsg = "data={$sampleProviderName} val=DIS_BOTH func={$aggFuncOuter}({$aggFuncInner}) int={$sampleProvider['interval']}";
  610. $actualAgg = $this->_analyst->valuesNestedAggAtInterval($scalarId, $sampleProvider['rangeStart'], $sampleProvider['rangeEnd'], $sampleProvider['interval'], $aggFuncOuter, true, $aggFuncInner, true);
  611. $this->assertDecimalEquals($expValues['DIS_BOTH'][$aggFuncOuter][$aggFuncInner], $actualAgg, $errorMsg);
  612. }
  613. }
  614. }
  615. }
  616. /**
  617. * @test
  618. * @group BasicDecimal
  619. * @group findsValuesAggAtRecurrence
  620. * @group valuesAggAtRecurrence
  621. * @group decimal
  622. * @group createScalar
  623. * @group createSample
  624. */
  625. public function findsValuesAggAtRecurrence()
  626. {
  627. $allSampleProviders = self::provideFullSamplesData();
  628. $this->assertFalse(empty($allSampleProviders));
  629. $expProvider = self::provideExpectedValues('provideValuesAggAtRecurrence');
  630. $this->assertFalse(empty($expProvider));
  631. foreach ($expProvider as $sampleProviderName => $expValues) {
  632. $sampleProvider = $allSampleProviders[$sampleProviderName];
  633. $this->assertFalse(empty($sampleProvider));
  634. $scalarFields = array('name' => self::randomString(), 'type' => 'decimal');
  635. $scalarId = $this->_core->createScalar($scalarFields);
  636. foreach ($sampleProvider['samples'] as $sample) {
  637. list($end, $value) = $sample;
  638. $this->_partition->createSample($scalarId, $value, $end);
  639. }
  640. foreach (Hashmark_Analyst_BasicDecimal::getRecurFunctions() as $recurFunc) {
  641. foreach (self::$_aggFunctions as $aggFunc) {
  642. $errorMsg = "data={$sampleProviderName} val=ALL recur={$recurFunc} agg={$aggFunc}";
  643. $actValues = $this->_analyst->valuesAggAtRecurrence($scalarId, $sampleProvider['rangeStart'], $sampleProvider['rangeEnd'], $recurFunc, $aggFunc, false);
  644. foreach ($actValues as $actual) {
  645. $this->assertDecimalEquals($expValues['ALL'][$recurFunc][$actual['x']][$aggFunc], $actual['y'], $errorMsg . " x={$actual['x']}");
  646. }
  647. $errorMsg = "data={$sampleProviderName} val=DIS recur={$recurFunc} agg={$aggFunc}";
  648. $actValues = $this->_analyst->valuesAggAtRecurrence($scalarId, $sampleProvider['rangeStart'], $sampleProvider['rangeEnd'], $recurFunc, $aggFunc, true);
  649. foreach ($actValues as $actual) {
  650. $this->assertDecimalEquals($expValues['DIS'][$recurFunc][$actual['x']][$aggFunc], $actual['y'], $errorMsg . " x={$actual['x']}");
  651. }
  652. }
  653. }
  654. }
  655. }
  656. /**
  657. * @test
  658. * @group BasicDecimal
  659. * @group findsChanges
  660. * @group changes
  661. * @group decimal
  662. * @group createScalar
  663. * @group createSample
  664. */
  665. public function findsChanges()
  666. {
  667. $allSampleProviders = self::provideFullSamplesData();
  668. $this->assertFalse(empty($allSampleProviders));
  669. $expProvider = self::provideExpectedValues('provideChanges');
  670. $this->assertFalse(empty($expProvider));
  671. foreach ($expProvider as $sampleProviderName => $expValues) {
  672. $sampleProvider = $allSampleProviders[$sampleProviderName];
  673. $this->assertFalse(empty($sampleProvider));
  674. $scalarFields = array('name' => self::randomString(), 'type' => 'decimal');
  675. $scalarId = $this->_core->createScalar($scalarFields);
  676. foreach ($sampleProvider['samples'] as $sample) {
  677. list($end, $value) = $sample;
  678. $this->_partition->createSample($scalarId, $value, $end);
  679. }
  680. $errorMsg = "data={$sampleProviderName}";
  681. $actValues = $this->_analyst->changes($scalarId, 50, $sampleProvider['rangeStart'], $sampleProvider['rangeEnd']);
  682. $this->assertEquals(count($expValues), count($actValues), $errorMsg);
  683. foreach ($actValues as $actual) {
  684. $this->assertDecimalEquals($expValues[$actual['x']], $actual['y2'], $errorMsg . " x={$actual['x']}");
  685. }
  686. }
  687. }
  688. /**
  689. * @test
  690. * @group BasicDecimal
  691. * @group findsChangesAtInterval
  692. * @group changesAtInterval
  693. * @group decimal
  694. * @group createScalar
  695. * @group createSample
  696. */
  697. public function findsChangesAtInterval()
  698. {
  699. $allSampleProviders = self::provideFullSamplesData();
  700. $this->assertFalse(empty($allSampleProviders));
  701. $expProvider = self::provideExpectedValues('provideChangesAtInterval');
  702. $this->assertFalse(empty($expProvider));
  703. foreach ($expProvider as $sampleProviderName => $expValues) {
  704. $sampleProvider = $allSampleProviders[$sampleProviderName];
  705. $this->assertFalse(empty($sampleProvider));
  706. $scalarFields = array('name' => self::randomString(), 'type' => 'decimal');
  707. $scalarId = $this->_core->createScalar($scalarFields);
  708. foreach ($sampleProvider['samples'] as $sample) {
  709. list($end, $value) = $sample;
  710. $this->_partition->createSample($scalarId, $value, $end);
  711. }
  712. $actValues = $this->_analyst->changesAtInterval($scalarId, 50, $sampleProvider['rangeStart'], $sampleProvider['rangeEnd'], $sampleProvider['interval']);
  713. $errorMsg = "data={$sampleProviderName} int={$sampleProvider['interval']}";
  714. $this->assertEquals(count($expValues), count($actValues), $errorMsg);
  715. foreach ($actValues as $actual) {
  716. $this->assertDecimalEquals($expValues[$actual['x']], $actual['y2'], $errorMsg . " x={$actual['x']}");
  717. }
  718. }
  719. }
  720. /**
  721. * @test
  722. * @group BasicDecimal
  723. * @group findsChangesAgg
  724. * @group changesAgg
  725. * @group decimal
  726. * @group createScalar
  727. * @group createSample
  728. */
  729. public function findsChangesAgg()
  730. {
  731. $allSampleProviders = self::provideFullSamplesData();
  732. $this->assertFalse(empty($allSampleProviders));
  733. $expProvider = self::provideExpectedValues('provideChangesAgg');
  734. $this->assertFalse(empty($expProvider));
  735. foreach ($expProvider as $sampleProviderName => $expValues) {
  736. $sampleProvider = $allSampleProviders[$sampleProviderName];
  737. $this->assertFalse(empty($sampleProvider));
  738. $scalarFields = array('name' => self::randomString(), 'type' => 'decimal');
  739. $scalarId = $this->_core->createScalar($scalarFields);
  740. foreach ($sampleProvider['samples'] as $sample) {
  741. list($end, $value) = $sample;
  742. $this->_partition->createSample($scalarId, $value, $end);
  743. }
  744. foreach (self::$_aggFunctions as $aggFunc) {
  745. $errorMsg = "val=ALL f={$aggFunc}";
  746. $actual = $this->_analyst->changesAgg($scalarId, $sampleProvider['rangeStart'], $sampleProvider['rangeEnd'], $aggFunc, false);
  747. $this->assertDecimalEquals($expValues['ALL'][$aggFunc], $actual, $errorMsg);
  748. $errorMsg = "val=DIS f={$aggFunc}";
  749. $actual = $this->_analyst->changesAgg($scalarId, $sampleProvider['rangeStart'], $sampleProvider['rangeEnd'], $aggFunc, true);
  750. $this->assertDecimalEquals($expValues['DIS'][$aggFunc], $actual, $errorMsg);
  751. }
  752. }
  753. }
  754. /**
  755. * @test
  756. * @group BasicDecimal
  757. * @group findsChangesAggAtInterval
  758. * @group changesAggAtInterval
  759. * @group decimal
  760. * @group createScalar
  761. * @group createSample
  762. */
  763. public function findsChangesAggAtInterval()
  764. {
  765. $allSampleProviders = self::provideFullSamplesData();
  766. $this->assertFalse(empty($allSampleProviders));
  767. $expProvider = self::provideExpectedValues('provideChangesAggAtInterval');
  768. $this->assertFalse(empty($expProvider));
  769. foreach ($expProvider as $sampleProviderName => $expValues) {
  770. $sampleProvider = $allSampleProviders[$sampleProviderName];
  771. $this->assertFalse(empty($sampleProvider));
  772. $aggCount = count($expValues['ALL']['AVG']);
  773. $aggDistinctCount = count($expValues['DIS']['AVG']);
  774. $scalarFields = array('name' => self::randomString(), 'type' => 'decimal');
  775. $scalarId = $this->_core->createScalar($scalarFields);
  776. foreach ($sampleProvider['samples'] as $sample) {
  777. list($end, $value) = $sample;
  778. $this->_partition->createSample($scalarId, $value, $end);
  779. }
  780. foreach (self::$_aggFunctions as $aggFunc) {
  781. $errorMsg = "data={$sampleProviderName} val=ALL f={$aggFunc} int={$sampleProvider['interval']}";
  782. $actValues = $this->_analyst->changesAggAtInterval($scalarId, $sampleProvider['rangeStart'], $sampleProvider['rangeEnd'], $sampleProvider['interval'], $aggFunc, false);
  783. $this->assertEquals($aggCount, count($actValues), $errorMsg);
  784. foreach ($actValues as $actual) {
  785. $this->assertDecimalEquals($expValues['ALL'][$aggFunc][$actual['x']], $actual['y'], $errorMsg . " x={$actual['x']}");
  786. }
  787. $errorMsg = "data={$sampleProviderName} val=DIS f={$aggFunc} int={$sampleProvider['interval']}";
  788. $actValues = $this->_analyst->changesAggAtInterval($scalarId, $sampleProvider['rangeStart'], $sampleProvider['rangeEnd'], $sampleProvider['interval'], $aggFunc, true);
  789. $this->assertEquals($aggDistinctCount, count($actValues), $errorMsg);
  790. foreach ($actValues as $actual) {
  791. $this->assertDecimalEquals($expValues['DIS'][$aggFunc][$actual['x']], $actual['y'], $errorMsg . " x={$actual['x']}");
  792. }
  793. }
  794. }
  795. }
  796. /**
  797. * @test
  798. * @group BasicDecimal
  799. * @group findsChangesNestedAggsAtInterval
  800. * @group changesNestedAggAtInterval
  801. * @group decimal
  802. * @group createScalar
  803. * @group createSample
  804. */
  805. public function findsChangesNestedAggsAtInterval()
  806. {
  807. $allSampleProviders = self::provideFullSamplesData();
  808. $this->assertFalse(empty($allSampleProviders));
  809. $expProvider = self::provideExpectedValues('provideChangesNestedAggAtInterval');
  810. $this->assertFalse(empty($expProvider));
  811. foreach ($expProvider as $sampleProviderName => $expValues) {
  812. $sampleProvider = $allSampleProviders[$sampleProviderName];
  813. $this->assertFalse(empty($sampleProvider));
  814. $scalarFields = array('name' => self::randomString(), 'type' => 'decimal');
  815. $scalarId = $this->_core->createScalar($scalarFields);
  816. foreach ($sampleProvider['samples'] as $sample) {
  817. list($end, $value) = $sample;
  818. $this->_partition->createSample($scalarId, $value, $end);
  819. }
  820. foreach (self::$_aggFunctions as $aggFuncOuter) {
  821. foreach (self::$_aggFunctions as $aggFuncInner) {
  822. $errorMsg = "data={$sampleProviderName} val=ALL func={$aggFuncOuter}({$aggFuncInner}) int={$sampleProvider['interval']}";
  823. $actualAgg = $this->_analyst->changesNestedAggAtInterval($scalarId, $sampleProvider['rangeStart'], $sampleProvider['rangeEnd'], $sampleProvider['interval'], $aggFuncOuter, false, $aggFuncInner, false);
  824. $this->assertDecimalEquals($expValues['ALL'][$aggFuncOuter][$aggFuncInner], $actualAgg, $errorMsg);
  825. $errorMsg = "data={$sampleProviderName} val=DIS_INNER func={$aggFuncOuter}({$aggFuncInner}) int={$sampleProvider['interval']}";
  826. $actualAgg = $this->_analyst->changesNestedAggAtInterval($scalarId, $sampleProvider['rangeStart'], $sampleProvider['rangeEnd'], $sampleProvider['interval'], $aggFuncOuter, false, $aggFuncInner, true);
  827. $this->assertDecimalEquals($expValues['DIS_INNER'][$aggFuncOuter][$aggFuncInner], $actualAgg, $errorMsg);
  828. $errorMsg = "data={$sampleProviderName} val=DIS_OUTER func={$aggFuncOuter}({$aggFuncInner}) int={$sampleProvider['interval']}";
  829. $actualAgg = $this->_analyst->changesNestedAggAtInterval($scalarId, $sampleProvider['rangeStart'], $sampleProvider['rangeEnd'], $sampleProvider['interval'], $aggFuncOuter, true, $aggFuncInner, false);
  830. $this->assertDecimalEquals($expValues['DIS_OUTER'][$aggFuncOuter][$aggFuncInner], $actualAgg, $errorMsg);
  831. $errorMsg = "data={$sampleProviderName} val=DIS_BOTH func={$aggFuncOuter}({$aggFuncInner}) int={$sampleProvider['interval']}";
  832. $actualAgg = $this->_analyst->changesNestedAggAtInterval($scalarId, $sampleProvider['rangeStart'], $sampleProvider['rangeEnd'], $sampleProvider['interval'], $aggFuncOuter, true, $aggFuncInner, true);
  833. $this->assertDecimalEquals($expValues['DIS_BOTH'][$aggFuncOuter][$aggFuncInner], $actualAgg, $errorMsg);
  834. }
  835. }
  836. }
  837. }
  838. /**
  839. * @test
  840. * @group BasicDecimal
  841. * @group findsChangesAggAtRecurrence
  842. * @group changesAggAtRecurrence
  843. * @group decimal
  844. * @group createScalar
  845. * @group createSample
  846. */
  847. public function findsChangesAggAtRecurrence()
  848. {
  849. $allSampleProviders = self::provideFullSamplesData();
  850. $this->assertFalse(empty($allSampleProviders));
  851. $expProvider = self::provideExpectedValues('provideChangesAggAtRecurrence');
  852. $this->assertFalse(empty($expProvider));
  853. foreach ($expProvider as $sampleProviderName => $expValues) {
  854. $sampleProvider = $allSampleProviders[$sampleProviderName];
  855. $this->assertFalse(empty($sampleProvider));
  856. $scalarFields = array('name' => self::randomString(), 'type' => 'decimal');
  857. $scalarId = $this->_core->createScalar($scalarFields);
  858. foreach ($sampleProvider['samples'] as $sample) {
  859. list($end, $value) = $sample;
  860. $this->_partition->createSample($scalarId, $value, $end);
  861. }
  862. foreach (Hashmark_Analyst_BasicDecimal::getRecurFunctions() as $recurFunc) {
  863. foreach (self::$_aggFunctions as $aggFunc) {
  864. $errorMsg = "data={$sampleProviderName} val=ALL recur={$recurFunc} agg={$aggFunc}";
  865. $actValues = $this->_analyst->changesAggAtRecurrence($scalarId, $sampleProvider['rangeStart'], $sampleProvider['rangeEnd'], $recurFunc, $aggFunc, false);
  866. foreach ($actValues as $actual) {
  867. $this->assertDecimalEquals($expValues['ALL'][$recurFunc][$actual['x']][$aggFunc], $actual['y'], $errorMsg . " x={$actual['x']}");
  868. }
  869. $errorMsg = "data={$sampleProviderName} val=DIS recur={$recurFunc} agg={$aggFunc}";
  870. $actValues = $this->_analyst->changesAggAtRecurrence($scalarId, $sampleProvider['rangeStart'], $sampleProvider['rangeEnd'], $recurFunc, $aggFunc, true);
  871. foreach ($actValues as $actual) {
  872. $this->assertDecimalEquals($expValues['DIS'][$recurFunc][$actual['x']][$aggFunc], $actual['y'], $errorMsg . " x={$actual['x']}");
  873. }
  874. }
  875. }
  876. }
  877. }
  878. /**
  879. * @test
  880. * @group BasicDecimal
  881. * @group findsFrequencies
  882. * @group frequency
  883. * @group decimal
  884. * @group createScalar
  885. * @group c…

Large files files are truncated, but you can click here to view the full file