|
34 | 34 | * @since 2.0 |
35 | 35 | */ |
36 | 36 | 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 | + |
37 | 39 | private void assertNotEmpty(BeiderMorseEncoder bmpm, final String value) throws EncoderException { |
38 | 40 | Assert.assertFalse(value, bmpm.encode(value).equals("")); |
39 | 41 | } |
@@ -164,23 +166,32 @@ public void testSetRuleTypeToRulesIllegalArgumentException() { |
164 | 166 |
|
165 | 167 | /** |
166 | 168 | * Runs between 1.1 and 13 seconds at length 40 for me (Gary Gregory, 2011/08/06) |
167 | | - * |
| 169 | + * |
168 | 170 | * @throws EncoderException |
169 | 171 | */ |
170 | 172 | @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(); |
174 | 175 | StringBuffer stringBuffer = new StringBuffer(); |
175 | 176 | 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)]); |
178 | 178 | for (int i = 0; i < 40; i++) { |
179 | | - start = System.currentTimeMillis(); |
180 | | - // System.out.println(i + " String to encode:" + stringBuffer.toString()); |
181 | 179 | 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]); |
184 | 195 | } |
185 | 196 | } |
186 | 197 | } |
0 commit comments