Exemplo n.º 1
0
function test($msg, $angle, $dist, $expect_xoff, $expect_yoff, $expected_align)
{
    global $test_debug, $tests, $fails, $error;
    $failed = False;
    $tests++;
    $p = new PHPlot_test();
    if (isset($angle)) {
        $p->data_value_label_angle = $angle;
    }
    if (isset($dist)) {
        $p->data_value_label_distance = $dist;
    }
    // 'plotin' arg always enables labels.
    $p->test_CheckDataValueLabels('plotin', $x_adj, $y_adj, $h_align, $v_align);
    $align = $h_align . $v_align;
    if ($test_debug) {
        echo "CheckDataValueLabels(angle=" . (isset($angle) ? $angle : "UNSET") . ', dist=' . (isset($dist) ? $dist : "UNSET") . ")\n  " . "offset=({$x_adj}, {$y_adj}) alignment={$align}\n";
    }
    if (!expect_equal($expected_align, $align, "{$msg} alignment", $error)) {
        $failed = True;
    }
    // Offsets need to be checked within a fuzz factor. Use 1 since the
    // function actually returns an integer number of pixels.
    if (!expect_float($expect_xoff, $x_adj, 1, "{$msg} x-offset", $error) || !expect_float($expect_yoff, $y_adj, 1, "{$msg} y-offset", $error)) {
        $failed = True;
    }
    if ($failed) {
        $fails++;
    }
}
Exemplo n.º 2
0
function test($start, $step, $anchor)
{
    static $need_header = 0;
    global $cases, $errors, $verbose;
    $plot = new PHPlot_test();
    // Minimal plot setup. Data values do not matter - only CalcTicks is used.
    $plot->SetPlotAreaWorld(NULL, $start, NULL, $start + 10 * $step);
    $plot->SetYTickIncrement($step);
    $plot->SetYTickAnchor($anchor);
    $plot->SetDataValues(array(array('', $start), array('', $start + 1)));
    $plot->SetDataType('text-data');
    $plot->SetPlotType('points');
    $plot->SetPrintImage(False);
    $plot->DrawGraph();
    // Get the actual values from CalcTicks() for Y:
    list($tick_start, $tick_end, $tick_step) = $plot->test_CalcTicks('y');
    $cases++;
    // Check results:
    $result = '';
    // Adjusted tick mark must not be to the left of the original:
    if ($tick_start < $start) {
        $result .= ' Wrong direction;';
        // Adjusted tick mark must not be more than 1 tick mark right of original:
    } elseif ($tick_start >= $start + $step) {
        $result .= ' Too far;';
    }
    // There should be an integer number of steps between start and anchor.
    // But allow for some fuzz.
    $n_tick = ($tick_start - $anchor) / $step;
    if ($n_tick > 0 && ($n_tick - (int) $n_tick) / $n_tick > 0.005) {
        $result .= ' No tick @ anchor;';
    }
    // Report results:
    if (empty($result)) {
        $status = 'OK';
    } else {
        $status = 'Error:';
        $errors++;
    }
    if ($verbose) {
        if ($need_header == 0) {
            $need_header = 20;
            echo "Start    Step     Anchor   => Adjusted  Result:\n";
            echo "-------- -------- -------- => --------  ------------\n";
        }
        printf("%8g %8g %8g => %8g  %s\n", $start, $step, $anchor, $tick_start, $status . $result);
        $need_header--;
    }
    if (!empty($result)) {
        fwrite(STDERR, "Error: start={$start} step={$step} anchor={$anchor}\n");
        fwrite(STDERR, "      Result={$tick_start}   Error={$result}\n");
    }
}
Exemplo n.º 3
0
function test($name, $data_type, $plot_type, $data, $expected)
{
    global $test_verbose, $n_tests, $n_pass, $n_fail;
    $n_tests++;
    $title = "Test case {$n_tests}: {$name}";
    if ($test_verbose) {
        echo "{$title}\n";
    }
    $p = new PHPlot_test();
    // See above, for access to protected methods
    $p->SetDataType($data_type);
    $p->SetPlotType($plot_type);
    $p->SetDataValues($data);
    // For PHPlot>5.1.2 (CVS). FindDataLimits requires this.
    $p->CALL_CheckDataArray();
    // Call internal function:
    $p->CALL_FindDataLimits();
    // Get min,max x,y - cast to float for comparing
    $results = $p->GET_min_max_x_y();
    // Backward compatibility fixup(s):
    compat_1($p, $data_type, $expected);
    $error = '';
    if (expect_equal($expected, $results, $title, $error)) {
        $n_pass++;
    } else {
        $n_fail++;
        echo "{$error}\n";
    }
}
Exemplo n.º 4
0
function test($data_xmin, $data_xmax, $data_ymin, $data_ymax)
{
    global $test_verbose, $n_tests, $n_pass, $n_fail;
    $n_tests++;
    $q = compact('data_xmin', 'data_ymin', 'data_xmax', 'data_ymax');
    $title = "({$data_xmin}, {$data_ymin}) : ({$data_xmax}, {$data_ymax})";
    if ($test_verbose) {
        testin($q);
    }
    $p = new PHPlot_test();
    $p->SetDataValues(array(array('', $data_xmin, $data_ymin), array('', $data_xmax, $data_ymax)));
    $p->SetDataType('data-data');
    $p->SetPlotType('lines');
    $p->test_CalcPlotAreaWorld();
    # This returns an array with several protected variables: plot_xmin,
    # plot_xmax, plot_ymin, plot_ymax, xtick, ytick:
    $p->test_GetVars($q);
    # Calculate number of tick intervals:
    $q['nxtick'] = (int) (1.001 * ($q['plot_xmax'] - $q['plot_xmin']) / $q['xtick']);
    $q['nytick'] = (int) (1.001 * ($q['plot_ymax'] - $q['plot_ymin']) / $q['ytick']);
    if ($test_verbose) {
        testout($q);
    }
    $result = validate($q);
    if (empty($result)) {
        $n_pass++;
    } else {
        $n_fail++;
        echo "Failed test case {$n_tests}: {$title}\n{$result}\n";
    }
}
Exemplo n.º 5
0
function test_show_calcstepdatetime()
{
    $p = new PHPlot_test();
    echo "The following are valid steps returned by CalcDatetime():\n";
    echo "Seconds    Interval\n";
    echo "--------   -----------\n";
    $prev_step = -1;
    for ($i = 1; $i < 2000000; $i++) {
        $step = $p->test_CalcStepDatetime($i, 1);
        if ($step != $prev_step) {
            printf("%8d   %s\n", $step, interval($step));
            $prev_step = $step;
        }
    }
    echo "\n";
}
Exemplo n.º 6
0
expect_match('[a-z]\\.ttf$', $font, 'Case 3. SetTTFPath to dir, then get default', $error);
if (!empty($test_debug)) {
    echo "3. font={$font}\n";
}
# 4. Set font path to local variant, then specify font name with extension.
$p = new PHPlot_test();
$p->SetTTFPath(getcwd() . DIRECTORY_SEPARATOR . 'images');
$p->SetDefaultTTFont(TEST_FONT);
$font = $p->test_GetDefaultTTFont();
expect_match('[a-z]\\.ttf$', $font, 'Case 4. Set local font dir, then font name', $error);
if (!empty($test_debug)) {
    echo "4. font={$font}\n";
}
# 5. SetFontTTF with path and extension
$font_with_path_and_ext = $phplot_test_ttfdir . $phplot_test_ttfonts['serif'];
$p = new PHPlot_test();
$p->SetFontTTF('title', $font_with_path_and_ext, 12);
$font = $p->fonts['title']['font'];
expect_match('[a-z]\\.ttf$', $font, 'Case 5. Set title font with path and extension', $error);
if (!empty($test_debug)) {
    echo "5. font={$font}\n";
}
# 6. SetFontTTF with path and no extension - expected to fail.
$pp = pathinfo($phplot_test_ttfonts['serif']);
$font_with_path_no_ext = $phplot_test_ttfdir . basename($phplot_test_ttfonts['serif'], '.ttf');
// Note this uses the PHPlot_test2() class which suppresses the error image
// and allows the messages to be completely off.
$p = new PHPlot_test2();
$p->hide_error = True;
// Disables error message from PHPlot_test2
if ($p->SetFontTTF('title', $font_with_path_no_ext, 12)) {