Skip to content

Commit 0c0c692

Browse files
committed
Renamed testSpeedCheck to testSpeedCheckRandom. Made testSpeedCheck deterministic.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@1155027 13f79535-47bb-0310-9956-ffa450edef68
1 parent 5214caa commit 0c0c692

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

src/test/org/apache/commons/codec/language/bm/BeiderMorseEncoderTest.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
* @since 2.0
3535
*/
3636
public class BeiderMorseEncoderTest extends StringEncoderAbstractTest {
37+
private static final char[] TEST_CHARS = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'o', 'u' };
38+
3739
private void assertNotEmpty(BeiderMorseEncoder bmpm, final String value) throws EncoderException {
3840
Assert.assertFalse(value, bmpm.encode(value).equals(""));
3941
}
@@ -164,23 +166,32 @@ public void testSetRuleTypeToRulesIllegalArgumentException() {
164166

165167
/**
166168
* Runs between 1.1 and 13 seconds at length 40 for me (Gary Gregory, 2011/08/06)
167-
*
169+
*
168170
* @throws EncoderException
169171
*/
170172
@Test(/* timeout = 20000L */)
171-
public void testSpeedCheck() throws EncoderException {
172-
char[] chars = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'o', 'u' };
173-
BeiderMorseEncoder bmpm = createGenericApproxEncoder();
173+
public void testSpeedCheckRandom() throws EncoderException {
174+
BeiderMorseEncoder bmpm = this.createGenericApproxEncoder();
174175
StringBuffer stringBuffer = new StringBuffer();
175176
Random rand = new Random();
176-
stringBuffer.append(chars[rand.nextInt(chars.length)]);
177-
long start;
177+
stringBuffer.append(TEST_CHARS[rand.nextInt(TEST_CHARS.length)]);
178178
for (int i = 0; i < 40; i++) {
179-
start = System.currentTimeMillis();
180-
// System.out.println(i + " String to encode:" + stringBuffer.toString());
181179
bmpm.encode(stringBuffer.toString());
182-
stringBuffer.append(chars[rand.nextInt(chars.length)]);
183-
// System.out.println(i + " Elapsed time in ms:" + (System.currentTimeMillis() - start));
180+
stringBuffer.append(TEST_CHARS[rand.nextInt(TEST_CHARS.length)]);
181+
}
182+
}
183+
184+
@Test(/* timeout = 20000L */)
185+
public void testSpeedCheck() throws EncoderException {
186+
BeiderMorseEncoder bmpm = this.createGenericApproxEncoder();
187+
StringBuffer stringBuffer = new StringBuffer();
188+
stringBuffer.append(TEST_CHARS[0]);
189+
for (int i = 0, j = 1; i < 40; i++, j++) {
190+
if (j == TEST_CHARS.length) {
191+
j = 0;
192+
}
193+
bmpm.encode(stringBuffer.toString());
194+
stringBuffer.append(TEST_CHARS[j]);
184195
}
185196
}
186197
}

0 commit comments

Comments
 (0)