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