/t/sdlgamerect.t

http://github.com/PerlGameDev/SDL · Raku · 155 lines · 133 code · 18 blank · 4 comment · 0 complexity · 0cb13342f56c829020b66130b50da0e2 MD5 · raw file

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