| 98 |
- |
1 |
<?php
|
|
|
2 |
# PHPlot / contrib / prune_labels : Test
|
|
|
3 |
# $Id: prune_labels.test.php 455 2009-12-09 03:45:57Z lbayuk $
|
|
|
4 |
# Test driver for contrib / prune_labels
|
|
|
5 |
|
|
|
6 |
require_once 'prune_labels.php';
|
|
|
7 |
|
|
|
8 |
/* Testing the prune_labels function: */
|
|
|
9 |
function test($count, $maxlabels)
|
|
|
10 |
{
|
|
|
11 |
# Make an array of count records, like PHPlot uses, with labels:
|
|
|
12 |
$data = array();
|
|
|
13 |
for ($i = 0; $i < $count; $i++) {
|
|
|
14 |
$data[] = array("Row $i", $i, 100, 200, 300);
|
|
|
15 |
}
|
|
|
16 |
|
|
|
17 |
prune_labels($data, $maxlabels);
|
|
|
18 |
|
|
|
19 |
# See how many labels are non-blank now:
|
|
|
20 |
$line = '';
|
|
|
21 |
$non_blank = 0;
|
|
|
22 |
for ($i = 0; $i < $count; $i++) {
|
|
|
23 |
if (!empty($data[$i][0])) {
|
|
|
24 |
$non_blank++;
|
|
|
25 |
$line .= '*';
|
|
|
26 |
} else {
|
|
|
27 |
$line .= '_';
|
|
|
28 |
}
|
|
|
29 |
}
|
|
|
30 |
$status = ($non_blank <= $maxlabels) ? 'PASS' : 'FAIL';
|
|
|
31 |
echo "$status: $count rows, maxlabels=$maxlabels => $non_blank labels\n";
|
|
|
32 |
echo substr($line, 0, 80) . "\n"; # Only show first 80 chars.
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
/* Test cases for prune_labels */
|
|
|
36 |
for ($n = 7; $n <= 1000; $n *= 2) test($n, 10);
|
|
|
37 |
for ($g = 5; $g <= 40; $g++) test(72, $g);
|
|
|
38 |
# Edge cases
|
|
|
39 |
test(80, 41);
|
|
|
40 |
test(80, 40);
|
|
|
41 |
test(80, 39);
|