1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.objects.classes; |
21 |
|
|
22 |
|
import java.util.Random; |
23 |
|
|
24 |
|
import org.junit.Assert; |
25 |
|
import org.junit.Test; |
26 |
|
|
27 |
|
|
28 |
|
@link |
29 |
|
|
30 |
|
@version |
31 |
|
@since |
32 |
|
|
|
|
| 88% |
Uncovered Elements: 3 (25) |
Complexity: 3 |
Complexity Density: 0.15 |
|
33 |
|
public class PropertyClassTest |
34 |
|
{ |
35 |
|
@link |
|
|
| 87.5% |
Uncovered Elements: 3 (24) |
Complexity: 3 |
Complexity Density: 0.15 |
1PASS
|
|
36 |
1 |
@Test... |
37 |
|
public void testCompareTo() |
38 |
|
{ |
39 |
1 |
PropertyClass one = new PropertyClass(); |
40 |
1 |
PropertyClass two = new PropertyClass(); |
41 |
|
|
42 |
1 |
int n1, n2; |
43 |
|
|
44 |
1 |
one.setName("first"); |
45 |
1 |
two.setName("second"); |
46 |
|
|
47 |
|
|
48 |
1 |
Random random = new Random(); |
49 |
21 |
for (int i = 0; i < 20; ++i) { |
50 |
20 |
n1 = random.nextInt(); |
51 |
20 |
n2 = random.nextInt(); |
52 |
20 |
one.setNumber(n1); |
53 |
20 |
two.setNumber(n2); |
54 |
|
|
55 |
20 |
if (n1 == n2) { |
56 |
0 |
Assert.assertEquals(Math.signum(one.compareTo(two)), -1.0, 0); |
57 |
0 |
Assert.assertEquals(Math.signum(two.compareTo(one)), 1.0, 0); |
58 |
|
} else { |
59 |
20 |
Assert.assertEquals(0, Float.compare(Math.signum(one.compareTo(two)), Math.signum(n1 - n2))); |
60 |
20 |
Assert.assertEquals(0, Float.compare(Math.signum(two.compareTo(one)), Math.signum(n2 - n1))); |
61 |
|
} |
62 |
|
} |
63 |
|
|
64 |
|
|
65 |
1 |
one.setNumber(42); |
66 |
1 |
two.setNumber(42); |
67 |
1 |
Assert.assertEquals(Math.signum(one.compareTo(two)), -1.0, 0); |
68 |
1 |
Assert.assertEquals(Math.signum(two.compareTo(one)), 1.0, 0); |
69 |
|
} |
70 |
|
} |