MathTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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-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. require_once 'Zend/Crypt/Math.php';
  23. /**
  24. * @category Zend
  25. * @package Zend_Crypt
  26. * @subpackage UnitTests
  27. * @copyright Copyright (c) 2005-2010 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. try {
  36. $math = new Zend_Crypt_Math_BigInteger();
  37. } catch (Zend_Crypt_Math_BigInteger_Exception $e) {
  38. if (strpos($e->getMessage(), 'big integer precision math support not detected') !== false) {
  39. $this->markTestSkipped($e->getMessage());
  40. } else {
  41. throw $e;
  42. }
  43. }
  44. $math = new Zend_Crypt_Math();
  45. $higher = '155172898181473697471232257763715539915724801966915404479707795314057629378541917580651227423698188993727816152646631438561595825688188889951272158842675419950341258706556549803580104870537681476726513255747040765857479291291572334510643245094715007229621094194349783925984760375594985848253359305585439638443';
  46. $lower = '155172898181473697471232257763715539915724801966915404479707795314057629378541917580651227423698188993727816152646631438561595825688188889951272158842675419950341258706556549803580104870537681476726513255747040765857479291291572334510643245094715007229621094194349783925984760375594985848253359305585439638442';
  47. $result = $math->rand($lower, $higher);
  48. $this->assertTrue(bccomp($result, $higher) !== '1');
  49. $this->assertTrue(bccomp($result, $lower) !== '-1');
  50. }
  51. }