98 |
- |
1 |
<?php
|
|
|
2 |
/*
|
|
|
3 |
PHPlot / contrib / color_range : Unit tests
|
|
|
4 |
$Id: color_range.test2.php 452 2009-12-09 03:45:51Z lbayuk $
|
|
|
5 |
|
|
|
6 |
Tests color.range.php functions:
|
|
|
7 |
color_range($color_a, $color_b, $n_steps)
|
|
|
8 |
count_data_sets($data, $data_type)
|
|
|
9 |
|
|
|
10 |
*/
|
|
|
11 |
require_once 'color_range.php';
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
# Testing count_data_sets()
|
|
|
15 |
function test_count_data_sets($data, $data_type, $expected)
|
|
|
16 |
{
|
|
|
17 |
$n = count_data_sets($data, $data_type);
|
|
|
18 |
if ($n == $expected) $result = "Pass";
|
|
|
19 |
else $result = "FAIL: Expected $expected but got";
|
|
|
20 |
echo "$result: $n data sets, $data_type with " . count($data) . " records.\n";
|
|
|
21 |
}
|
|
|
22 |
|
|
|
23 |
function test_driver_count_data_sets()
|
|
|
24 |
{
|
|
|
25 |
echo "\nTesting count_data_sets():\n";
|
|
|
26 |
$data1 = array(array('a', 1, 2, 3), array('b', 2, 2, 3));
|
|
|
27 |
$data2 = array(array('a', 1, 2, 3, 4, 5, 6, 7), array('b', 2, 4, 5, 6));
|
|
|
28 |
$data3 = array(array('', 1), array('', 2), array('', 3), array('', 4));
|
|
|
29 |
$data4 = array(array('', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13),
|
|
|
30 |
array('', 1, 2, 3, 4, 5, 6, 7),
|
|
|
31 |
array('', 1, 2, 3, 4));
|
|
|
32 |
|
|
|
33 |
test_count_data_sets($data1, 'text-data', 3);
|
|
|
34 |
test_count_data_sets($data1, 'data-data', 2);
|
|
|
35 |
test_count_data_sets($data2, 'data-data-error', 2);
|
|
|
36 |
test_count_data_sets($data3, 'text-data-single', 4);
|
|
|
37 |
|
|
|
38 |
test_count_data_sets($data4, 'text-data', 13);
|
|
|
39 |
test_count_data_sets($data4, 'data-data', 12);
|
|
|
40 |
test_count_data_sets($data4, 'data-data-error', 4);
|
|
|
41 |
test_count_data_sets($data4, 'text-data-single', 3);
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
# Testing color_range()
|
|
|
45 |
function test_color_range($color1, $color2, $nsteps, $expected)
|
|
|
46 |
{
|
|
|
47 |
$info = 'From (' . implode(', ', $color1)
|
|
|
48 |
. ') To (' . implode(', ', $color2) . ") with $nsteps steps";
|
|
|
49 |
|
|
|
50 |
$colors = color_range($color1, $color2, $nsteps);
|
|
|
51 |
if ($colors == $expected) echo "Pass: $info\n";
|
|
|
52 |
else echo "FAIL: $info\n" . print_r($colors, True) . "\n";
|
|
|
53 |
if (($n = count($colors)) != $nsteps)
|
|
|
54 |
echo "FAIL: Bad count $n expecting $nsteps\n";
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
function test_driver_color_range()
|
|
|
58 |
{
|
|
|
59 |
echo "\nTesting color_range():\n";
|
|
|
60 |
test_color_range(array(0,0,0), array(255,255,255), 3,
|
|
|
61 |
array(array(0,0,0), array(127,127,127), array(255,255,255)));
|
|
|
62 |
|
|
|
63 |
test_color_range(array(255,0,0), array(0,255,0), 2,
|
|
|
64 |
array(array(255,0,0), array(0,255,0)));
|
|
|
65 |
|
|
|
66 |
test_color_range(array(100,0,100), array(0,100,0), 6,
|
|
|
67 |
array(array(100,0,100), array(80,20,80), array(60,40,60),
|
|
|
68 |
array(40,60,40), array(20,80,20), array(0,100,0)));
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
|
|
|
72 |
test_driver_count_data_sets();
|
|
|
73 |
test_driver_color_range();
|