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 package org.perfidix.element;
28
29 import static org.junit.Assert.assertFalse;
30 import static org.junit.Assert.fail;
31
32 import java.lang.reflect.Method;
33 import java.util.ArrayList;
34 import java.util.Iterator;
35 import java.util.List;
36
37 import org.junit.Before;
38 import org.junit.Test;
39 import org.perfidix.annotation.Bench;
40
41
42
43
44
45
46 public class ShuffleMethodArrangementTest {
47
48 private transient List<BenchmarkElement> elemSet;
49
50
51
52
53 @Before
54 public void setUp() {
55 elemSet = new ArrayList<BenchmarkElement>();
56 final Class<?> testClazz = TestBenchClass.class;
57 for (final Method meth : testClazz.getDeclaredMethods()) {
58 if (BenchmarkMethod.isBenchmarkable(meth)) {
59 elemSet.add(new BenchmarkElement(new BenchmarkMethod(meth)));
60 }
61 }
62 }
63
64
65
66
67 @Test
68 public void test() {
69 try {
70
71 final AbstractMethodArrangement arrangement =
72 AbstractMethodArrangement.getMethodArrangement(elemSet, KindOfArrangement.ShuffleArrangement);
73 final String[] expectedNames = {
74 "bench1", "bench2", "bench4"
75 };
76 final Iterator<BenchmarkElement> iterBench = arrangement.iterator();
77 final BenchmarkElement elem1 = iterBench.next();
78 final BenchmarkElement elem2 = iterBench.next();
79 final BenchmarkElement elem3 = iterBench.next();
80 if ((expectedNames[0].equals(elem1.getMeth().getMethodToBench().getName()))
81 && (expectedNames[1].equals(elem2.getMeth().getMethodToBench().getName()))
82 && (expectedNames[2].equals(elem3.getMeth().getMethodToBench().getName()))) {
83 fail("Something has to be arranged in a different way!");
84
85 }
86 assertFalse("No more elements should be left", iterBench.hasNext());
87
88 } catch (final Exception e) {
89 fail(e.toString());
90 }
91 }
92
93 class TestBenchClass {
94
95 @Bench
96 public void bench1() {
97
98 }
99
100 @Bench
101 public void bench2() {
102
103 }
104
105 public void bench3() {
106
107 }
108
109 @Bench
110 public void bench4() {
111
112 }
113
114 }
115
116 }