Debian Codegraph @

t/pdl-graphics.t

raw symbols SCIP
1 BEGIN{
2 # Set perl to not try to resolve all symbols at startup
3 # The default behavior causes some problems because
4 # the PGPLOT code defines interfaces for all PGPLOT functions
5 # whether or not they are linked.
6 $ENVscip-perl cpan PGPLOT 2.36 main/`%ENV`.{'PERL_DL_NONLAZY'}=0;
7 }
8
9 use strictscip-perl cpan PGPLOT 2.36 strict/;
10 use warningsscip-perl cpan PGPLOT 2.36 warnings/;
11 use Test::Morescip-perl cpan PGPLOT 2.36 Test/More/;
12 use PGPLOTscip-perl cpan PGPLOT 2.36 PGPLOT/;
13 BEGIN {
14 eval {requirescip-perl cpan PGPLOT 2.36 main/require(). PDL};
15 planscip-perl cpan PGPLOT 2.36 main/plan(). skip_all => "No PDL, can't test this ($@)" if $@scip-perl cpan PGPLOT 2.36 main/`$@`.;
16 planscip-perl cpan PGPLOT 2.36 main/plan(). skip_all => "DISPLAY environment variable not set"
17 if !existsscip-perl cpan PGPLOT 2.36 main/exists(). $ENVscip-perl cpan PGPLOT 2.36 main/`%ENV`.{'DISPLAY'} and !existsscip-perl cpan PGPLOT 2.36 main/exists(). $ENVscip-perl cpan PGPLOT 2.36 main/`%ENV`.{HARNESS_ACTIVE};
18 }
19 use PDLscip-perl cpan PGPLOT 2.36 PDL/;
20 use PDL::Graphics::PGPLOTscip-perl cpan PGPLOT 2.36 PDL/Graphics/PGPLOT/;
21 use PDL::Graphics::PGPLOT::Windowscip-perl cpan PGPLOT 2.36 PDL/Graphics/PGPLOT/Window/;
22
23 sub get_answerscip-perl cpan PGPLOT 2.36 main/get_answer(). () {
24 print STDERR "Does this look OK (y/n, y is default)? :";
25 my $answer = <STDIN>;
26 return $answer !~ m/n/i;
27 }
28
29 my $tick_txt = <<'EOD';
30 PGPLOT X device... you should see a 6 inch (153 mm) x 4 inch (102 mm)
31 X window with four plots in it. All four images should have tick marks
32 on the outside of the axes.
33
34 [ Scaled image of m51; scale [Scaled image of m51 with scale from
35 in pixels on both axes ] X=[-1.8, 2.0],Y=[-1.9, 1.9] arcmin,
36 with cal. wedge, centered in rect. frame]
37
38 [ Square image of m51; scale [Square image of m51 with scale as above,
39 in pixels on both axes; ``shrink-wrapped'']
40 ``shrinkwrapped'' ]
41
42 EOD
43 my $pitch_txt = <<'EOD';
44 ==============================================================
45
46 You should see four plots demonstrating pitch setting, justification,
47 and alignment:
48
49 [ Square image of m51 scaled to [Short, squat image of m51 with
50 300 ppi (1.25 inches wide), aligned aspect ratio 1:2, width 1.25 inch,
51 to bottom left corner of rect. plot and height 0.625 inch, shrinkwrapped
52 box and cropped at the top. ] and placed at lower left of plot rgn]
53
54 [ Square image of m51 scaled to [Tall, narrow image of m51 with
55 300 ppi (1.25 inches wide), aligned aspect ratio 2:1, width 0.625 inch,
56 to upper right corner of rect. plot and height 1.25 inch, shrinkwrapped
57 box and cropped at the bottom. ] and placed at upper right of plot rgn]
58
59 EOD
60 my $fib_txt = <<'EOD';
61 ==============================================================
62
63 You should see two windows:
64
65 One with two graphs, left with Fibonacci curve
66 One with one graph
67
68 EOD
69
70 sub interactivescip-perl cpan PGPLOT 2.36 main/interactive(). ($$) {
71 my $flag = shiftscip-perl cpan PGPLOT 2.36 main/shift().;
72 return unless $flag; # ie not interactive
73 my $num = shiftscip-perl cpan PGPLOT 2.36 main/shift().;
74 if (1 == $num) {
75 print STDERR $tick_txt;
76 } elsif (2 == $num) {
77 print STDERR $pitch_txt;
78 } elsif (3 == $num) {
79 print STDERR $fib_txt;
80 } else {
81 diescip-perl cpan PGPLOT 2.36 main/die(). "Internal error: unknown test number $num for interactive()!\n";
82 }
83 return get_answerscip-perl cpan PGPLOT 2.36 main/get_answer().();
84 }
85
86 my $interactive = existsscip-perl cpan PGPLOT 2.36 main/exists().($ENVscip-perl cpan PGPLOT 2.36 main/`%ENV`.{'PDL_INT'});
87 my $skip_interactive_msg = "no interactive tests as env var PDL_INT not set";
88 my $interactive_ctr = 0;
89
90 my $dev = $ENVscip-perl cpan PGPLOT 2.36 main/`%ENV`.{'PGPLOT_DEV'} || "/xw";
91 $dev = '/null' if existsscip-perl cpan PGPLOT 2.36 main/exists(). $ENVscip-perl cpan PGPLOT 2.36 main/`%ENV`.{HARNESS_ACTIVE} and not $interactive;
92
93 my $w = PDL::Graphics::PGPLOT::Window->newscip-perl cpan PGPLOT 2.36 PDL/Graphics/PGPLOT/Window/new().(
94 Dev => $dev,
95 Size=> [6,4],
96 NX=>2, NY=>2,
97 Ch=>2.5, HardCH=>2.5
98 );
99 isa_okscip-perl cpan PGPLOT 2.36 main/isa_ok().($w, "PDL::Graphics::PGPLOT::Window");
100
101 # try and find m51.fits
102 my @f = qw(PDL Demos m51.fits);
103 our $m51filescip-perl cpan PGPLOT 2.36 main/$m51file. = undef;
104 foreach my $path ( @INCscip-perl cpan PGPLOT 2.36 main/`@INC`. ) {
105 my $file = File::Spec->catfilescip-perl cpan PGPLOT 2.36 File/Spec/catfile().( $path, @f );
106 if ( -f $file ) { $m51filescip-perl cpan PGPLOT 2.36 main/$m51file. = $file; last; }
107 }
108 diescip-perl cpan PGPLOT 2.36 main/die(). "Unable to find m51.fits within the perl libraries.\n"
109 unless definedscip-perl cpan PGPLOT 2.36 main/defined(). $m51filescip-perl cpan PGPLOT 2.36 main/$m51file.;
110 my $x = rfitsscip-perl cpan PGPLOT 2.36 main/rfits().($m51filescip-perl cpan PGPLOT 2.36 main/$m51file.);
111
112 ##############################
113 # Page 1
114 #
115 foreach my $str (
116 '$w->imag($x,{Title=>"\$w->imag(\$x);"} );',
117 '$w->fits_imag($x,{Title=>"\$w->fits_imag(\$x);"});',
118 '$w->imag($x,{J=>1,Title=>"\$w->imag(\$x,{J=>1});"});',
119 '$w->fits_imag($x,{J=>1,Title=>"\$w->fits_imag(\$x,{J=>1});"});'
120 ) {
121 my $result = eval $str;
122 isscip-perl cpan PGPLOT 2.36 main/is(). $@scip-perl cpan PGPLOT 2.36 main/`$@`., '', "eval '$str'";
123 isntscip-perl cpan PGPLOT 2.36 main/isnt(). $result, 0, 'returned true';
124 }
125
126 $interactive_ctr++;
127 SKIP: {
128 skipscip-perl cpan PGPLOT 2.36 main/skip(). $skip_interactive_msg, 1 unless $interactive;
129 okscip-perl cpan PGPLOT 2.36 main/ok().(interactivescip-perl cpan PGPLOT 2.36 main/interactive().($interactive, $interactive_ctr), "interactive tests");
130 }
131
132 ##############################
133 # Page 2
134 #
135 foreach my $str ( (
136 '$w->imag($x,{Pitch=>300,Align=>"LB",Title=>"\$w->imag(\$x,{Pitch=>300,Align=>LB})"});',
137 '$w->imag($x,{J=>.5,Pitch=>300,Align=>"LB",Title=>"\$w->imag(\$x,{J=>.5,Pitch=>300,Align=>LB})"});',
138 '$w->imag($x,{Pitch=>300,Align=>"RT",Title=>"\$w->imag(\$x,{Pitch=>300,Align=>RT})"});',
139 '$w->imag($x,{J=>2,Pitch=>600,Align=>"RT",Title=>"\$w->imag(\$x,{J=>2,Pitch=>600,Align=>RT}) ."});',
140 ) ) {
141 my $result = eval $str;
142 isscip-perl cpan PGPLOT 2.36 main/is(). $@scip-perl cpan PGPLOT 2.36 main/`$@`., '', "eval '$str'";
143 isntscip-perl cpan PGPLOT 2.36 main/isnt(). $result, 0, 'returned true';
144 }
145
146 $interactive_ctr++;
147 SKIP: {
148 skipscip-perl cpan PGPLOT 2.36 main/skip(). $skip_interactive_msg, 1 unless $interactive;
149 okscip-perl cpan PGPLOT 2.36 main/ok().(interactivescip-perl cpan PGPLOT 2.36 main/interactive().($interactive, $interactive_ctr), "interactive tests");
150 }
151
152 my $result = eval '$w->close';
153 isscip-perl cpan PGPLOT 2.36 main/is(). $@scip-perl cpan PGPLOT 2.36 main/`$@`., '', "close window";
154 isntscip-perl cpan PGPLOT 2.36 main/isnt(). $result, 0, 'returned true';
155
156 my @opts = (Device => $dev, Aspect => 1, WindowWidth => 5);
157 my $rate_win = PDL::Graphics::PGPLOT::Window->newscip-perl cpan PGPLOT 2.36 PDL/Graphics/PGPLOT/Window/new().(@opts, NXPanel => 2);
158 my $area_win = PDL::Graphics::PGPLOT::Window->newscip-perl cpan PGPLOT 2.36 PDL/Graphics/PGPLOT/Window/new().(@opts);
159 isa_okscip-perl cpan PGPLOT 2.36 main/isa_ok().($rate_win, "PDL::Graphics::PGPLOT::Window");
160 isa_okscip-perl cpan PGPLOT 2.36 main/isa_ok().($area_win, "PDL::Graphics::PGPLOT::Window");
161 foreach my $str ( (
162 q($rate_win->env(0, 10, 0, 1000, {XTitle => 'Days', YTitle => '#Rabbits'})),
163 q($rate_win->env(0, 10, 0, 100, {Xtitle=>'Days', Ytitle => 'Rabbits/day'})),
164 q($area_win->env(0, 1, 0, 1, {XTitle => 'Km', Ytitle => 'Km'})),
165 q($rate_win->line(sequence(10), fibonacci(10), {Panel => [1, 1]})),
166 ) ) {
167 my $result = eval $str;
168 isscip-perl cpan PGPLOT 2.36 main/is(). $@scip-perl cpan PGPLOT 2.36 main/`$@`., '', "eval '$str'";
169 isntscip-perl cpan PGPLOT 2.36 main/isnt(). $result, 0, 'returned true';
170 }
171
172 $interactive_ctr++;
173 SKIP: {
174 skipscip-perl cpan PGPLOT 2.36 main/skip(). $skip_interactive_msg, 1 unless $interactive;
175 okscip-perl cpan PGPLOT 2.36 main/ok().(interactivescip-perl cpan PGPLOT 2.36 main/interactive().($interactive, $interactive_ctr), "interactive tests");
176 }
177
178 for my $win ($rate_win, $area_win) {
179 my $result = eval { $win->closescip-perl cpan PGPLOT 2.36 main/close(). };
180 isscip-perl cpan PGPLOT 2.36 main/is(). $@scip-perl cpan PGPLOT 2.36 main/`$@`., '', "close window";
181 isntscip-perl cpan PGPLOT 2.36 main/isnt(). $result, 0, 'returned true';
182 }
183
184 diagscip-perl cpan PGPLOT 2.36 main/diag(). 'On X you need to close the X window to continue' if $interactive;
185
186 done_testing;