Remove random

This commit is contained in:
Isc 2020-05-11 14:40:17 +08:00
parent 916a5fef7b
commit 29d23f4d9d

View file

@ -45,41 +45,41 @@ public class SearchableBaseNoteFragmentTest {
} }
} }
@Test // @Test
public void testCountOccurrencesRandom() { // public void testCountOccurrencesRandom() {
try { // try {
Method method = SearchableBaseNoteFragment.class.getDeclaredMethod("countOccurrences", String.class, String.class); // Method method = SearchableBaseNoteFragment.class.getDeclaredMethod("countOccurrences", String.class, String.class);
method.setAccessible(true); // method.setAccessible(true);
//
for (int count = 10; count <= 15; ++count) { // for (int count = 10; count <= 15; ++count) {
StringBuilder sb = new StringBuilder("Mike Chester Wang"); // StringBuilder sb = new StringBuilder("Mike Chester Wang");
Random rand = new Random(); // Random rand = new Random();
for (int i = 0; i < count * 100; ++i) { // for (int i = 0; i < count * 100; ++i) {
sb.append(rand.nextDouble()); // sb.append(rand.nextDouble());
if (i % 100 == 0) { // if (i % 100 == 0) {
sb.append("flag"); // sb.append("flag");
} // }
} // }
//
long startTime = System.currentTimeMillis(); // long startTime = System.currentTimeMillis();
int num = (int) method.invoke(null, sb.toString(), String.valueOf(rand.nextInt(100))); // int num = (int) method.invoke(null, sb.toString(), String.valueOf(rand.nextInt(100)));
long endTime = System.currentTimeMillis(); // long endTime = System.currentTimeMillis();
System.out.println("Random Version"); // System.out.println("Random Version");
System.out.println("Total Time: " + (endTime - startTime) + " ms"); // System.out.println("Total Time: " + (endTime - startTime) + " ms");
System.out.println("Total Times: " + num); // System.out.println("Total Times: " + num);
System.out.println("String Size: " + (sb.length() / 1024) + " K"); // System.out.println("String Size: " + (sb.length() / 1024) + " K");
System.out.println(); // System.out.println();
//
if (endTime - startTime > 10) { // if (endTime - startTime > 10) {
fail("The algorithm spends too much time."); // fail("The algorithm spends too much time.");
} // }
} // }
//
} catch (Exception e) { // } catch (Exception e) {
fail(Arrays.toString(e.getStackTrace())); // fail(Arrays.toString(e.getStackTrace()));
Log.e("Test Count Occurrences Random", Arrays.toString(e.getStackTrace())); // Log.e("Test Count Occurrences Random", Arrays.toString(e.getStackTrace()));
} // }
} // }
@Test @Test
public void testNullOrEmptyInput() { public void testNullOrEmptyInput() {