RandomTest.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace Tools\Test\TestCase\Utility;
  3. use Shim\TestSuite\TestCase;
  4. use Tools\Utility\Random;
  5. class RandomTest extends TestCase {
  6. /**
  7. * @return void
  8. */
  9. public function testInt() {
  10. $is = Random::int(2, 200);
  11. //pr($is);
  12. $this->assertTrue($is >= 2 && $is <= 200);
  13. }
  14. /**
  15. * @return void
  16. */
  17. public function testArrayValue() {
  18. $array = [
  19. 'x',
  20. 'y',
  21. 'z',
  22. ];
  23. $is = Random::arrayValue($array, null, null, true);
  24. $this->assertTrue(in_array($is, $array));
  25. // non-numerical indexes
  26. $array = [
  27. 'e' => 'x',
  28. 'f' => 'y',
  29. 'g' => 'z',
  30. ];
  31. $is = Random::arrayValue($array);
  32. $this->assertTrue(in_array($is, $array));
  33. }
  34. /**
  35. * @return void
  36. */
  37. public function testPwd() {
  38. $result = Random::pwd(10);
  39. $this->assertTrue(mb_strlen($result) === 10);
  40. }
  41. /**
  42. * @return void
  43. */
  44. public function testPronounceablePwd() {
  45. $is = Random::pronounceablePwd(6);
  46. //pr($is);
  47. $this->assertTrue(strlen($is) === 6);
  48. $is = Random::pronounceablePwd(11);
  49. //pr($is);
  50. $this->assertTrue(strlen($is) === 11);
  51. }
  52. }