@@ -93,12 +93,17 @@ private void validateDiffCollection(List<String> before, List<String> after) {
93
93
@ Test
94
94
public void compareUtf8StringsShouldReturnCorrectValue () {
95
95
ArrayList <String > errors = new ArrayList <>();
96
- int seed = new Random ().nextInt ();
96
+ int seed = new Random ().nextInt (Integer . MAX_VALUE );
97
97
int passCount = 0 ;
98
- StringGenerator stringGenerator = new StringGenerator (seed );
98
+ StringGenerator stringGenerator = new StringGenerator (29750468 );
99
+ StringPairGenerator stringPairGenerator = new StringPairGenerator (stringGenerator );
99
100
for (int i = 0 ; i < 1_000_000 && errors .size () < 10 ; i ++) {
100
- String s1 = stringGenerator .next ();
101
- String s2 = stringGenerator .next ();
101
+ final String s1 , s2 ;
102
+ {
103
+ StringPairGenerator .StringPair stringPair = stringPairGenerator .next ();
104
+ s1 = stringPair .s1 ;
105
+ s2 = stringPair .s2 ;
106
+ }
102
107
103
108
int actual = Util .compareUtf8Strings (s1 , s2 );
104
109
@@ -140,6 +145,31 @@ public void compareUtf8StringsShouldReturnCorrectValue() {
140
145
}
141
146
}
142
147
148
+ private static class StringPairGenerator {
149
+
150
+ private final StringGenerator stringGenerator ;
151
+
152
+ public StringPairGenerator (StringGenerator stringGenerator ) {
153
+ this .stringGenerator = stringGenerator ;
154
+ }
155
+
156
+ public StringPair next () {
157
+ String prefix = stringGenerator .next ();
158
+ String s1 = prefix + stringGenerator .next ();
159
+ String s2 = prefix + stringGenerator .next ();
160
+ return new StringPair (s1 , s2 );
161
+ }
162
+
163
+ public static class StringPair {
164
+ public final String s1 , s2 ;
165
+
166
+ public StringPair (String s1 , String s2 ) {
167
+ this .s1 = s1 ;
168
+ this .s2 = s2 ;
169
+ }
170
+ }
171
+ }
172
+
143
173
private static class StringGenerator {
144
174
145
175
private static final float DEFAULT_SURROGATE_PAIR_PROBABILITY = 0.33f ;
@@ -214,7 +244,8 @@ public String next() {
214
244
final int length = rnd .nextInt (maxLength + 1 );
215
245
final StringBuilder sb = new StringBuilder ();
216
246
while (sb .length () < length ) {
217
- sb .appendCodePoint (nextCodePoint ());
247
+ int codePoint = nextCodePoint ();
248
+ sb .appendCodePoint (codePoint );
218
249
}
219
250
return sb .toString ();
220
251
}
0 commit comments