Exemple #1
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";
    }
}
Exemple #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");
    }
}
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";
    }
}