-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTychoTest.java
More file actions
246 lines (166 loc) · 9.68 KB
/
TychoTest.java
File metadata and controls
246 lines (166 loc) · 9.68 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
package edu.easternct.bigdata;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.spark.api.java.JavaPairRDD;
import org.apache.spark.api.java.JavaRDD;
import org.junit.Test;
import com.holdenkarau.spark.testing.JavaRDDComparisons;
import com.holdenkarau.spark.testing.SharedJavaSparkContext;
import edu.easternct.bigdata.*;
import scala.Option;
import scala.Serializable;
import scala.Tuple2;
import java.math.BigDecimal;
import java.math.MathContext;
import scala.reflect.ClassTag;
import org.junit.Test;
public class TychoTest extends SharedJavaSparkContext {
/**
*
*/
@Test
public void verifyValidStars() {
// Create and run the test
System.out.println("Verify Valid Stars");
JavaRDD<String> inputRDD = jsc().textFile("/home/training/training_materials/Spark/data/tyc2.test.dat/tyc2.dat.00");
JavaRDD<Star> result = TychoAnalysis4.findValidStars(inputRDD);
System.out.println("Input Count: " +result.count());
// Create the expected output
Star temp1 = new Star("0001 00008 1", " ",2.31750494,2.23184345,new BigDecimal("12.146",new MathContext(5)),new BigDecimal("12.146",new MathContext(5)), " ");
Star temp2 = new Star("0001 00013 1", " ",1.12558209,2.267394,new BigDecimal(10.488,new MathContext(5)),new BigDecimal(8.67,new MathContext(5))," ");
Star temp3 = new Star("0001 00016 1", " ",1.0568649,1.8978287,new BigDecimal(12.921,new MathContext(5)),new BigDecimal(12.10,new MathContext(5))," ");
Star temp6 = new Star("0001 00020 1", " ",0.37220148,2.48018803,new BigDecimal(12.193,new MathContext(5)),new BigDecimal(11.398,new MathContext(5))," ");
Star temp7 = new Star("0001 00022 1", " ",1.02766471,1.45849152,new BigDecimal(12.682,new MathContext(5)),new BigDecimal(12.289,new MathContext(5))," ");
Star temp8 = new Star("0001 00024 1", " ",0.77431739,1.71059531,new BigDecimal(12.537,new MathContext(5)),new BigDecimal(11.697,new MathContext(5))," ");
Star temp9 = new Star("0001 00036 1", " ",0.29838646,1.92361761,new BigDecimal(11.672,new MathContext(5)),new BigDecimal(11.648,new MathContext(5))," ");
Star temp10 = new Star("0001 00039 1", " ",2.37141849,2.30400355,new BigDecimal(9.51,new MathContext(5)),new BigDecimal(9.387,new MathContext(5))," ");
List<Star> expectedInput = Arrays.asList(temp1, temp2, temp3, temp6, temp7, temp8, temp9, temp10);
expectedInput.forEach(s -> {s.setRaBin(); s.setBMinV();});
JavaRDD<Star> expectedRDD = jsc().parallelize(expectedInput);
System.out.println("Spark Generated data: " +result.count());
result.foreach(System.out::println);
System.out.println("Expected Generated data: " +expectedRDD.count());
expectedRDD.foreach(System.out::println);
ClassTag<Star> tag =
scala.reflect.ClassTag$.MODULE$
.apply(Star.class);
// Run the assertions on the result and expected
JavaRDDComparisons.assertRDDEquals(
JavaRDD.fromRDD(JavaRDD.toRDD(result), tag),
JavaRDD.fromRDD(JavaRDD.toRDD(expectedRDD), tag));
}
@Test
public void verifyBinStarCount() {
System.out.println("Verify Bin Star Count");
// Create and run the test
JavaRDD<String> inputRDD = jsc().textFile("/home/training/training_materials/Spark/data/tyc2.test.dat/tyc2.dat.00");
JavaRDD<Star> result = TychoAnalysis4.findValidStars(inputRDD);
JavaPairRDD<Integer, Integer> binStarCounts = TychoAnalysis4.computeBinStarCounts(result);
// Create the expected output
Tuple2<Integer, Integer> temp1 = new Tuple2<Integer, Integer>(1, 3);
Tuple2<Integer, Integer> temp2 = new Tuple2<Integer, Integer>(2, 3);
Tuple2<Integer, Integer> temp3 = new Tuple2<Integer, Integer>(3, 2);
// RaBin temp2 = new RaBin(2, 3, 2.57720000);
// RaBin temp3 = new RaBin(3, 3, 0.10455000);
List<Tuple2<Integer, Integer>> expectedInput = Arrays.asList(temp1, temp2, temp3);
JavaPairRDD<Integer, Integer> expectedRDD = jsc().parallelizePairs(expectedInput);
System.out.println("Spark Generated data: " +binStarCounts.count());
binStarCounts.foreach(System.out::println);
System.out.println("Expected Generated data: " +expectedRDD.count());
expectedRDD.foreach(System.out::println);
ClassTag<Tuple2<Integer, Integer>> tag =
scala.reflect.ClassTag$.MODULE$
.apply(Tuple2.class);
// Run the assertions on the result and expected
JavaRDDComparisons.assertRDDEquals(
JavaRDD.fromRDD(JavaPairRDD.toRDD(binStarCounts), tag),
JavaRDD.fromRDD(JavaPairRDD.toRDD(expectedRDD), tag));
}
@Test
public void verifyBinColorIndexes() {
System.out.println("Verify Bin Color Indexes");
// Create and run the test
JavaRDD<String> inputRDD = jsc().textFile("/home/training/training_materials/Spark/data/tyc2.test.dat/tyc2.dat.00");
JavaRDD<Star> result = TychoAnalysis4.findValidStars(inputRDD);
JavaPairRDD<Integer, BigDecimal> starColorIndexes = TychoAnalysis4.getColorIndexDetails(result);
JavaPairRDD<Integer, BigDecimal> binColorIndexes = TychoAnalysis4.computeTotalColorIndex(starColorIndexes);
// Create the expected output
Tuple2<Integer, BigDecimal> temp1 = new Tuple2<>(1, new BigDecimal("1.410150",new MathContext(6)));
Tuple2<Integer, BigDecimal> temp2 = new Tuple2<>(2, new BigDecimal("2.577200",new MathContext(6)));
Tuple2<Integer, BigDecimal> temp3 = new Tuple2<>(3, new BigDecimal("0.104550",new MathContext(6)));
List<Tuple2<Integer, BigDecimal>> expectedInput = Arrays.asList(temp1, temp2, temp3);
JavaPairRDD<Integer, BigDecimal> expectedRDD = jsc().parallelizePairs(expectedInput);
System.out.println("Spark Generated data: " +binColorIndexes.count());
binColorIndexes.foreach(System.out::println);
System.out.println("Expected Generated data: " +expectedRDD.count());
expectedRDD.foreach(System.out::println);
ClassTag<Tuple2<Integer, BigDecimal>> tag =
scala.reflect.ClassTag$.MODULE$
.apply(Tuple2.class);
// Run the assertions on the result and expected
JavaRDDComparisons.assertRDDEquals(
JavaRDD.fromRDD(JavaPairRDD.toRDD(binColorIndexes), tag),
JavaRDD.fromRDD(JavaPairRDD.toRDD(expectedRDD), tag));
}
@Test
public void verifyRaBinCreation() {
System.out.println("Verify RA Bin Creation");
// Create and run the test
JavaRDD<String> inputRDD = jsc().textFile("/home/training/training_materials/Spark/data/tyc2.test.dat/tyc2.dat.00");
JavaRDD<Star> result = TychoAnalysis4.findValidStars(inputRDD);
JavaPairRDD<Integer, Integer> binStarCounts = TychoAnalysis4.computeBinStarCounts(result);
JavaPairRDD<Integer, BigDecimal> starColorIndexes = TychoAnalysis4.getColorIndexDetails(result);
JavaPairRDD<Integer, BigDecimal> binColorIndexes = TychoAnalysis4.computeTotalColorIndex(starColorIndexes);
JavaPairRDD<Integer, RaBin> binStats = TychoAnalysis4.groupAndCollect(starColorIndexes);
JavaRDD<RaBin> outputRDD = TychoAnalysis4.createBins(binStarCounts, binColorIndexes,binStats);
System.out.println("Got this far #1: " +outputRDD.count());
// Create the expected output
RaBin temp1 = new RaBin(1, 3, new BigDecimal("1.410150"));
RaBin temp2 = new RaBin(2, 3, new BigDecimal("2.5772"));
RaBin temp3 = new RaBin(3, 2, new BigDecimal("0.104550"));
List<RaBin> expectedInput = Arrays.asList(temp1, temp2, temp3);
System.out.println("Got this far #2: " +expectedInput.size());
JavaRDD<RaBin> expectedRDD = jsc().parallelize(expectedInput);
System.out.println("Got this far #3: " +expectedRDD.count());
System.out.println("Spark Generated data: " +outputRDD.count());
outputRDD.foreach((RaBin r) -> System.out.println(r.toFormattedString()));
System.out.println("Expected Generated data: " +expectedRDD.count());
expectedRDD.foreach((RaBin r) -> System.out.println(r.toFormattedString()));
ClassTag<RaBin> tag =
scala.reflect.ClassTag$.MODULE$
.apply(RaBin.class);
// Run the assertions on the result and expected
JavaRDDComparisons.assertRDDEquals(
JavaRDD.fromRDD(JavaRDD.toRDD(outputRDD), tag),
JavaRDD.fromRDD(JavaRDD.toRDD(expectedRDD), tag));
}
@Test
public void verifyCollectStats() {
System.out.println("Verify Collect Stats");
// Create and run the test
BigDecimal data1 = new BigDecimal("100.50");
BigDecimal data2 = new BigDecimal("50.50");
BigDecimal data3 = new BigDecimal("1");
BigDecimal data4 = new BigDecimal("175.00");
BigDecimal data5 = new BigDecimal("40.00");
List<BigDecimal> input = new ArrayList<>();
input.add(data1);
input.add(data2);
input.add(data3);
input.add(data4);
input.add(data5);
List<Double> results = TychoAnalysis4.collectStats(1, input);
// Create the expected output
StringBuffer expected = new StringBuffer();
expected.append("limited Entires length: 3/n");
expected.append("RaBin : 1 Mean : 180.517 Minimum : 180.517 Maximum : 180.517 Median : 180.517 Standard Deviation : 0.0/n");
assert(results.get(0).equals(new Double(91.75))); //mean
assert(results.get(1).equals(new Double(50.50))); //median
assert(results.get(2).equals(new Double(25.00))); //sd
assert(results.get(3).equals(new Double(1.00))); //min
assert(results.get(4).equals(new Double(175.00))); //max
assert(results.get(5).equals(new Double(1.00))); // ??
}
}