-
Notifications
You must be signed in to change notification settings - Fork 676
/
TestOfFollowerCountMySQLDAO.php
361 lines (277 loc) · 16.7 KB
/
TestOfFollowerCountMySQLDAO.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
<?php
/**
*
* ThinkUp/tests/TestOfFollowerCountMySQLDAO.php
*
* Copyright (c) 2009-2013 Gina Trapani
*
* LICENSE:
*
* This file is part of ThinkUp (http://thinkupapp.com).
*
* ThinkUp is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any
* later version.
*
* ThinkUp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with ThinkUp. If not, see
* <http://www.gnu.org/licenses/>.
*
*
* @author Gina Trapani <ginatrapani[at]gmail[dot]com>
* @license http://www.gnu.org/licenses/gpl.html
* @copyright 2009-2013 Gina Trapani
*/
require_once dirname(__FILE__).'/init.tests.php';
require_once THINKUP_WEBAPP_PATH.'_lib/extlib/simpletest/autorun.php';
require_once THINKUP_WEBAPP_PATH.'config.inc.php';
class TestOfFollowerCountMySQLDAO extends ThinkUpUnitTestCase {
public function setUp() {
parent::setUp();
}
public function tearDown() {
parent::tearDown();
}
public function testConstructor() {
$dao = new FollowerCountMySQLDAO();
$this->assertTrue(isset($dao));
}
public function testInsert() {
$dao = new FollowerCountMySQLDAO();
$result = $dao->insert(930061, 'twitter', 1001);
$this->assertEqual($result, 1, 'One count inserted');
}
public function testGetDayHistoryNoGapsMilestoneNotInSight() {
$format = 'n/j';
$date = date ( $format );
$todays_day_of_the_week = date('w');
$this->debug("It's currently the ".$todays_day_of_the_week." day of the week");
if ($todays_day_of_the_week == 0 ) {
$follower_count = array('network_user_id'=>'930061', 'network'=>'twitter', 'date'=>'-2d', 'count'=>14);
$builder1 = FixtureBuilder::build('follower_count', $follower_count);
$follower_count = array('network_user_id'=>'930061', 'network'=>'twitter', 'date'=>'-3d', 'count'=>10);
$builder2 = FixtureBuilder::build('follower_count', $follower_count);
$follower_count = array('network_user_id'=>'930061', 'network'=>'twitter', 'date'=>'-4d', 'count'=>12);
$builder3 = FixtureBuilder::build('follower_count', $follower_count);
} else {
$follower_count = array('network_user_id'=>'930061', 'network'=>'twitter', 'date'=>'-1d', 'count'=>14);
$builder1 = FixtureBuilder::build('follower_count', $follower_count);
$follower_count = array('network_user_id'=>'930061', 'network'=>'twitter', 'date'=>'-2d', 'count'=>10);
$builder2 = FixtureBuilder::build('follower_count', $follower_count);
$follower_count = array('network_user_id'=>'930061', 'network'=>'twitter', 'date'=>'-3d', 'count'=>12);
$builder3 = FixtureBuilder::build('follower_count', $follower_count);
}
$dao = new FollowerCountMySQLDAO();
$result = $dao->getHistory('930061', 'twitter', 'DAY', 3);
$this->assertEqual(sizeof($result), 4, '4 sets of data returned--history, trend, and milestone, and vis_data');
$this->debug(Utils::varDumpToString($result));
//check history
$this->assertEqual(sizeof($result['history']), 3, '3 counts returned');
$format = 'm/d/Y';
if ($todays_day_of_the_week == 0 ) {
$date_ago = date ($format, strtotime('-4 day'.$date));
$this->assertEqual($result['history'][$date_ago], 12);
$date_ago = date ($format, strtotime('-3 day'.$date));
$this->assertEqual($result['history'][$date_ago], 10);
$date_ago = date ($format, strtotime('-2 day'.$date));
$this->assertEqual($result['history'][$date_ago], 14);
} else {
$date_ago = date ($format, strtotime('-3 day'.$date));
$this->assertEqual($result['history'][$date_ago], 12);
$date_ago = date ($format, strtotime('-2 day'.$date));
$this->assertEqual($result['history'][$date_ago], 10);
$date_ago = date ($format, strtotime('-1 day'.$date));
$this->assertEqual($result['history'][$date_ago], 14);
}
//check trend
$this->assertEqual($result['trend'], 1);
//check milestone
//latest follower count is 14, next milestone is 100 followers
//with a 1+/day trend, this should take 86 days
//that's over the "don't feel bad about yourself" threshold of 10, so milestone should be null
$this->assertNull($result['milestone']);
$this->assertNotNull($result['vis_data']);
}
public function testGetDayHistoryNoGapsMilestoneInSight() {
$format = 'n/j';
$date = date ( $format );
$todays_day_of_the_week = date('w');
$this->debug("It's currently the ".$todays_day_of_the_week." day of the week");
if ($todays_day_of_the_week == 0 ) {
$follower_count = array('network_user_id'=>930061, 'network'=>'twitter', 'date'=>'-2d', 'count'=>940);
$builder1 = FixtureBuilder::build('follower_count', $follower_count);
$follower_count = array('network_user_id'=>930061, 'network'=>'twitter', 'date'=>'-3d', 'count'=>900);
$builder2 = FixtureBuilder::build('follower_count', $follower_count);
$follower_count = array('network_user_id'=>930061, 'network'=>'twitter', 'date'=>'-4d', 'count'=>920);
$builder3 = FixtureBuilder::build('follower_count', $follower_count);
} else {
$follower_count = array('network_user_id'=>930061, 'network'=>'twitter', 'date'=>'-1d', 'count'=>940);
$builder1 = FixtureBuilder::build('follower_count', $follower_count);
$follower_count = array('network_user_id'=>930061, 'network'=>'twitter', 'date'=>'-2d', 'count'=>900);
$builder2 = FixtureBuilder::build('follower_count', $follower_count);
$follower_count = array('network_user_id'=>930061, 'network'=>'twitter', 'date'=>'-3d', 'count'=>920);
$builder3 = FixtureBuilder::build('follower_count', $follower_count);
}
$dao = new FollowerCountMySQLDAO();
$result = $dao->getHistory(930061, 'twitter', 'DAY', 3);
$this->assertEqual(sizeof($result), 4, '4 sets of data returned--history, trend, and milestone, and vis_data');
$this->debug(Utils::varDumpToString($result));
//check history
$this->assertEqual(sizeof($result['history']), 3, '3 counts returned');
$format = 'm/d/Y';
if ($todays_day_of_the_week == 0 ) {
$date_ago = date ($format, strtotime('-4 day'.$date));
$this->assertEqual($result['history'][$date_ago], 920);
$date_ago = date ($format, strtotime('-3 day'.$date));
$this->assertEqual($result['history'][$date_ago], 900);
$date_ago = date ($format, strtotime('-2 day'.$date));
$this->assertEqual($result['history'][$date_ago], 940);
} else {
$date_ago = date ($format, strtotime('-3 day'.$date));
$this->assertEqual($result['history'][$date_ago], 920);
$date_ago = date ($format, strtotime('-2 day'.$date));
$this->assertEqual($result['history'][$date_ago], 900);
$date_ago = date ($format, strtotime('-1 day'.$date));
$this->assertEqual($result['history'][$date_ago], 940);
}
//check trend
$this->assertEqual($result['trend'], 7);
//check milestone
//latest follower count is 940, next milestone is 1,000 followers
//with a 7+/day trend, this should take 9 days
$this->assertEqual($result['milestone']['next_milestone'], 1000);
$this->assertEqual($result['milestone']['will_take'], 9);
$this->assertEqual($result['milestone']['units_of_time'], 'DAY');
}
public function testGetDayHistoryWeekNoGaps() {
$format = 'm/j';
$date = date ( $format );
$follower_count = array('network_user_id'=>930061, 'network'=>'twitter', 'date'=>'-1d', 'count'=>140);
$builder1 = FixtureBuilder::build('follower_count', $follower_count);
$follower_count = array('network_user_id'=>930061, 'network'=>'twitter', 'date'=>'-2d', 'count'=>139);
$builder2 = FixtureBuilder::build('follower_count', $follower_count);
$follower_count = array('network_user_id'=>930061, 'network'=>'twitter', 'date'=>'-3d', 'count'=>138);
$builder3 = FixtureBuilder::build('follower_count', $follower_count);
$follower_count = array('network_user_id'=>930061, 'network'=>'twitter', 'date'=>'-4d', 'count'=>137);
$builder4 = FixtureBuilder::build('follower_count', $follower_count);
$follower_count = array('network_user_id'=>930061, 'network'=>'twitter', 'date'=>'-5d', 'count'=>136);
$builder5 = FixtureBuilder::build('follower_count', $follower_count);
$follower_count = array('network_user_id'=>930061, 'network'=>'twitter', 'date'=>'-6d', 'count'=>135);
$builder6 = FixtureBuilder::build('follower_count', $follower_count);
$follower_count = array('network_user_id'=>930061, 'network'=>'twitter', 'date'=>'-7d', 'count'=>134);
$builder7 = FixtureBuilder::build('follower_count', $follower_count);
$follower_count = array('network_user_id'=>930061, 'network'=>'twitter', 'date'=>'-8d', 'count'=>133);
$builder8 = FixtureBuilder::build('follower_count', $follower_count);
$follower_count = array('network_user_id'=>930061, 'network'=>'twitter', 'date'=>'-9d', 'count'=>132);
$builder9 = FixtureBuilder::build('follower_count', $follower_count);
$follower_count = array('network_user_id'=>930061, 'network'=>'twitter', 'date'=>'-10d', 'count'=>131);
$builder10 = FixtureBuilder::build('follower_count', $follower_count);
$follower_count = array('network_user_id'=>930061, 'network'=>'twitter', 'date'=>'-11d', 'count'=>130);
$builder11 = FixtureBuilder::build('follower_count', $follower_count);
$follower_count = array('network_user_id'=>930061, 'network'=>'twitter', 'date'=>'-12d', 'count'=>129);
$builder12 = FixtureBuilder::build('follower_count', $follower_count);
$follower_count = array('network_user_id'=>930061, 'network'=>'twitter', 'date'=>'-13d', 'count'=>128);
$builder13 = FixtureBuilder::build('follower_count', $follower_count);
$follower_count = array('network_user_id'=>930061, 'network'=>'twitter', 'date'=>'-14d', 'count'=>127);
$builder14 = FixtureBuilder::build('follower_count', $follower_count);
$dao = new FollowerCountMySQLDAO();
$result = $dao->getHistory(930061, 'twitter', 'WEEK', 3);
$this->assertEqual(sizeof($result), 4, '4 sets of data returned--history, trend, and milestone, and vis_data');
$this->debug(Utils::varDumpToString($result));
$todays_day_of_the_week = date('w');
$this->debug("It's currently ".$todays_day_of_the_week." day of the week. You can test all days except ".
"Sunday");
if ($todays_day_of_the_week != 0) {
//check history
$this->assertEqual(sizeof($result['history']), 3, '3 counts returned');
}
$date_ago = date ($format, strtotime('-1 day'.$date));
$this->assertEqual($result['history'][$date_ago], 140);
//check trend
//$this->assertEqual($result['trend'], 3);
//check milestone
//latest follower count is 140, next milestone is 1,000 followers
//with a 7+/day trend, this should take 123 days
//beyond our "don't feel bad about yourself" threshold of 10, so should be null
if ($todays_day_of_the_week != 0) {
$this->assertNull($result['milestone']);
}
}
public function testGetDayHistoryWithGaps() {
// Filling gaps was only required by the old visualization library
$format = 'n/j';
$date = date ( $format );
$follower_count = array('network_user_id'=>930061, 'network'=>'twitter', 'date'=>'-1d', 'count'=>140);
$builder1 = FixtureBuilder::build('follower_count', $follower_count);
$follower_count = array('network_user_id'=>930061, 'network'=>'twitter', 'date'=>'-2d', 'count'=>100);
$builder2 = FixtureBuilder::build('follower_count', $follower_count);
$follower_count = array('network_user_id'=>930061, 'network'=>'twitter', 'date'=>'-5d', 'count'=>120);
$builder3 = FixtureBuilder::build('follower_count', $follower_count);
$dao = new FollowerCountMySQLDAO();
$result = $dao->getHistory(930061, 'twitter', 'DAY', 5);
$this->assertEqual(sizeof($result), 4, '4 sets of data returned--history, trend, and milestone, and vis_data');
//check history
$this->assertEqual(sizeof($result['history']), 3);
$format = 'm/d/Y';
$this->debug(Utils::varDumpToString($result));
$date_ago = date ($format, strtotime('-5 day'.$date));
$this->assertEqual($result['history'][$date_ago], 120);
$date_ago = date ($format, strtotime('-4 day'.$date));
$this->assertTrue(!isset($result['history'][$date_ago]), 'gap filled');
$date_ago = date ($format, strtotime('-3 day'.$date));
$this->assertTrue(!isset($result['history'][$date_ago]), 'gap filled');
$date_ago = date ($format, strtotime('-2 day'.$date));
$this->assertEqual($result['history'][$date_ago], 100);
$date_ago = date ($format, strtotime('-1 day'.$date));
$this->assertEqual($result['history'][$date_ago], 140);
//check trend
$this->assertFalse($result['trend']);
//check milestone
$this->assertFalse($result['milestone']);
}
public function testTrendMillionPlusFollowers() {
$format = 'n/j';
$date = date ( $format );
$follower_count = array('network_user_id'=>930061, 'network'=>'twitter', 'date'=>'-1d', 'count'=>1772643);
$builder1 = FixtureBuilder::build('follower_count', $follower_count);
$follower_count = array('network_user_id'=>930061, 'network'=>'twitter', 'date'=>'-2d', 'count'=>1771684);
$builder2 = FixtureBuilder::build('follower_count', $follower_count);
$follower_count = array('network_user_id'=>930061, 'network'=>'twitter', 'date'=>'-3d', 'count'=>1771500);
$builder3 = FixtureBuilder::build('follower_count', $follower_count);
$follower_count = array('network_user_id'=>930061, 'network'=>'twitter', 'date'=>'-4d', 'count'=>1761500);
$builder4 = FixtureBuilder::build('follower_count', $follower_count);
$dao = new FollowerCountMySQLDAO();
$result = $dao->getHistory(930061, 'twitter', 'DAY', 4);
$this->assertEqual(sizeof($result), 4, '4 sets of data returned--history, trend, and milestone, and vis_data');
$this->debug(Utils::varDumpToString($result));
//check milestone
//latest follower count is 1.7M, next milestone is 2M
//with a 2786+/day trend, this should take 82 days
//beyond our "don't feel bad about yourself" threshold of 10, so should be null
$this->assertNull($result['milestone']);
}
public function testTrendMillionPlusFollowers2() {
$format = 'n/j';
$date = date ( $format );
$follower_count = array('network_user_id'=>930061, 'network'=>'twitter', 'date'=>'-1d', 'count'=>1272643);
$builder1 = FixtureBuilder::build('follower_count', $follower_count);
$follower_count = array('network_user_id'=>930061, 'network'=>'twitter', 'date'=>'-2d', 'count'=>1271684);
$builder2 = FixtureBuilder::build('follower_count', $follower_count);
$follower_count = array('network_user_id'=>930061, 'network'=>'twitter', 'date'=>'-3d', 'count'=>1271500);
$builder3 = FixtureBuilder::build('follower_count', $follower_count);
$follower_count = array('network_user_id'=>930061, 'network'=>'twitter', 'date'=>'-4d', 'count'=>1261500);
$builder4 = FixtureBuilder::build('follower_count', $follower_count);
$dao = new FollowerCountMySQLDAO();
$result = $dao->getHistory(930061, 'twitter', 'DAY', 4);
$this->assertEqual(sizeof($result), 4, '4 sets of data returned--history, trend, and milestone, and vis_data');
$this->debug(Utils::varDumpToString($result));
//check milestone
//latest follower count is 1.7M, next milestone is 2M
//with a 2786+/day trend, this should take 82 days
//beyond our "don't feel bad about yourself" threshold of 10, so should be null
$this->assertNull($result['milestone']);
}
}