Debian Codegraph @

t/ifeffit.t

raw
1 #! /usr/bin/perl -w
2 # Before `make install' is performed this script should be runnable with
3 # `make test'. After `make install' it should work as `perl test.pl'
4
5 ######################### We start with some black magic to print on failure.
6
7 # Change 1..1 below to 1..last_test_to_print .
8 # (It may become useful if the test is moved to ./t subdirectory.)
9
10 BEGIN { $| = 1; print "1..8$/"; }
11 END {print "not ok 1$/" unless $loaded;}
12 use Ifeffit;
13 $loaded = 1;
14 print "ok 1$/";
15
16 ######################### End of black magic.
17
18 # Insert your test code below (better if it prints "ok 13"
19 # (correspondingly "not ok 13") depending on the success of chunk 13
20 # of the test code):
21
22 $test = 0; $pass = 0;
23 #----------------------------------------------------------------
24 # load ifeffit
25 $test++;
26 if ($@ ne "") {print "FAILED\n"; die;}
27
28 use Ifeffit qw(get_scalar get_string get_array);
29 use Ifeffit qw(put_scalar put_string put_array);
30 use Ifeffit qw(get_echo);
31 print "import methods:\nok 2$/";
32
33 $pass++;
34 #----------------------------------------------------------------
35 # call ifeffit
36 $test++;
37
38 $i = ifeffit( "x = 1.234500");
39 print STDERR "show: ";
40 if ($i eq 0) {
41 ifeffit( "show x");
42 print "ok 3$/";
43 } else {
44 print "not ok 3$/";
45 }
46
47 $pass++;
48 #----------------------------------------------------------------
49 # here doc
50 $test++;
51
52 my ($file, $type, $kweight) = ("a.xmu", "xmu", 1);
53 my $read_data =<<"END";
54 set (kmin = 0., kweight = $kweight, rbkg = 1.2)
55 read_data(file = $file, prefix = my, type = $type)
56 END
57
58 $i = ifeffit($read_data);
59
60 print STDERR "show arrays: ";
61 if ($i eq 0) {
62 ifeffit(" show my.energy, my.xmu");
63 print "ok 4$/";
64 } else {
65 print "not ok 4$/";
66 }
67
68 $pass++;
69 #----------------------------------------------------------------
70 # get scalar
71 $test++;
72
73 my $x = get_scalar("x");
74 print STDERR "get_scalar: ";
75 print $x == 1.2345 ? "ok 5\n" : "not ok 5\n";
76
77
78 $pass++;
79 #----------------------------------------------------------------
80 # put scalar
81 $test++;
82
83 my $phi = put_scalar("phi", 1.605);
84
85 print STDERR "put_scalar: ";
86 print get_scalar("phi") == 1.605 ? "ok 6\n" : "not ok 6\n";
87
88 $pass++;
89 #----------------------------------------------------------------
90 # put string
91 $test++;
92
93 print STDERR "put/get_string: ";
94 put_string("\$filename", "my.xmu");
95 print get_string("filename") eq "my.xmu" ? "ok 7\n" : "not ok 7\n";
96
97 $pass++;
98 #----------------------------------------------------------------
99 # put array
100 $test++;
101
102 for ($i = 0; $i< 5; $i++ ) { $z[$i] = sin($i * 799 + 99.111);}
103 $i = put_array("my.test", \@z);
104
105 @arr = get_array("my.test");
106 $ok = ( ($arr[0] + 0.988646491563589 < 0.001) and
107 ($arr[1] + 0.375094695653461 < 0.001) and
108 ($arr[2] - 0.605955984630199 < 0.001) and
109 ($arr[3] - 0.993321521104809 < 0.001) and
110 ($arr[4] - 0.40748067780344 < 0.001) );
111 print STDERR "put/get_array:";
112 print $ok ? "ok 8\n" : "not ok 8\n";
113
114
115 $pass++;