PageRenderTime 35ms CodeModel.GetById 8ms app.highlight 23ms RepoModel.GetById 2ms app.codeStats 0ms

/t/sdlgamerect.t

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