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