/tests/Zend/Measure/AngleTest.php

https://github.com/Exercise/zf2 · PHP · 389 lines · 183 code · 56 blank · 150 comment · 0 complexity · 7c478507fea5e82c52b2a10e4ab844f5 MD5 · raw file

  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Measure
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @namespace
  24. */
  25. namespace ZendTest\Measure;
  26. use Zend\Measure;
  27. /**
  28. * @category Zend
  29. * @package Zend_Measure
  30. * @subpackage UnitTests
  31. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  32. * @license http://framework.zend.com/license/new-bsd New BSD License
  33. * @group Zend_Measure
  34. */
  35. class AngleTest extends \PHPUnit_Framework_TestCase
  36. {
  37. /**
  38. * test for Angle initialisation
  39. * expected instance
  40. */
  41. public function testAngleInit()
  42. {
  43. $value = new Measure\Angle('100',Measure\Angle::STANDARD,'de');
  44. $this->assertTrue($value instanceof Measure\Angle,'Zend\Measure\Angle Object not returned');
  45. }
  46. /**
  47. * test for exception unknown type
  48. * expected exception
  49. */
  50. public function testAngleUnknownType()
  51. {
  52. try {
  53. $value = new Measure\Angle('100','Angle::UNKNOWN','de');
  54. $this->fail('Exception expected because of unknown type');
  55. } catch (Measure\Exception $e) {
  56. // success
  57. }
  58. }
  59. /**
  60. * test for exception unknown value
  61. * expected exception
  62. */
  63. public function testAngleUnknownValue()
  64. {
  65. try {
  66. $value = new Measure\Angle('novalue',Measure\Angle::STANDARD,'de');
  67. $this->fail('Exception expected because of empty value');
  68. } catch (Measure\Exception $e) {
  69. // success
  70. }
  71. }
  72. /**
  73. * test for exception unknown locale
  74. * expected root value
  75. */
  76. public function testAngleUnknownLocale()
  77. {
  78. try {
  79. $value = new Measure\Angle('100',Measure\Angle::STANDARD,'nolocale');
  80. $this->fail('Exception expected because of unknown locale');
  81. } catch (Measure\Exception $e) {
  82. // success
  83. }
  84. }
  85. /**
  86. * test for standard locale
  87. * expected integer
  88. */
  89. public function testAngleNoLocale()
  90. {
  91. $value = new Measure\Angle('100',Measure\Angle::STANDARD);
  92. $this->assertEquals(100, $value->getValue(),'Zend\Measure\Angle value expected');
  93. }
  94. /**
  95. * test for positive value
  96. * expected integer
  97. */
  98. public function testAngleValuePositive()
  99. {
  100. $value = new Measure\Angle('100',Measure\Angle::STANDARD,'de');
  101. $this->assertEquals(100, $value->getValue(), 'Zend\Measure\Angle value expected to be a positive integer');
  102. }
  103. /**
  104. * test for negative value
  105. * expected integer
  106. */
  107. public function testAngleValueNegative()
  108. {
  109. $value = new Measure\Angle('-100',Measure\Angle::STANDARD,'de');
  110. $this->assertEquals(-100, $value->getValue(), 'Zend\Measure\Angle value expected to be a negative integer');
  111. }
  112. /**
  113. * test for decimal value
  114. * expected float
  115. */
  116. public function testAngleValueDecimal()
  117. {
  118. $value = new Measure\Angle('-100,200',Measure\Angle::STANDARD,'de');
  119. $this->assertEquals(-100.200, $value->getValue(), 'Zend\Measure\Angle value expected to be a decimal value');
  120. }
  121. /**
  122. * test for decimal seperated value
  123. * expected float
  124. */
  125. public function testAngleValueDecimalSeperated()
  126. {
  127. $value = new Measure\Angle('-100.100,200',Measure\Angle::STANDARD,'de');
  128. $this->assertEquals(-100100.200, $value->getValue(),'Zend\Measure\Angle Object not returned');
  129. }
  130. /**
  131. * test for string with integrated value
  132. * expected float
  133. */
  134. public function testAngleValueString()
  135. {
  136. $value = new Measure\Angle('-100.100,200',Measure\Angle::STANDARD,'de');
  137. $this->assertEquals(-100100.200, $value->getValue(),'Zend\Measure\Angle Object not returned');
  138. }
  139. /**
  140. * test for equality
  141. * expected true
  142. */
  143. public function testAngleEquality()
  144. {
  145. $value = new Measure\Angle('-100.100,200',Measure\Angle::STANDARD,'de');
  146. $newvalue = new Measure\Angle('-100.100,200',Measure\Angle::STANDARD,'de');
  147. $this->assertTrue($value->equals($newvalue),'Zend\Measure\Angle Object should be equal');
  148. }
  149. /**
  150. * test for no equality
  151. * expected false
  152. */
  153. public function testAngleNoEquality()
  154. {
  155. $value = new Measure\Angle('-100.100,200',Measure\Angle::STANDARD,'de');
  156. $newvalue = new Measure\Angle('-100,200',Measure\Angle::STANDARD,'de');
  157. $this->assertFalse($value->equals($newvalue),'Zend\Measure\Angle Object should be not equal');
  158. }
  159. /**
  160. * test for set positive value
  161. * expected integer
  162. */
  163. public function testAngleSetPositive()
  164. {
  165. $value = new Measure\Angle('100',Measure\Angle::STANDARD,'de');
  166. $value->setValue('200',Measure\Angle::STANDARD,'de');
  167. $this->assertEquals(200, $value->getValue(), 'Zend\Measure\Angle value expected to be a positive integer');
  168. }
  169. /**
  170. * test for set negative value
  171. * expected integer
  172. */
  173. public function testAngleSetNegative()
  174. {
  175. $value = new Measure\Angle('-100',Measure\Angle::STANDARD,'de');
  176. $value->setValue('-200',Measure\Angle::STANDARD,'de');
  177. $this->assertEquals(-200, $value->getValue(), 'Zend\Measure\Angle value expected to be a negative integer');
  178. }
  179. /**
  180. * test for set decimal value
  181. * expected float
  182. */
  183. public function testAngleSetDecimal()
  184. {
  185. $value = new Measure\Angle('-100,200',Measure\Angle::STANDARD,'de');
  186. $value->setValue('-200,200',Measure\Angle::STANDARD,'de');
  187. $this->assertEquals(-200.200, $value->getValue(), 'Zend\Measure\Angle value expected to be a decimal value');
  188. }
  189. /**
  190. * test for set decimal seperated value
  191. * expected float
  192. */
  193. public function testAngleSetDecimalSeperated()
  194. {
  195. $value = new Measure\Angle('-100.100,200',Measure\Angle::STANDARD,'de');
  196. $value->setValue('-200.200,200',Measure\Angle::STANDARD,'de');
  197. $this->assertEquals(-200200.200, $value->getValue(),'Zend\Measure\Angle Object not returned');
  198. }
  199. /**
  200. * test for set string with integrated value
  201. * expected float
  202. */
  203. public function testAngleSetString()
  204. {
  205. $value = new Measure\Angle('-100.100,200',Measure\Angle::STANDARD,'de');
  206. $value->setValue('-200.200,200',Measure\Angle::STANDARD,'de');
  207. $this->assertEquals(-200200.200, $value->getValue(),'Zend\Measure\Angle Object not returned');
  208. }
  209. /**
  210. * test for exception unknown type
  211. * expected exception
  212. */
  213. public function testAngleSetUnknownType()
  214. {
  215. try {
  216. $value = new Measure\Angle('100',Measure\Angle::STANDARD,'de');
  217. $value->setValue('-200.200,200','Angle::UNKNOWN','de');
  218. $this->fail('Exception expected because of unknown type');
  219. } catch (Measure\Exception $e) {
  220. // success
  221. }
  222. }
  223. /**
  224. * test for exception unknown value
  225. * expected exception
  226. */
  227. public function testAngleSetUnknownValue()
  228. {
  229. try {
  230. $value = new Measure\Angle('100',Measure\Angle::STANDARD,'de');
  231. $value->setValue('novalue',Measure\Angle::STANDARD,'de');
  232. $this->fail('Exception expected because of empty value');
  233. } catch (Measure\Exception $e) {
  234. // success
  235. }
  236. }
  237. /**
  238. * test for exception unknown locale
  239. * expected exception
  240. */
  241. public function testAngleSetUnknownLocale()
  242. {
  243. try {
  244. $value = new Measure\Angle('100',Measure\Angle::STANDARD,'de');
  245. $value->setValue('200',Measure\Angle::STANDARD,'nolocale');
  246. $this->fail('Exception expected because of unknown locale');
  247. } catch (Measure\Exception $e) {
  248. // success
  249. }
  250. }
  251. /**
  252. * test for exception unknown locale
  253. * expected exception
  254. */
  255. public function testAngleSetWithNoLocale()
  256. {
  257. $value = new Measure\Angle('100', Measure\Angle::STANDARD, 'de');
  258. $value->setValue('200', Measure\Angle::STANDARD);
  259. $this->assertEquals(200, $value->getValue(), 'Zend\Measure\Angle value expected to be a positive integer');
  260. }
  261. /**
  262. * test setting type
  263. * expected new type
  264. */
  265. public function testAngleSetType()
  266. {
  267. $value = new Measure\Angle('-100',Measure\Angle::STANDARD,'de');
  268. $value->setType(Measure\Angle::GRAD);
  269. $this->assertEquals(Measure\Angle::GRAD, $value->getType(), 'Zend\Measure\Angle type expected');
  270. }
  271. /**
  272. * test setting computed type
  273. * expected new type
  274. */
  275. public function testAngleSetComputedType1()
  276. {
  277. $value = new Measure\Angle('-100',Measure\Angle::RADIAN,'de');
  278. $value->setType(Measure\Angle::MINUTE);
  279. $this->assertEquals(Measure\Angle::MINUTE, $value->getType(), 'Zend\Measure\Angle type expected');
  280. }
  281. /**
  282. * test setting computed type
  283. * expected new type
  284. */
  285. public function testAngleSetComputedType2()
  286. {
  287. $value = new Measure\Angle('-100',Measure\Angle::MINUTE,'de');
  288. $value->setType(Measure\Angle::RADIAN);
  289. $this->assertEquals(Measure\Angle::RADIAN, $value->getType(), 'Zend\Measure\Angle type expected');
  290. }
  291. /**
  292. * test setting unknown type
  293. * expected new type
  294. */
  295. public function testAngleSetTypeFailed()
  296. {
  297. try {
  298. $value = new Measure\Angle('-100',Measure\Angle::STANDARD,'de');
  299. $value->setType('Angle::UNKNOWN');
  300. $this->fail('Exception expected because of unknown type');
  301. } catch (Measure\Exception $e) {
  302. // success
  303. }
  304. }
  305. /**
  306. * test toString
  307. * expected string
  308. */
  309. public function testAngleToString()
  310. {
  311. $value = new Measure\Angle('-100',Measure\Angle::STANDARD,'de');
  312. $this->assertEquals('-100 rad', $value->toString(), 'Value -100 rad expected');
  313. }
  314. /**
  315. * test __toString
  316. * expected string
  317. */
  318. public function testAngle_ToString()
  319. {
  320. $value = new Measure\Angle('-100',Measure\Angle::STANDARD,'de');
  321. $this->assertEquals('-100 rad', $value->__toString(), 'Value -100 rad expected');
  322. }
  323. /**
  324. * test getConversionList
  325. * expected array
  326. */
  327. public function testAngleConversionList()
  328. {
  329. $value = new Measure\Angle('-100',Measure\Angle::STANDARD,'de');
  330. $unit = $value->getConversionList();
  331. $this->assertTrue(is_array($unit), 'Array expected');
  332. }
  333. }