Imported Upstream version 1.1.0
[platform/upstream/iotivity.git] / service / simulator / unittests / SimulatorTest / src / org / oic / simulator / test / DoublePropertyTest.java
1 /*
2  * Copyright 2016 Samsung Electronics All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.oic.simulator.test;
18
19 import org.oic.simulator.AttributeValue;
20 import org.oic.simulator.DoubleProperty;
21
22 import junit.framework.TestCase;
23
24 public class DoublePropertyTest extends TestCase {
25
26     protected void setUp() throws Exception {
27         super.setUp();
28     }
29
30     protected void tearDown() throws Exception {
31         super.tearDown();
32     }
33
34     public void testDoubleProperty_P01() {
35         DoubleProperty property = new DoubleProperty.Builder().build();
36
37         assertNotNull(property);
38         assertEquals(property.getDefaultValue(), 0.0);
39     }
40
41     public void testIsDouble_P01() {
42         DoubleProperty property = new DoubleProperty.Builder().build();
43
44         assertNotNull(property);
45         assertTrue(property.isDouble());
46     }
47
48     public void testGetDefaultValue_P02() {
49         DoubleProperty.Builder builder = new DoubleProperty.Builder();
50         builder.setDefaultValue(3.142);
51
52         DoubleProperty property = builder.build();
53
54         assertNotNull(property);
55         assertEquals(property.getDefaultValue(), 3.142);
56     }
57
58     public void testHasRange_P01() {
59         DoubleProperty.Builder builder = new DoubleProperty.Builder();
60         builder.setRange(1.0, 10.25);
61
62         DoubleProperty property = builder.build();
63
64         assertNotNull(property);
65         assertTrue(property.hasRange());
66     }
67
68     public void testGetRange_P03() {
69         DoubleProperty.Builder builder = new DoubleProperty.Builder();
70         builder.setRange(1.0, 10.25);
71
72         DoubleProperty property = builder.build();
73
74         assertNotNull(property);
75         assertEquals(property.min(), 1.0);
76         assertEquals(property.max(), 10.25);
77     }
78
79     public void testHasValues_P01() {
80         DoubleProperty.Builder builder = new DoubleProperty.Builder();
81         double[] values = { 1.5, 2, 3.2 };
82         builder.setValues(values);
83
84         DoubleProperty property = builder.build();
85
86         assertNotNull(property);
87         assertTrue(property.hasValues());
88     }
89
90     public void testGetValues_P04() {
91         DoubleProperty.Builder builder = new DoubleProperty.Builder();
92         double[] values = { 1.5, 2, 3.2 };
93         builder.setValues(values);
94
95         DoubleProperty property = builder.build();
96
97         assertNotNull(property);
98         assertNotNull(property.getValues());
99         assertEquals(property.getValues().length, 3);
100     }
101
102     public void testValidate_P04() {
103         DoubleProperty.Builder builder = new DoubleProperty.Builder();
104         builder.setRange(1.0, 10.25);
105
106         DoubleProperty property = builder.build();
107
108         assertNotNull(property);
109         assertTrue(property.validate(new AttributeValue(3.25)));
110     }
111
112     public void testValidate_P05() {
113         DoubleProperty.Builder builder = new DoubleProperty.Builder();
114         builder.setRange(1.0, 10.25);
115
116         DoubleProperty property = builder.build();
117
118         assertNotNull(property);
119         assertTrue(property.validate(3.25));
120     }
121
122     public void testValidate_P06() {
123         DoubleProperty.Builder builder = new DoubleProperty.Builder();
124         double[] values = { 1.5, 2, 3.2 };
125         builder.setValues(values);
126
127         DoubleProperty property = builder.build();
128
129         assertNotNull(property);
130         assertTrue(property.validate(new AttributeValue(3.2)));
131     }
132
133     public void testValidate_P07() {
134         DoubleProperty.Builder builder = new DoubleProperty.Builder();
135         double[] values = { 1.5, 2, 3.2 };
136         builder.setValues(values);
137
138         DoubleProperty property = builder.build();
139
140         assertNotNull(property);
141         assertTrue(property.validate(3.2));
142     }
143
144     public void testValidate_N01() {
145         DoubleProperty.Builder builder = new DoubleProperty.Builder();
146         builder.setRange(1.0, 10.25);
147
148         DoubleProperty property = builder.build();
149
150         assertNotNull(property);
151         assertFalse(property.validate(new AttributeValue(11.5)));
152     }
153
154     public void testValidate_N02() {
155         DoubleProperty.Builder builder = new DoubleProperty.Builder();
156         builder.setRange(1.0, 10.25);
157
158         DoubleProperty property = builder.build();
159
160         assertNotNull(property);
161         assertFalse(property.validate(11.5));
162     }
163
164     public void testValidate_N04() {
165         DoubleProperty.Builder builder = new DoubleProperty.Builder();
166         double[] values = { 1.5, 2, 3.2 };
167         builder.setValues(values);
168
169         DoubleProperty property = builder.build();
170
171         assertNotNull(property);
172         assertFalse(property.validate(new AttributeValue(11.25)));
173     }
174
175     public void testValidate_N05() {
176         DoubleProperty.Builder builder = new DoubleProperty.Builder();
177         double[] values = { 1.5, 2, 3.2 };
178         builder.setValues(values);
179
180         DoubleProperty property = builder.build();
181
182         assertNotNull(property);
183         assertFalse(property.validate(11.25));
184     }
185 }