Fixed the pod path in archive
[sdlgit/SDL_perl.git] / t / sdlgamerect.t
CommitLineData
68210590 1use Test::More tests => 87;
2use strict;
1109e28a 3use SDL;
68210590 4
5use_ok( 'SDL::Game::Rect' );
6
7can_ok ('SDL::Game::Rect', qw/
8 new
9 x
10 y
11 width
12 height
13 w
14 h
15 top
16 left
17 centerx
18 centery
19 /);
20
1109e28a 21
3441c67a 22my $rect = SDL::Game::Rect->new( 0, 0, 0, 0);
68210590 23
24isa_ok ($rect, 'SDL::Game::Rect','new went ok');
25
26foreach my $attr (qw(x y top left width height
27 w h bottom right centerx centery)
28 ) {
29 is ($rect->$attr, 0, "$attr is 0");
30}
31
32# set and get at the same time (and testing method aliases)
33is ($rect->left(15), 15, 'left is now 15');
34is ($rect->x, 15, 'x and left point to the same place');
35is ($rect->x(12), 12, 'x is now 12');
36is ($rect->left, 12, 'left is an alias to x');
37
38is ($rect->top(132), 132, 'top is now 132');
39is ($rect->y, 132, 'y and top point to the same place');
40is ($rect->y(123), 123, 'y is now 123');
41is ($rect->top, 123, 'top is an alias to y');
42
60465232 43
1109e28a 44
68210590 45is ($rect->w(54), 54, 'w is now 54');
46is ($rect->width, 54, 'w and width point to the same place');
47is ($rect->width(45), 45, 'w is now 45');
48is ($rect->w, 45, 'w is an alias to width');
49
1c436bbf 50
68210590 51is ($rect->h(76), 76, 'h is now 76');
52is ($rect->height, 76, 'h and height point to the same place');
53is ($rect->height(67), 67, 'h is now 67');
54is ($rect->h, 67, 'h is an alias to height');
55
56# get alone
57is ($rect->x(), 12, 'x is 12');
58is ($rect->left(), 12, 'left is 12');
59is ($rect->y(), 123, 'y is 123');
60is ($rect->top(), 123, 'top is 123');
61is ($rect->width(), 45, 'width is 45');
62is ($rect->w(), 45, 'w is 45');
63is ($rect->height(), 67, 'height is 67');
64is ($rect->h(), 67, 'h is 67');
65
66# other helpers
67is ($rect->bottom, 190, 'bottom should be relative to heigth and top');
68is ($rect->bottom(189), 189, 'changing bottom value');
69is ($rect->bottom, 189, 'checking bottom value again');
70is ($rect->top, 122, 'top value should have been updated after bottom change');
71is ($rect->height, 67, 'height should have stayed the same');
72
73is ($rect->centery, 155, 'checking vertical center');
74is ($rect->centery(154), 154, 'changing centery value');
75is ($rect->centery, 154, 'checking centery value again');
76is ($rect->top, 121, 'top value should have been updated after centery change');
77is ($rect->height, 67, 'height should have stayed the same');
78
79is ($rect->right, 57, 'right should be relative to width and left');
80is ($rect->right(56), 56, 'changing right value');
81is ($rect->right, 56, 'checking right value again');
82is ($rect->left, 11, 'left value should have been updated after bottom change');
83is ($rect->width, 45, 'width should have stayed the same');
84
85is ($rect->centerx, 33, 'checking horizontal center');
86is ($rect->centerx(32), 32, 'changing centerx value');
87is ($rect->centerx, 32, 'checking centerx value again');
88is ($rect->left, 10, 'left value should have been updated after bottom change');
89is ($rect->width, 45, 'width should have stayed the same');
90
91# checking two-valued accessors
92can_ok ('SDL::Game::Rect', qw/
93 size
94 center
95 topleft
96 midleft
97 bottomleft
98 topright
99 midright
100 bottomright
101 midtop
102 midbottom
103 /);
104
105
106is_deeply ( [$rect->center], [32, 154], 'checking center pair');
107$rect->center(undef, undef);
108is($rect->centerx, 32, 'center() does nothing when passed undef');
109is($rect->centery, 154, 'center() does nothing when passed undef');
110$rect->center(undef, 200);
111is($rect->centerx, 32, 'center() does nothing for X when passed undef');
112is($rect->centery, 200, 'center() works on one-parameter (y)');
113$rect->center(7, undef);
114is($rect->centerx, 7, 'center() works on one-parameter (x)');
115is($rect->centery, 200, 'center() does nothing for Y when passed undef');
116$rect->center(32, 154);
117is($rect->centerx, 32, 'center() can be used as an acessor for x');
118is($rect->centery, 154, 'center() can be used as an acessor for y');
119
120is_deeply ( [$rect->topleft], [121, 10], 'checking topleft pair');
121$rect->topleft(undef, undef);
122is($rect->top, 121, 'topleft() does nothing when passed undef');
123is($rect->left, 10, 'topleft() does nothing when passed undef');
124$rect->topleft(undef, 200);
125is($rect->top, 121, 'topleft() does nothing for Y when passed undef');
126is($rect->left, 200, 'topleft() works on one-parameter (x)');
127$rect->topleft(7, undef);
128is($rect->top, 7, 'topleft() works on one-parameter (y)');
129is($rect->left, 200, 'topleft() does nothing for X when passed undef');
130$rect->topleft(121, 10);
131is($rect->top, 121, 'topleft() can be used as an acessor for y');
132is($rect->left, 10, 'topleft() can be used as an acessor for x');
133
134is_deeply ( [$rect->midleft], [154, 10], 'checking midleft pair');
135$rect->midleft(undef, undef);
136is($rect->centery, 154, 'midleft() does nothing when passed undef');
137is($rect->left, 10, 'midleft() does nothing when passed undef');
138$rect->midleft(undef, 200);
139is($rect->centery, 154, 'midleft() does nothing for Y when passed undef');
140is($rect->left, 200, 'midleft() works on one-parameter (x)');
141$rect->midleft(7, undef);
142is($rect->centery, 7, 'midleft() works on one-parameter (y)');
143is($rect->left, 200, 'midleft() does nothing for X when passed undef');
144$rect->midleft(154, 10);
145is($rect->centery, 154, 'midleft() can be used as an acessor for y');
146is($rect->left, 10, 'midleft() can be used as an acessor for x');