Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.7 KiB

  1. <?php
  2. /**
  3. * this file contains tests for the autoname function
  4. *
  5. * @package test.util
  6. */
  7. /** required, it is the file under test */
  8. require_once('include/text.php');
  9. /**
  10. * TestCase for the autoname function
  11. *
  12. * @author Alexander Kampmann
  13. * @package test.util
  14. */
  15. class AutonameTest extends PHPUnit_Framework_TestCase {
  16. /**
  17. *autonames should be random, even length
  18. */
  19. public function testAutonameEven() {
  20. $autoname1=autoname(10);
  21. $autoname2=autoname(10);
  22. $this->assertNotEquals($autoname1, $autoname2);
  23. }
  24. /**
  25. *autonames should be random, odd length
  26. */
  27. public function testAutonameOdd() {
  28. $autoname1=autoname(9);
  29. $autoname2=autoname(9);
  30. $this->assertNotEquals($autoname1, $autoname2);
  31. }
  32. /**
  33. * try to fail autonames
  34. */
  35. public function testAutonameNoLength() {
  36. $autoname1=autoname(0);
  37. $this->assertEquals(0, strlen($autoname1));
  38. }
  39. /**
  40. * try to fail it with invalid input
  41. *
  42. * TODO: What's corect behaviour here? An exception?
  43. */
  44. public function testAutonameNegativeLength() {
  45. $autoname1=autoname(-23);
  46. $this->assertEquals(0, strlen($autoname1));
  47. }
  48. // public function testAutonameMaxLength() {
  49. // $autoname2=autoname(PHP_INT_MAX);
  50. // $this->assertEquals(PHP_INT_MAX, count($autoname2));
  51. // }
  52. /**
  53. * test with a length, that may be too short
  54. */
  55. public function testAutonameLength1() {
  56. $autoname1=autoname(1);
  57. $this->assertEquals(1, count($autoname1));
  58. $autoname2=autoname(1);
  59. $this->assertEquals(1, count($autoname2));
  60. // The following test is problematic, with only 26 possibilities
  61. // generating the same thing twice happens often aka
  62. // birthday paradox
  63. // $this->assertFalse($autoname1==$autoname2);
  64. }
  65. }