@@ -34,6 +34,75 @@ public static function provideGenerateInt() {
3434 );
3535 }
3636
37+ public function provideGenerateString () {
38+ return array (
39+ array (
40+ 1 ,
41+ 1 ,
42+ "01 " ,
43+ function ($ j ) {
44+ return str_pad (decbin ($ j ), 1 , '0 ' , STR_PAD_LEFT );
45+ }
46+ ),
47+ array (
48+ 2 ,
49+ 3 ,
50+ "01 " ,
51+ function ($ j ) {
52+ return str_pad (decbin ($ j ), 2 , '0 ' , STR_PAD_LEFT );
53+ }
54+ ),
55+ array (
56+ 3 ,
57+ 7 ,
58+ "01 " ,
59+ function ($ j ) {
60+ return str_pad (decbin ($ j ), 3 , '0 ' , STR_PAD_LEFT );
61+ }
62+ ),
63+ array (
64+ 8 ,
65+ 255 ,
66+ "01 " ,
67+ function ($ j ) {
68+ return str_pad (decbin ($ j ), 8 , '0 ' , STR_PAD_LEFT );
69+ }
70+ ),
71+ array (
72+ 16 ,
73+ 255 ,
74+ "01 " ,
75+ function ($ j ) {
76+ return str_pad (decbin ($ j ), 16 , '0 ' , STR_PAD_LEFT );
77+ }
78+ ),
79+ array (
80+ 1 ,
81+ 15 ,
82+ "0123456789abcdef " ,
83+ function ($ j ) {
84+ return str_pad (dechex ($ j ), 1 , '0 ' , STR_PAD_LEFT );
85+ }
86+ ),
87+ array (
88+ 2 ,
89+ 255 ,
90+ "0123456789abcdef " ,
91+ function ($ j ) {
92+ return str_pad (dechex ($ j ), 2 , '0 ' , STR_PAD_LEFT );
93+ }
94+ ),
95+ array (
96+ 3 ,
97+ 300 ,
98+ "0123456789abcdef " ,
99+ function ($ j ) {
100+ return str_pad (dechex ($ j ), 3 , '0 ' , STR_PAD_LEFT );
101+ }
102+ ),
103+ );
104+ }
105+
37106 /**
38107 * This test asserts that the algorithm that generates the integers does not
39108 * actually introduce any bias into the generated numbers. If this test
@@ -49,6 +118,21 @@ public function testGenerateInt($min, $max, $offset = 0) {
49118 }
50119 }
51120
121+ /**
122+ * This test asserts that the algorithm that generates the strings does not
123+ * actually introduce any bias into the generated numbers. If this test
124+ * passes, the generated strings from the generator will be as unbiased as
125+ * the sources that provide the data.
126+ *
127+ * @dataProvider provideGenerateString
128+ */
129+ public function testGenerateString ($ length , $ max , $ chrs , $ func ) {
130+ $ generator = $ this ->getGenerator ($ max );
131+ for ($ i = $ max ; $ i >= 0 ; $ i --) {
132+ $ this ->assertEquals ($ func ($ i ), $ generator ->generateString ($ length , $ chrs ));
133+ }
134+ }
135+
52136 public function getGenerator ($ random ) {
53137 $ source1 = new Source (array (
54138 'generate ' => function ($ size ) use (&$ random ) {
0 commit comments