ZodiacLibTest.php 5.8 KB

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