RandomTest.php 975 B

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