BuildInStats_Test

The Contact Form DB BuildInStats Test class.

Defined (1)

The class is defined in the following location(s).

/phpunit/BuildInStats_Test.php  
  1. class BuildInStats_Test extends PHPUnit_Framework_TestCase { 
  2.  
  3. var $data; 
  4.  
  5. public function setUp() { 
  6. date_default_timezone_set('America/New_York'); 
  7. $str = file_get_contents('scores.json'); 
  8. $this->data = json_decode($str, true); 
  9.  
  10. public function test_count() { 
  11. $trans = new CountField('score'); 
  12. foreach ($this->data as $entry) { 
  13. $trans->addEntry($entry); 
  14. $data = $trans->getTransformedData(); 
  15. print_r($data); 
  16.  
  17. $this->assertEquals(1, count($data)); 
  18. $this->assertEquals(14, $data[0]['score']); 
  19. $this->assertEquals(1, count($data[0])); 
  20.  
  21. public function test_count_groupby() { 
  22. $trans = new CountField('score', 'name'); 
  23. foreach ($this->data as $entry) { 
  24. $trans->addEntry($entry); 
  25. $data = $trans->getTransformedData(); 
  26. print_r($data); 
  27.  
  28. $this->assertEquals(4, count($data)); 
  29.  
  30. $idx = 0; 
  31. $this->assertEquals('AAA', $data[$idx]['name']); 
  32. $this->assertEquals(4, $data[$idx]['score']); 
  33. $this->assertEquals(2, count($data[$idx])); 
  34.  
  35. $idx++; 
  36. $this->assertEquals('BBB', $data[$idx]['name']); 
  37. $this->assertEquals(4, $data[$idx]['score']); 
  38. $this->assertEquals(2, count($data[$idx])); 
  39.  
  40. $idx++; 
  41. $this->assertEquals('CCC', $data[$idx]['name']); 
  42. $this->assertEquals(4, $data[$idx]['score']); 
  43. $this->assertEquals(2, count($data[$idx])); 
  44.  
  45. $idx++; 
  46. $this->assertEquals('DDD', $data[$idx]['name']); 
  47. $this->assertEquals(2, $data[$idx]['score']); 
  48. $this->assertEquals(2, count($data[$idx])); 
  49.  
  50.  
  51. public function test_min() { 
  52. $trans = new MinField('score'); 
  53. foreach ($this->data as $entry) { 
  54. $trans->addEntry($entry); 
  55. $data = $trans->getTransformedData(); 
  56. print_r($data); 
  57.  
  58. $this->assertEquals(1, count($data)); 
  59. $this->assertEquals(-1, $data[0]['score']); 
  60. $this->assertEquals(1, count($data[0])); 
  61.  
  62. public function test_min_groupby() { 
  63. $trans = new MinField('score', 'name'); 
  64. foreach ($this->data as $entry) { 
  65. $trans->addEntry($entry); 
  66. $data = $trans->getTransformedData(); 
  67. print_r($data); 
  68.  
  69. $this->assertEquals(4, count($data)); 
  70.  
  71. $idx = 0; 
  72. $this->assertEquals('AAA', $data[$idx]['name']); 
  73. $this->assertEquals(20, $data[$idx]['score']); 
  74. $this->assertEquals(2, count($data[$idx])); 
  75.  
  76. $idx++; 
  77. $this->assertEquals('BBB', $data[$idx]['name']); 
  78. $this->assertEquals(9, $data[$idx]['score']); 
  79. $this->assertEquals(2, count($data[$idx])); 
  80.  
  81. $idx++; 
  82. $this->assertEquals('CCC', $data[$idx]['name']); 
  83. $this->assertEquals(-1, $data[$idx]['score']); 
  84. $this->assertEquals(2, count($data[$idx])); 
  85.  
  86. $idx++; 
  87. $this->assertEquals('DDD', $data[$idx]['name']); 
  88. $this->assertEquals(900, $data[$idx]['score']); 
  89. $this->assertEquals(2, count($data[$idx])); 
  90.  
  91. public function test_max() { 
  92. $trans = new MaxField('score'); 
  93. foreach ($this->data as $entry) { 
  94. $trans->addEntry($entry); 
  95. $data = $trans->getTransformedData(); 
  96. print_r($data); 
  97.  
  98. $this->assertEquals(1, count($data)); 
  99. $this->assertEquals(20000, $data[0]['score']); 
  100. $this->assertEquals(1, count($data[0])); 
  101.  
  102. public function test_max_groupby() { 
  103. $trans = new MaxField('score', 'name'); 
  104. foreach ($this->data as $entry) { 
  105. $trans->addEntry($entry); 
  106. $data = $trans->getTransformedData(); 
  107. print_r($data); 
  108.  
  109. $this->assertEquals(4, count($data)); 
  110.  
  111. $idx = 0; 
  112. $this->assertEquals('AAA', $data[$idx]['name']); 
  113. $this->assertEquals(1514, $data[$idx]['score']); 
  114. $this->assertEquals(2, count($data[$idx])); 
  115.  
  116. $idx++; 
  117. $this->assertEquals('BBB', $data[$idx]['name']); 
  118. $this->assertEquals(1500, $data[$idx]['score']); 
  119. $this->assertEquals(2, count($data[$idx])); 
  120.  
  121. $idx++; 
  122. $this->assertEquals('CCC', $data[$idx]['name']); 
  123. $this->assertEquals(20000, $data[$idx]['score']); 
  124. $this->assertEquals(2, count($data[$idx])); 
  125.  
  126. $idx++; 
  127. $this->assertEquals('DDD', $data[$idx]['name']); 
  128. $this->assertEquals(900, $data[$idx]['score']); 
  129. $this->assertEquals(2, count($data[$idx])); 
  130.  
  131. public function test_sum() { 
  132. $trans = new SumField('score'); 
  133. foreach ($this->data as $entry) { 
  134. $trans->addEntry($entry); 
  135. $data = $trans->getTransformedData(); 
  136. print_r($data); 
  137.  
  138. $this->assertEquals(1, count($data)); 
  139. $this->assertEquals(24704, $data[0]['score']); 
  140. $this->assertEquals(1, count($data[0])); 
  141.  
  142.  
  143. public function test_sum_groupby() { 
  144. $trans = new SumField('score', 'name'); 
  145. foreach ($this->data as $entry) { 
  146. $trans->addEntry($entry); 
  147. $data = $trans->getTransformedData(); 
  148. print_r($data); 
  149. $this->assertEquals(4, count($data)); 
  150.  
  151. $idx = 0; 
  152. $this->assertEquals('AAA', $data[$idx]['name']); 
  153. $this->assertEquals(1764, $data[$idx]['score']); 
  154. $this->assertEquals(2, count($data[$idx])); 
  155.  
  156. $idx++; 
  157. $this->assertEquals('BBB', $data[$idx]['name']); 
  158. $this->assertEquals(2021, $data[$idx]['score']); 
  159. $this->assertEquals(2, count($data[$idx])); 
  160.  
  161. $idx++; 
  162. $this->assertEquals('CCC', $data[$idx]['name']); 
  163. $this->assertEquals(20019, $data[$idx]['score']); 
  164. $this->assertEquals(2, count($data[$idx])); 
  165.  
  166. $idx++; 
  167. $this->assertEquals('DDD', $data[$idx]['name']); 
  168. $this->assertEquals(900, $data[$idx]['score']); 
  169. $this->assertEquals(2, count($data[$idx])); 
  170.  
  171. public function test_average() { 
  172. $trans = new AverageField('score'); 
  173. foreach ($this->data as $entry) { 
  174. $trans->addEntry($entry); 
  175. $data = $trans->getTransformedData(); 
  176. print_r($data); 
  177.  
  178. $this->assertEquals(1, count($data)); 
  179. $this->assertEquals(1900.3076923077, $data[0]['score']); 
  180. $this->assertEquals(1, count($data[0])); 
  181.  
  182. public function test_average_groupby() { 
  183. $trans = new AverageField('score', 'name'); 
  184. foreach ($this->data as $entry) { 
  185. $trans->addEntry($entry); 
  186. $data = $trans->getTransformedData(); 
  187. print_r($data); 
  188.  
  189. $this->assertEquals(4, count($data)); 
  190.  
  191. $idx = 0; 
  192. $this->assertEquals('AAA', $data[$idx]['name']); 
  193. $this->assertEquals(441, $data[$idx]['score']); 
  194. $this->assertEquals(2, count($data[$idx])); 
  195.  
  196. $idx++; 
  197. $this->assertEquals('BBB', $data[$idx]['name']); 
  198. $this->assertEquals(505.25, $data[$idx]['score']); 
  199. $this->assertEquals(2, count($data[$idx])); 
  200.  
  201. $idx++; 
  202. $this->assertEquals('CCC', $data[$idx]['name']); 
  203. $this->assertEquals(5004.75, $data[$idx]['score']); 
  204. $this->assertEquals(2, count($data[$idx])); 
  205.  
  206. $idx++; 
  207. $this->assertEquals('DDD', $data[$idx]['name']); 
  208. $this->assertEquals(900, $data[$idx]['score']); 
  209. $this->assertEquals(2, count($data[$idx])); 
  210.