コード例 #1
0
int main(int argc, char *argv[])
{
    int        p[2];
    int        stdoutfd;
        struct obj exp;

        (void)argc;
        (void)argv;

    printf("1..1\n");
    fflush(stdout);
    stderrfd = dup(STDERR_FILENO);

    if (stderrfd < 0)
        err(1, "dup of stderr failed");

    stdoutfd = dup(STDOUT_FILENO);

    if (stdoutfd < 0)
        err(1, "dup of stdout failed");

    if (pipe(p) != 0)
        failmsg("pipe failed");

    if (dup2(p[1], STDERR_FILENO) < 0 || dup2(p[1], STDOUT_FILENO) < 0)
        failmsg("Duplicating file descriptor");

    plan_tests(10);
    expect(p[0], "1..10\n");

    ok(1, "msg1");
    expect(p[0], "ok 1 - msg1\n");

    ok(0, "msg2");
    expect(p[0], "not ok 2 - msg2\n"
           "#     Failed test (*test.1.tap.c:main() at line 199)\n");

    ok1(true);
    expect(p[0], "ok 3 - true\n");

    ok1(false);
    expect(p[0], "not ok 4 - false\n"
           "#     Failed test (*test.1.tap.c:main() at line 206)\n");

    pass("passed");
    expect(p[0], "ok 5 - passed\n");

    fail("failed");
    expect(p[0], "not ok 6 - failed\n"
           "#     Failed test (*test.1.tap.c:main() at line 213)\n");

    skip(2, "skipping %s", "test");
    expect(p[0], "ok 7 # skip skipping test\n"
           "ok 8 # skip skipping test\n");

    todo_start("todo");
    ok1(false);
    expect(p[0], "not ok 9 - false # TODO todo\n"
                 "#     Failed (TODO) test (*test.1.tap.c:main() at line 222)\n");
    ok1(true);
    expect(p[0], "ok 10 - true # TODO todo\n");
    todo_end();

    if (exit_status() != 3)
        failmsg("Expected exit status 3, not %i", exit_status());

        is(one_int(), 1, "one_int() returns 1");
        expect(p[0], "ok 11 - one_int() returns 1\n");
        is(one_int(), 2, "one_int() returns 2");
        expect(p[0], "not ok 12 - one_int() returns 2\n"
               "#     Failed test (*test.1.tap.c:main() at line 234)\n"
               "#          got: 1\n"
               "#     expected: 2\n");

        is_eq(one_str(), "one", "one_str() returns 'one'");
        expect(p[0], "ok 13 - one_str() returns 'one'\n");
        is_eq(one_str(), "two", "one_str() returns 'two'");
        expect(p[0], "not ok 14 - one_str() returns 'two'\n"
               "#     Failed test (*test.1.tap.c:main() at line 242)\n"
               "#          got: \"one\"\n"
               "#     expected: \"two\"\n");

        exp.id = 1;
        is_cmp(one_obj(), &exp, obj_cmp, obj_to_str, "one_obj() has id 1");
        expect(p[0], "ok 15 - one_obj() has id 1\n");
        exp.id = 2;
        is_cmp(one_obj(), &exp, obj_cmp, obj_to_str, "one_obj() has id 2");
        expect(p[0], "not ok 16 - one_obj() has id 2\n"
               "#     Failed test (*test.1.tap.c:main() at line 252)\n"
               "#          got: {id=1}\n"
               "#     expected: {id=2}\n");

        is_strstr(one_str(), "n", "one_str() contains 'n'");
        expect(p[0], "ok 17 - one_str() contains 'n'\n");
        is_strstr(one_str(), "w", "one_str() contains 'w'");
        expect(p[0], "not ok 18 - one_str() contains 'w'\n"
               "#     Failed test (*test.1.tap.c:main() at line 260)\n"
               "#                     got: \"one\"\n"
               "#     expected to contain: \"w\"\n");
#if 0
    /* Manually run the atexit command. */
    _cleanup();
    expect(p[0], "# Looks like you failed 2 tests of 9.\n");
#endif

    write_all(stdoutfd, "ok 1 - All passed\n",
          strlen("ok 1 - All passed\n"));
    _exit(0);
}
コード例 #2
0
ファイル: cheb.c プロジェクト: CaptainSifff/tr29124_test
main() {

    int i, n, m5, ma, mf;
    double a, b, h, x, f, err;
    double *c, *cint, *cder;

    a = 0.0;
    b = 5.0;
    h = (b-a)/10.0;
    n = 40;
    m5 = 5;
    ma = 10;
    mf = 15;

    c = dvector( 0, n-1 );
    cder = dvector( 0, n-1 );
    cint = dvector( 0, n-1 );


    printf( "\n\n\n  Test Chebyshev fitting.\n" );



    chebyshev_fit( a, b, c, n, one );
    chebyshev_deriv( a, b, c, cder, mf );
    chebyshev_integ( a, b, c, cint, mf );

    printf( "\n\n  Fit of f(x) = 1 from a = %3.1f to b = %3.1f with %d coefficients . . .", a, b, n );
    for ( i = 0; i < n/2; ++i ) printf( "\n  c[%2d] = %16.12f                c[%2d] = %16.12f", i, c[i], i+n/2, c[i+n/2] );

    printf( "\n\n  Evaluation of f(x) = 1 from a = %3.1f to b = %3.1f with %d coefficients . . .", a, b, m5 );
    x = a;
    while ( x <= b ) {
        f = chebyshev_eval( a, b, c, m5, x );
        err = f - one(x);
        printf( "\n  f(%3.1f) = %16.12f    error = %16.12f", x, f, err );
        x += h;
    }

    printf( "\n\n  Evaluation of f(x) = 1 from a = %3.1f to b = %3.1f with %d coefficients . . .", a, b, ma );
    x = a;
    while ( x <= b ) {
        f = chebyshev_eval( a, b, c, ma, x );
        err = f - one(x);
        printf( "\n  f(%3.1f) = %16.12f    error = %16.12f", x, f, err );
        x += h;
    }

    printf( "\n\n  Evaluation of derivative of f(x) from a = %3.1f to b = %3.1f with %d coefficients . . .", a, b, ma );
    x = a;
    while ( x <= b ) {
        f = chebyshev_eval( a, b, cder, ma, x );
        err = f - one_der(x);
        printf( "\n  f(%3.1f) = %16.12f    error = %16.12f", x, f, err );
        x += h;
    }

    printf( "\n\n  Evaluation of integral of f(x) from a = %3.1f to b = %3.1f with %d coefficients . . .", a, b, ma );
    x = a;
    while ( x <= b ) {
        f = chebyshev_eval( a, b, cint, ma, x );
        err = f - one_int(x);
        printf( "\n  f(%3.1f) = %16.12f    error = %16.12f", x, f, err );
        x += h;
    }



    chebyshev_fit( a, b, c, n, ex );
    chebyshev_deriv( a, b, c, cder, mf );
    chebyshev_integ( a, b, c, cint, mf );

    printf( "\n\n  Fit of f(x) = x from a = %3.1f to b = %3.1f with %d coefficients . . .", a, b, n );
    for ( i = 0; i < n/2; ++i ) printf( "\n  c[%2d] = %16.12f                c[%2d] = %16.12f", i, c[i], i+n/2, c[i+n/2] );

    printf( "\n\n  Evaluation of f(x) = x from a = %3.1f to b = %3.1f with %d coefficients . . .", a, b, m5 );
    x = a;
    while ( x <= b ) {
        f = chebyshev_eval( a, b, c, m5, x );
        err = f - ex(x);
        printf( "\n  f(%3.1f) = %16.12f    error = %16.12f", x, f, err );
        x += h;
    }

    printf( "\n\n  Evaluation of f(x) = x from a = %3.1f to b = %3.1f with %d coefficients . . .", a, b, ma );
    x = a;
    while ( x <= b ) {
        f = chebyshev_eval( a, b, c, ma, x );
        err = f - ex(x);
        printf( "\n  f(%3.1f) = %16.12f    error = %16.12f", x, f, err );
        x += h;
    }

    printf( "\n\n  Evaluation of derivative of f(x) from a = %3.1f to b = %3.1f with %d coefficients . . .", a, b, ma );
    x = a;
    while ( x <= b ) {
        f = chebyshev_eval( a, b, cder, ma, x );
        err = f - ex_der(x);
        printf( "\n  f(%3.1f) = %16.12f    error = %16.12f", x, f, err );
        x += h;
    }

    printf( "\n\n  Evaluation of integral of f(x) from a = %3.1f to b = %3.1f with %d coefficients . . .", a, b, ma );
    x = a;
    while ( x <= b ) {
        f = chebyshev_eval( a, b, cint, ma, x );
        err = f - ex_int(x);
        printf( "\n  f(%3.1f) = %16.12f    error = %16.12f", x, f, err );
        x += h;
    }



    chebyshev_fit( a, b, c, n, foo );
    chebyshev_deriv( a, b, c, cder, mf );
    chebyshev_integ( a, b, c, cint, n );

    printf( "\n\n  Fit of f(x) = (1 - x)exp(-x/2) from a = %3.1f to b = %3.1f with %d coefficients . . .", a, b, n );
    for ( i = 0; i < n/2; ++i ) printf( "\n  c[%2d] = %16.12f                c[%2d] = %16.12f", i, c[i], i+n/2, c[i+n/2] );

    printf( "\n\n  Fit of f'(x) = -(3 - x)exp(-x/2)/2 from a = %3.1f to b = %3.1f with %d coefficients . . .", a, b, n );
    for ( i = 0; i < n/2; ++i ) printf( "\n  cder[%2d] = %16.12f                cder[%2d] = %16.12f", i, cder[i], i+n/2, cder[i+n/2] );

    printf( "\n\n  Fit of F(x) = 2(1 + x)exp(-x/2) - 2 from a = %3.1f to b = %3.1f with %d coefficients . . .", a, b, n );
    for ( i = 0; i < n/2; ++i ) printf( "\n  cint[%2d] = %16.12f                cint[%2d] = %16.12f", i, cint[i], i+n/2, cint[i+n/2] );

    printf( "\n\n  Evaluation of f(x) = (1 - x)exp(-x/2) from a = %3.1f to b = %3.1f with %d coefficients . . .", a, b, m5 );
    x = a;
    while ( x <= b ) {
        f = chebyshev_eval( a, b, c, m5, x );
        err = f - foo(x);
        printf( "\n  f(%3.1f) = %16.12f    error = %16.12f", x, f, err );
        x += h;
    }

    printf( "\n\n  Evaluation of f(x) = (1 - x)exp(-x/2) from a = %3.1f to b = %3.1f with %d coefficients . . .", a, b, ma );
    x = a;
    while ( x <= b ) {
        f = chebyshev_eval( a, b, c, ma, x );
        err = f - foo(x);
        printf( "\n  f(%3.1f) = %16.12f    error = %16.12f", x, f, err );
        x += h;
    }

    printf( "\n\n  Evaluation of f(x) = (1 - x)exp(-x/2) from a = %3.1f to b = %3.1f with %d coefficients . . .", a, b, mf );
    x = a;
    while ( x <= b ) {
        f = chebyshev_eval( a, b, c, mf, x );
        err = f - foo(x);
        printf( "\n  f(%3.1f) = %16.12f    error = %16.12f", x, f, err );
        x += h;
    }

    printf( "\n\n  Evaluation of f'(x) = -(3 - x)exp(-x/2)/2 from a = %3.1f to b = %3.1f with %d coefficients . . .", a, b, mf );
    x = a;
    while ( x <= b ) {
        f = chebyshev_eval( a, b, cder, mf, x );
        err = f - foo_der(x);
        printf( "\n  f(%3.1f) = %16.12f    error = %16.12f", x, f, err );
        x += h;
    }

    printf( "\n\n  Evaluation F(x) = 2(1 + x)exp(-x/2) - 2 from a = %3.1f to b = %3.1f with %d coefficients . . .", a, b, mf );
    x = a;
    while ( x <= b ) {
        f = chebyshev_eval( a, b, cint, mf, x );
        err = f - foo_int(x);
        printf( "\n  f(%3.1f) = %16.12f    error = %16.12f", x, f, err );
        x += h;
    }




    printf( "\n\n" );


    free_dvector( cint, 0, n-1 );
    free_dvector( cder, 0, n-1 );
    free_dvector( c, 0, n-1 );
}