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