ZodiacLibTest.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <?php
  2. App::uses('ZodiacLib', 'Tools.Misc');
  3. class ZodiacLibTest extends CakeTestCase {
  4. public $Zodiac;
  5. public function setUp() {
  6. $this->Zodiac = new ZodiacLib();
  7. }
  8. public function testImage() {
  9. $is = $this->Zodiac->image(ZodiacLib::SIGN_ARIES);
  10. echo returns($is);
  11. $this->assertEquals($is, 'aries');
  12. }
  13. public function testSigns() {
  14. $is = $this->Zodiac->signs();
  15. echo returns($is);
  16. $this->assertTrue(count($is) === 12);
  17. }
  18. public function testSign() {
  19. $is = $this->Zodiac->getSign(4, 9);
  20. echo returns($is);
  21. $this->assertSame($is, ZodiacLib::SIGN_ARIES);
  22. $is = $this->Zodiac->signs($is);
  23. pr($is);
  24. $this->assertEquals($is, __('zodiacAries'));
  25. # january
  26. $is = $this->Zodiac->getSign(1, 20);
  27. pr($is);
  28. $this->assertSame($is, ZodiacLib::SIGN_CAPRICORN);
  29. $is = $this->Zodiac->getSign(1, 21);
  30. pr($is);
  31. $this->assertSame($is, ZodiacLib::SIGN_AQUARIUS);
  32. #february
  33. $is = $this->Zodiac->getSign(2, 19);
  34. pr($is);
  35. $this->assertSame($is, ZodiacLib::SIGN_AQUARIUS);
  36. $is = $this->Zodiac->getSign(2, 20);
  37. pr($is);
  38. $this->assertSame($is, ZodiacLib::SIGN_PISCES);
  39. #march
  40. $is = $this->Zodiac->getSign(3, 20);
  41. pr($is);
  42. $this->assertSame($is, ZodiacLib::SIGN_PISCES);
  43. $is = $this->Zodiac->getSign(3, 21);
  44. pr($is);
  45. $this->assertSame($is, ZodiacLib::SIGN_ARIES);
  46. #april
  47. $is = $this->Zodiac->getSign(4, 20);
  48. pr($is);
  49. $this->assertSame($is, ZodiacLib::SIGN_ARIES);
  50. $is = $this->Zodiac->getSign(4, 21);
  51. pr($is);
  52. $this->assertSame($is, ZodiacLib::SIGN_TAURUS);
  53. #may
  54. $is = $this->Zodiac->getSign(5, 21);
  55. pr($is);
  56. $this->assertSame($is, ZodiacLib::SIGN_TAURUS);
  57. $is = $this->Zodiac->getSign(5, 22);
  58. pr($is);
  59. $this->assertSame($is, ZodiacLib::SIGN_GEMINI);
  60. #june
  61. $is = $this->Zodiac->getSign(6, 21);
  62. pr($is);
  63. $this->assertSame($is, ZodiacLib::SIGN_GEMINI);
  64. $is = $this->Zodiac->getSign(6, 22);
  65. pr($is);
  66. $this->assertSame($is, ZodiacLib::SIGN_CANCER);
  67. #july
  68. $is = $this->Zodiac->getSign(7, 23);
  69. pr($is);
  70. $this->assertSame($is, ZodiacLib::SIGN_CANCER);
  71. $is = $this->Zodiac->getSign(7, 24);
  72. pr($is);
  73. $this->assertSame($is, ZodiacLib::SIGN_LEO);
  74. #august
  75. $is = $this->Zodiac->getSign(8, 23);
  76. pr($is);
  77. $this->assertSame($is, ZodiacLib::SIGN_LEO);
  78. $is = $this->Zodiac->getSign(8, 24);
  79. pr($is);
  80. $this->assertSame($is, ZodiacLib::SIGN_VIRGO);
  81. #september
  82. $is = $this->Zodiac->getSign(9, 23);
  83. pr($is);
  84. $this->assertSame($is, ZodiacLib::SIGN_VIRGO);
  85. $is = $this->Zodiac->getSign(9, 24);
  86. pr($is);
  87. $this->assertSame($is, ZodiacLib::SIGN_LIBRA);
  88. #october
  89. $is = $this->Zodiac->getSign(10, 23);
  90. pr($is);
  91. $this->assertSame($is, ZodiacLib::SIGN_LIBRA);
  92. $is = $this->Zodiac->getSign(10, 24);
  93. pr($is);
  94. $this->assertSame($is, ZodiacLib::SIGN_SCORPIO);
  95. #november
  96. $is = $this->Zodiac->getSign(11, 22);
  97. pr($is);
  98. $this->assertSame($is, ZodiacLib::SIGN_SCORPIO);
  99. $is = $this->Zodiac->getSign(11, 23);
  100. pr($is);
  101. $this->assertSame($is, ZodiacLib::SIGN_SAGITTARIUS);
  102. #december
  103. $is = $this->Zodiac->getSign(12, 21);
  104. pr($is);
  105. $this->assertSame($is, ZodiacLib::SIGN_SAGITTARIUS);
  106. $is = $this->Zodiac->getSign(12, 22);
  107. pr($is);
  108. $this->assertSame($is, ZodiacLib::SIGN_CAPRICORN);
  109. }
  110. public function testRange() {
  111. $is = $this->Zodiac->getRange(ZodiacLib::SIGN_AQUARIUS);
  112. $this->assertEquals($is, array(array(1, 21), array(2, 19)));
  113. $is = $this->Zodiac->getRange(ZodiacLib::SIGN_PISCES);
  114. $this->assertEquals($is, array(array(2, 20), array(3, 20)));
  115. $is = $this->Zodiac->getRange(ZodiacLib::SIGN_ARIES);
  116. $this->assertEquals($is, array(array(3, 21), array(4, 20)));
  117. $is = $this->Zodiac->getRange(ZodiacLib::SIGN_TAURUS);
  118. $this->assertEquals($is, array(array(4, 21), array(5, 21)));
  119. $is = $this->Zodiac->getRange(ZodiacLib::SIGN_GEMINI);
  120. $this->assertEquals($is, array(array(5, 22), array(6, 21)));
  121. $is = $this->Zodiac->getRange(ZodiacLib::SIGN_CANCER);
  122. $this->assertEquals($is, array(array(6, 22), array(7, 23)));
  123. $is = $this->Zodiac->getRange(ZodiacLib::SIGN_LEO);
  124. $this->assertEquals($is, array(array(7, 24), array(8, 23)));
  125. $is = $this->Zodiac->getRange(ZodiacLib::SIGN_VIRGO);
  126. $this->assertEquals($is, array(array(8, 24), array(9, 23)));
  127. $is = $this->Zodiac->getRange(ZodiacLib::SIGN_LIBRA);
  128. $this->assertEquals($is, array(array(9, 24), array(10, 23)));
  129. $is = $this->Zodiac->getRange(ZodiacLib::SIGN_SCORPIO);
  130. $this->assertEquals($is, array(array(10, 24), array(11, 22)));
  131. $is = $this->Zodiac->getRange(ZodiacLib::SIGN_SAGITTARIUS);
  132. $this->assertEquals($is, array(array(11, 23), array(12, 21)));
  133. $is = $this->Zodiac->getRange(ZodiacLib::SIGN_CAPRICORN);
  134. $this->assertEquals($is, array(array(12, 22), array(1, 20)));
  135. }
  136. public function testSignViaRange() {
  137. for ($i = 1; $i <= 12; $i++) {
  138. echo ZodiacLib::signs($i).BR;
  139. $range = $this->Zodiac->getRange($i);
  140. $is = $this->Zodiac->getSign($range[0][0], $range[0][1]);
  141. $this->assertSame($is, $i);
  142. $is = $this->Zodiac->getSign($range[1][0], $range[1][1]);
  143. $this->assertSame($is, $i);
  144. # min-1
  145. $month = $range[0][0];
  146. $day = $range[0][1]-1;
  147. $is = $this->Zodiac->getSign($month, $day);
  148. $ii = $i;
  149. if ($ii == 1) {
  150. $ii = 13;
  151. }
  152. //debug(($i-1) % 12);
  153. $this->assertSame($is, $ii-1);
  154. # max+1
  155. $month = $range[1][0];
  156. $day = $range[1][1]+1;
  157. $ii = $i;
  158. if ($ii == 12) {
  159. $ii = 0;
  160. }
  161. $is = $this->Zodiac->getSign($month, $day);
  162. $this->assertSame($is, $ii+1);
  163. }
  164. }
  165. }