@@ -151,7 +151,43 @@ public function test_if_it_can_use_skip_callback()
151151 $ this ->assertEquals ('00 ' , $ hash );
152152 }
153153
154- public function test_if_it_fail_after_max_possible_combination_reached ()
154+ public function test_if_it_can_generate_not_unique_hashes ()
155+ {
156+ $ config = new HashConfig ();
157+ $ config ->length (2 )
158+ ->count (5 )
159+ ->notUnique ()
160+ ->charset ('01 ' )
161+ ->skip (function ($ hash ) {
162+ return in_array ($ hash , ['10 ' , '11 ' , '01 ' ]);
163+ });
164+
165+ $ instance = new RandomHash ($ config );
166+ $ hashes = $ instance ->generate ();
167+
168+ foreach ($ hashes as $ hash ) {
169+ $ this ->assertEquals ('00 ' , $ hash );
170+ }
171+ }
172+
173+ public function test_if_it_can_generate_unique_hashes ()
174+ {
175+ $ config = new HashConfig ();
176+ $ config ->length (2 )
177+ ->count (2 )
178+ ->unique ()
179+ ->charset ('01 ' )
180+ ->skip (function ($ hash ) {
181+ return in_array ($ hash , ['10 ' , '11 ' ]);
182+ });
183+
184+ $ instance = new RandomHash ($ config );
185+ $ hashes = $ instance ->generate ();
186+
187+ $ this ->assertEqualsCanonicalizing (['01 ' , '00 ' ], $ hashes );
188+ }
189+
190+ public function test_if_it_fails_after_max_possible_combination_reached ()
155191 {
156192 $ config = new HashConfig ();
157193 $ config ->length (2 )
@@ -166,6 +202,23 @@ public function test_if_it_fail_after_max_possible_combination_reached()
166202 $ instance ->generate ();
167203 }
168204
205+ public function test_if_it_fails_after_max_possible_combination_reached_using_unique ()
206+ {
207+ $ config = new HashConfig ();
208+ $ config ->length (2 )
209+ ->charset ('01 ' )
210+ ->count (3 )
211+ ->unique ()
212+ ->skip (function ($ hash ) {
213+ return in_array ($ hash , ['10 ' , '11 ' ]);
214+ });
215+
216+ $ instance = new RandomHash ($ config );
217+
218+ $ this ->expectException (InvalidConfigException::class);
219+ $ instance ->generate ();
220+ }
221+
169222 public function test_if_it_can_generate_hashes_from_array_config ()
170223 {
171224 $ prefix = 'TEST_ ' ;
0 commit comments