1 package net.sourceforge.pmd.properties;
2
3 import net.sourceforge.pmd.PropertyDescriptor;
4 import net.sourceforge.pmd.lang.rule.properties.DoubleMultiProperty;
5 import net.sourceforge.pmd.lang.rule.properties.DoubleProperty;
6
7
8
9
10
11
12
13
14 public class DoublePropertyTest extends AbstractPropertyDescriptorTester {
15
16 private static final double MIN = -10.0;
17 private static final double MAX = 100.0;
18 private static final double SHIFT = 5.0;
19
20 public DoublePropertyTest() {
21 super();
22 }
23
24
25
26
27
28
29
30 protected Object createValue(int count) {
31
32 if (count == 1) return Double.valueOf(randomDouble(MIN, MAX));
33
34 Double[] values = new Double[count];
35 for (int i=0; i<values.length; i++) values[i] = (Double)createValue(1);
36 return values;
37 }
38
39
40
41
42
43
44
45 protected Object createBadValue(int count) {
46
47 if (count == 1) return Double.valueOf(
48 randomBool() ?
49 randomDouble(MIN - SHIFT, MIN - 0.01) :
50 randomDouble(MAX + 0.01, MAX + SHIFT)
51 );
52
53 Double[] values = new Double[count];
54 for (int i=0; i<values.length; i++) values[i] = (Double)createBadValue(1);
55 return values;
56 }
57
58
59
60
61
62
63
64 protected PropertyDescriptor createProperty(boolean multiValue) {
65
66 return multiValue ?
67 new DoubleMultiProperty("testDouble", "Test double property", MIN, MAX, new Double[] {-1d,0d,1d,2d}, 1.0f) :
68 new DoubleProperty("testDouble", "Test double property", MIN, MAX, 9.0, 1.0f);
69 }
70
71
72
73
74
75
76
77 protected PropertyDescriptor createBadProperty(boolean multiValue) {
78
79 return multiValue ?
80 new DoubleMultiProperty("testDouble", "Test double property", MIN, MAX, new Double[] {MIN-SHIFT,MIN,MIN+SHIFT,MAX+SHIFT}, 1.0f) :
81 new DoubleProperty("testDouble", "Test double property", MAX, MIN, 9.0, 1.0f) ;
82 }
83
84 public static junit.framework.Test suite() {
85 return new junit.framework.JUnit4TestAdapter(DoublePropertyTest.class);
86 }
87 }