Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SearchableBaseNoteFragmentTest.java « fragment « android « notes « owncloud « niedermann « it « java « test « src « app - github.com/stefan-niedermann/nextcloud-notes.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f63923b6ea46c6aa38c3f1ed3f4bb6814d033820 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package it.niedermann.owncloud.notes.android.fragment;

import android.util.Log;

import org.junit.Test;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Random;

import static org.junit.Assert.*;

public class SearchableBaseNoteFragmentTest {

    @Test
    public void testCountOccurrencesFixed() {
        try {
            Method method = SearchableBaseNoteFragment.class.getDeclaredMethod("countOccurrences", String.class, String.class);
            method.setAccessible(true);

            for (int count = 0; count <= 15; ++count) {
                StringBuilder sb = new StringBuilder("Mike Chester Wang");
                for (int i = 0; i < count; ++i) {
                    sb.append(sb);
                }

                long startTime = System.currentTimeMillis();
                int num = (int) method.invoke(null, sb.toString(), "Chester");
                long endTime = System.currentTimeMillis();
                System.out.println("Fixed Version");
                System.out.println("Total Time: " + (endTime - startTime) + " ms");
                System.out.println("Total Times: " + num);
                System.out.println("String Size: " + (sb.length() / 1024.0) + " K");
                assertEquals((int) Math.pow(2, count), num);
                System.out.println();
            }

        } catch (Exception e) {
            fail(Arrays.toString(e.getStackTrace()));
            System.out.println("Test Count Occurrences Fixed" + Arrays.toString(e.getStackTrace()));
        }
    }

    @Test
    public void testNullOrEmptyInput() {
        try {
            Method method = SearchableBaseNoteFragment.class.getDeclaredMethod("countOccurrences", String.class, String.class);
            method.setAccessible(true);

            int num;
            num = (int) method.invoke(null, null, "Hi");
            assertEquals(0, num);
            num = (int) method.invoke(null, "Hi my name is Mike Chester Wang", null);
            assertEquals(0, num);
            num = (int) method.invoke(null, "", "Hi");
            assertEquals(0, num);
            num = (int) method.invoke(null, "Hi my name is Mike Chester Wang", "");
            assertEquals(0, num);

        } catch (Exception e) {
            fail(Arrays.toString(e.getStackTrace()));
            System.out.println("Test Null Or Empty Input" + Arrays.toString(e.getStackTrace()));
        }
    }
}