File: sdlgamerect.t

package info (click to toggle)
libsdl-perl 2.548-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,972 kB
  • sloc: perl: 13,985; ansic: 583; makefile: 35
file content (155 lines) | stat: -rw-r--r-- 5,441 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
use Test::More tests => 87;
use strict;
use warnings;
use SDL;

use_ok('SDLx::Rect');

can_ok(
	'SDLx::Rect', qw/
		new
		x
		y
		width
		height
		w
		h
		top
		left
		centerx
		centery
		/
);

my $rect = SDLx::Rect->new( 0, 0, 0, 0 );

isa_ok( $rect, 'SDLx::Rect', 'new went ok' );

foreach my $attr (
	qw(x y top    left  width   height
	w h bottom right centerx centery)
	)
{
	is( $rect->$attr, 0, "$attr is 0" );
}

# set and get at the same time (and testing method aliases)
is( $rect->left(15), 15, 'left is now 15' );
is( $rect->x,        15, 'x and left point to the same place' );
is( $rect->x(12),    12, 'x is now 12' );
is( $rect->left,     12, 'left is an alias to x' );

is( $rect->top(132), 132, 'top is now 132' );
is( $rect->y,        132, 'y and top point to the same place' );
is( $rect->y(123),   123, 'y is now 123' );
is( $rect->top,      123, 'top is an alias to y' );

is( $rect->w(54),     54, 'w is now 54' );
is( $rect->width,     54, 'w and width point to the same place' );
is( $rect->width(45), 45, 'w is now 45' );
is( $rect->w,         45, 'w is an alias to width' );

is( $rect->h(76),      76, 'h is now 76' );
is( $rect->height,     76, 'h and height point to the same place' );
is( $rect->height(67), 67, 'h is now 67' );
is( $rect->h,          67, 'h is an alias to height' );

# get alone
is( $rect->x(),      12,  'x is 12' );
is( $rect->left(),   12,  'left is 12' );
is( $rect->y(),      123, 'y is 123' );
is( $rect->top(),    123, 'top is 123' );
is( $rect->width(),  45,  'width is 45' );
is( $rect->w(),      45,  'w is 45' );
is( $rect->height(), 67,  'height is 67' );
is( $rect->h(),      67,  'h is 67' );

# other helpers
is( $rect->bottom,      190, 'bottom should be relative to heigth and top' );
is( $rect->bottom(189), 189, 'changing bottom value' );
is( $rect->bottom,      189, 'checking bottom value again' );
is( $rect->top,         122, 'top value should have been updated after bottom change' );
is( $rect->height,      67,  'height should have stayed the same' );

is( $rect->centery,      155, 'checking vertical center' );
is( $rect->centery(154), 154, 'changing centery value' );
is( $rect->centery,      154, 'checking centery value again' );
is( $rect->top, 121,
	'top value should have been updated after centery change'
);
is( $rect->height, 67, 'height should have stayed the same' );

is( $rect->right,     57, 'right should be relative to width and left' );
is( $rect->right(56), 56, 'changing right value' );
is( $rect->right,     56, 'checking right value again' );
is( $rect->left, 11,
	'left value should have been updated after bottom change'
);
is( $rect->width, 45, 'width should have stayed the same' );

is( $rect->centerx,     33, 'checking horizontal center' );
is( $rect->centerx(32), 32, 'changing centerx value' );
is( $rect->centerx,     32, 'checking centerx value again' );
is( $rect->left, 10,
	'left value should have been updated after bottom change'
);
is( $rect->width, 45, 'width should have stayed the same' );

# checking two-valued accessors
can_ok(
	'SDLx::Rect', qw/
		size
		center
		topleft
		midleft
		bottomleft
		topright
		midright
		bottomright
		midtop
		midbottom
		/
);

is_deeply( [ $rect->center ], [ 32, 154 ], 'checking center pair' );
$rect->center( undef, undef );
is( $rect->centerx, 32,  'center() does nothing when passed undef' );
is( $rect->centery, 154, 'center() does nothing when passed undef' );
$rect->center( undef, 200 );
is( $rect->centerx, 32,  'center() does nothing for X when passed undef' );
is( $rect->centery, 200, 'center() works on one-parameter (y)' );
$rect->center( 7, undef );
is( $rect->centerx, 7,   'center() works on one-parameter (x)' );
is( $rect->centery, 200, 'center() does nothing for Y when passed undef' );
$rect->center( 32, 154 );
is( $rect->centerx, 32,  'center() can be used as an acessor for x' );
is( $rect->centery, 154, 'center() can be used as an acessor for y' );

is_deeply( [ $rect->topleft ], [ 121, 10 ], 'checking topleft pair' );
$rect->topleft( undef, undef );
is( $rect->top,  121, 'topleft() does nothing when passed undef' );
is( $rect->left, 10,  'topleft() does nothing when passed undef' );
$rect->topleft( undef, 200 );
is( $rect->top,  121, 'topleft() does nothing for Y when passed undef' );
is( $rect->left, 200, 'topleft() works on one-parameter (x)' );
$rect->topleft( 7, undef );
is( $rect->top,  7,   'topleft() works on one-parameter (y)' );
is( $rect->left, 200, 'topleft() does nothing for X when passed undef' );
$rect->topleft( 121, 10 );
is( $rect->top,  121, 'topleft() can be used as an acessor for y' );
is( $rect->left, 10,  'topleft() can be used as an acessor for x' );

is_deeply( [ $rect->midleft ], [ 154, 10 ], 'checking midleft pair' );
$rect->midleft( undef, undef );
is( $rect->centery, 154, 'midleft() does nothing when passed undef' );
is( $rect->left,    10,  'midleft() does nothing when passed undef' );
$rect->midleft( undef, 200 );
is( $rect->centery, 154, 'midleft() does nothing for Y when passed undef' );
is( $rect->left,    200, 'midleft() works on one-parameter (x)' );
$rect->midleft( 7, undef );
is( $rect->centery, 7,   'midleft() works on one-parameter (y)' );
is( $rect->left,    200, 'midleft() does nothing for X when passed undef' );
$rect->midleft( 154, 10 );
is( $rect->centery, 154, 'midleft() can be used as an acessor for y' );
is( $rect->left,    10,  'midleft() can be used as an acessor for x' );
sleep(2);