-
-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathDoubleListTest.java
More file actions
87 lines (70 loc) · 2.76 KB
/
Copy pathDoubleListTest.java
File metadata and controls
87 lines (70 loc) · 2.76 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package processing.data;
import junit.framework.TestCase;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static java.lang.Double.NaN;
import static org.junit.Assert.*;
public class DoubleListTest{
@Test
public void testDefaultConstructor() {
// 10 is the default value in DoubleList
DoubleList testedList = new DoubleList();
assertEquals(0, testedList.size());
assertEquals(10, testedList.data.length);
}
@Test
public void testConstructorWithLength() {
DoubleList testedList = new DoubleList(20);
assertEquals(0, testedList.size());
assertEquals(20, testedList.data.length);
}
@Test
public void testConstructorWithArray() {
double[] source = {1.0, 2.0};
DoubleList testedList = new DoubleList(source);
assertEquals(2, testedList.size());
assertEquals(2, testedList.data.length);
assertEquals(1, testedList.get(0),0);
assertEquals(2, testedList.get(1),0);
}
@Test
public void testConstructorWithEmptyArray() {
double[] source = {};
DoubleList testedList = new DoubleList(source);
assertEquals(0, testedList.size());
assertEquals(0, testedList.data.length);
}
@Test
public void testConstructorWithIterableObject() {
List<Object> source = new ArrayList<>(Arrays.asList("1.1", "test", null, 4.5, -1));
DoubleList testedList = new DoubleList(source);
assertEquals(5, testedList.size());
double[] expected = {1.1, NaN, NaN, 4.5, -1};
assertEquals(expected[0], testedList.get(0), 1e-7);
assertEquals(expected[1], testedList.get(1), 0);
assertTrue(Double.isNaN(testedList.get(1)));
assertEquals(expected[2], testedList.get(2), 0);
assertTrue(Double.isNaN(testedList.get(2)));
assertEquals(expected[3], testedList.get(3), 0);
assertEquals(expected[4], testedList.get(4), 0);
assertArrayEquals(expected, testedList.values(), 1e-7);
}
@Test
public void testConstructorWithObject() {
String eleStr = "Hello";
double eleDouble = 10.0;
float eleFloat = 1.2f;
Object eleObj = new Object();
DoubleList testedList = new DoubleList(eleStr, eleDouble, eleFloat, eleObj);
double[] expected = {NaN, 10.0, 1.2, NaN};
assertEquals(expected[0], testedList.get(0), 0);
assertTrue(Double.isNaN(testedList.get(0)));
assertEquals(expected[1], testedList.get(1), 0);
assertEquals(expected[2], testedList.get(2), 1e-7);
assertEquals(expected[3], testedList.get(3), 0);
assertTrue(Double.isNaN(testedList.get(3)));
assertArrayEquals(expected, testedList.values(),1e-7);
}
}