forked from processing/processing4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFloatListTest.java
More file actions
135 lines (103 loc) · 3.7 KB
/
FloatListTest.java
File metadata and controls
135 lines (103 loc) · 3.7 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package processing.data;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.*;
public class FloatListTest {
@Test
public void testConstructorDefault(){
FloatList testList = new FloatList();
assertEquals(0, testList.size());
assertEquals(10, testList.data.length);
}
@Test
public void testConstructorLength(){
FloatList testList = new FloatList(15);
assertEquals(0, testList.size());
assertEquals(15, testList.data.length);
}
@Test
public void testConstructorArray(){
FloatList testList = new FloatList(new float[] {1.1F, 2.2F, 3.3F});
assertEquals(3, testList.size());
assertEquals(3, testList.data.length);
assertEquals(1.1F, testList.get(0), 0.0F);
assertEquals(3.3F, testList.get(2), 0.0F);
}
@Test
public void testConstructorIterableObject(){
List<Object> src = new ArrayList<>(Arrays.asList("String", 9, 10.4F, 3.7, null));
FloatList testList = new FloatList(src);
assertEquals(5, testList.size());
float[] expected = {Float.NaN, 9.0F, 10.4F, 3.7F, Float.NaN};
assertEquals(expected[0], testList.get(0), 0.0F);
assertEquals(expected[1], testList.get(1), 0.0F);
assertEquals(expected[2], testList.get(2), 0.0F);
assertEquals(expected[3], testList.get(3), 0.0F);
}
@Test
public void testConstructorObject(){
String typeStr = "String";
int typeInt = 21;
float typeFlt = 4.5F;
Object typeObj = new Object();
FloatList testList = new FloatList(typeStr, typeInt, typeFlt, typeObj);
float[] expected = {Float.NaN, 21.0F, 4.5F, Float.NaN};
assertEquals(expected[0], testList.get(0), 0.0F);
assertEquals(expected[1], testList.get(1), 0.0F);
assertEquals(expected[2], testList.get(2), 0.0F);
assertEquals(expected[3], testList.get(3), 0.0F);
}
@Test
public void testSize(){
FloatList testList = new FloatList(new float[]{1.1F, 2.2F, 3.3F});
assertEquals(3, testList.size());
}
@Test
public void testResize(){
FloatList testList = new FloatList(new float[]{3.3F, 4.4F, 5.5F});
assertEquals(3, testList.size());
testList.resize(10);
assertEquals(10, testList.size());
assertEquals(10, testList.data.length);
}
@Test
public void testClear(){
FloatList testList = new FloatList(new float[]{45.8F, 5.6F, 9.8F});
assertEquals(3, testList.size());
testList.clear();
assertEquals(0, testList.size());
}
@Test
public void testGet(){
FloatList testList = new FloatList(new float[]{4.5F, 7.8F});
assertEquals(4.5F, testList.get(0), 0.0F);
assertEquals(7.8F, testList.get(1), 0.0F);
}
@Test
public void testSet(){
FloatList testList = new FloatList();
testList.set(0, 18.0F);
assertEquals(1, testList.size());
assertEquals(18.0F, testList.get(0), 0.0F);
testList.set(500, 4.9F);
assertEquals(501, testList.size());
assertEquals(4.9F, testList.get(500), 0.0F);
}
@Test
public void testPush(){
FloatList testList = new FloatList();
testList.push(34.0F);
assertEquals(1, testList.size());
assertEquals(34.0F, testList.get(0), 0.0F);
}
@Test
public void testPop(){
FloatList testList = new FloatList(new float[]{6.0F, 7.0F});
assertEquals(7.0F, testList.pop(), 0.0F);
assertEquals(1, testList.size());
assertEquals(6.0F, testList.pop(), 0.0F);
assertEquals(0, testList.size());
}
}