www.farid-hajji.net banner

Farid Hajji

Perl: Einführung, Anwendungen, Referenz (2/e) [Support-Site]

Farid Hajji: Perl - Einführung, Anwendungen, Referenz
2., aktualisierte und erweiterte Auflage
Addison-Wesley Longman, ISBN 3-8273-1535-2

Beispielprogramm

ST/Xten/test.pl
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'

#################### We start with some black magic to print on failure.

# Change 1..1 below to 1..last_test_to_print .
# (It may become useful if the test is moved to ./t subdirectory.)

BEGIN { $| = 1; print "1..8\n"; }
END {print "not ok 1\n" unless $loaded;}

use ST::Xten qw(t_norm1 t_norm2 t_norminf
        v_norm1 v_norm2 v_norminf
        v_normalize);

$loaded = 1;
print "ok 1\n";

#################### End of black magic.

# Insert your test code below (better if it prints "ok 13"
# (correspondingly "not ok 13") depending on the success of chunk 13
# of the test code):
my $epsilon = 1e-5;

my $tnorm1 = t_norm1(5,-6.2,7);
print abs($tnorm1 - 18.2) < $epsilon ? "ok 2\n" : "not ok 2\n";

my $tnorm2 = t_norm2(5,-6.2,7);
print abs($tnorm2 - 10.6037729) < $epsilon ? "ok 3\n" : "not ok 3\n";

my $tnormi = t_norminf(-3,2,1);
print abs($tnormi - 3) < $epsilon ? "ok 4\n" : "not ok 4\n";

my $vnorm1 = v_norm1(0.1,-0.2,0.3,-0.4,0.5);
print abs($vnorm1 - 1.5) < $epsilon ? "ok 5\n" : "not ok 5\n";

my $vnorm2 = v_norm2(0.1,-0.2,0.3,-0.4,0.5);
print abs($vnorm2 - .7416198) < $epsilon ? "ok 6\n" : "not ok 6\n";

my $vnormi = v_norminf(0.1,-0.2,0.3,-0.4,-0.5);
print abs($vnormi - 0.5) < $epsilon ? "ok 7\n" : "not ok 7\n";

@result = v_normalize(0.1,-0.2,0.3,-0.4,0.5);
if ($result[0] - .1348399725    < $epsilon and
    $result[1] - (-.2696799450) < $epsilon and
    $result[2] - .4045199175    < $epsilon and
    $result[3] - (-.5393598900) < $epsilon and
    $result[4] - .6741998625    < $epsilon) {
    print "ok 8\n";
} else {
    print "not ok 8\n";
}
   

[Prev] [Up] [Relevant Chapter] [Next]

[Alte Quelle]


Last modified: $Date: 2006/05/18 12:56:13 $
FH. Search :: Sitemap :: Disclaimer :: Copyright :: Privacy
FreeBSD Logo