MathTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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_Crypt
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2014 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. require_once 'Zend/Crypt/Math.php';
  23. /**
  24. * @category Zend
  25. * @package Zend_Crypt
  26. * @subpackage UnitTests
  27. * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  28. * @license http://framework.zend.com/license/new-bsd New BSD License
  29. * @group Zend_Crypt
  30. */
  31. class Zend_Crypt_MathTest extends PHPUnit_Framework_TestCase
  32. {
  33. public function testRand()
  34. {
  35. if (!extension_loaded('bcmath'))
  36. {
  37. $this->markTestSkipped('Extension bcmath not loaded');
  38. }
  39. try {
  40. $math = new Zend_Crypt_Math_BigInteger();
  41. } catch (Zend_Crypt_Math_BigInteger_Exception $e) {
  42. if (strpos($e->getMessage(), 'big integer precision math support not detected') !== false) {
  43. $this->markTestSkipped($e->getMessage());
  44. } else {
  45. throw $e;
  46. }
  47. }
  48. $math = new Zend_Crypt_Math();
  49. $higher = '155172898181473697471232257763715539915724801966915404479707795314057629378541917580651227423698188993727816152646631438561595825688188889951272158842675419950341258706556549803580104870537681476726513255747040765857479291291572334510643245094715007229621094194349783925984760375594985848253359305585439638443';
  50. $lower = '155172898181473697471232257763715539915724801966915404479707795314057629378541917580651227423698188993727816152646631438561595825688188889951272158842675419950341258706556549803580104870537681476726513255747040765857479291291572334510643245094715007229621094194349783925984760375594985848253359305585439638442';
  51. $result = $math->rand($lower, $higher);
  52. $this->assertTrue(bccomp($result, $higher) !== '1');
  53. $this->assertTrue(bccomp($result, $lower) !== '-1');
  54. }
  55. }