-
Notifications
You must be signed in to change notification settings - Fork 2
/
ProjectTests.java
349 lines (314 loc) · 11 KB
/
ProjectTests.java
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
import static org.junit.Assert.*;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import org.junit.Test;
public class ProjectTests {
@Test
public void testPassForXi() {
Individual hus = new Individual();
hus.setDeath("10 AUG 2014");
Individual wife = new Individual();
Family fam = new Family();
fam.setDivorced("5 JUN 2014");
// System.out.println(ReportingTool.divorceBeforeDeath(fam, wife, hus));
// assertEquals(true, ReportingTool.divorceBeforeDeath(fam, wife, hus).equals("N/AHusband"));
}
@Test
public void testPassForIsValidTag() {
assertEquals(true, isValid.isTagValid(1, "SEX"));
}
@Test
public void testFailForIsValidTag() {
assertEquals(false, isValid.isTagValid(2, "WIFE"));
}
@Test
public void testPassForIsValidDate() {
assertEquals(true, DateComparison.beforeToday("30 JUL 1994"));
}
@Test
public void testFailForIsValidDate() {
assertEquals(false, DateComparison.beforeToday("31 DEC 2017"));
}
@Test
public void testDateLegitimacy() throws ParseException {
assertEquals(true, DateComparison.illegitimateDate("5 FEB 2017"));
assertEquals(false, DateComparison.illegitimateDate("35 FEB 2017"));
}
@Test
public void testPassForDateComparison() {
assertEquals(true, DateComparison.beforeDate("25 MAY 2001", "2016-2-14"));
}
@Test
public void testFailForDateComparison() {
assertEquals(false, DateComparison.beforeDate("26 MAR 2001", "1997-1-1"));
}
@Test
public void testPassForBirthBeforeMarriage() {
Individual person1 = new Individual();
person1.setBirthday("14 FEB 1986");
Family family = new Family("E1", "7 JUL 2016", "P1", "L1");
assertEquals(true, DateComparison.beforeDate(person1.getBirthday(), family.getMarried()));
}
@Test
public void testFailForBirthBeforeMarriage() {
Individual person1 = new Individual();
person1.setBirthday("14 FEB 1986");
Family family = new Family("E1", "7 JUL 1980", "P1", "L1");
assertEquals(false, DateComparison.beforeDate(person1.getBirthday(), family.getMarried()));
}
@Test
public void testPassForBirthBeforeDeath() {
Individual person = new Individual();
person.setBirthday("14 FEB 1986");
person.setDeath("15 AUG 2016");
assertEquals(true, DateComparison.beforeDate(person.getBirthday(), person.getDeath()));
}
@Test
public void testFailForBirthBeforeDeath() {
Individual person = new Individual();
person.setBirthday("14 FEB 1976");
person.setDeath("15 AUG 1955");
assertEquals(false, DateComparison.beforeDate(person.getBirthday(), person.getDeath()));
}
@Test
public void testMarriageBeforeDivorced3(){
Family fam = new Family();
fam.setDivorced("5 JUN 2015");
fam.setMarried("2 FEB 2004");
assertEquals(true,fam.marriageBeforeDivorce());
}
@Test
public void testMarriageBeforeDivorced4(){
Family fam = new Family();
fam.setDivorced("5 JUN 2015");
fam.setMarried("2 FEB 2019");
assertEquals(false,fam.marriageBeforeDivorce());
}
@Test
public void testBirthBeforeMarriageOfParents1(){
Family fam = new Family();
fam.setMarried("5 JUN 2015");
Individual indi = new Individual();
indi.setBirthday("5 JUN 2017");
long beforeDay = DateComparison.differentValueDate(indi.getBirthday(), fam.getMarried());
assertEquals(true, beforeDay>270);
}
@Test
public void testBirthBeforeMarriageOfParents2(){
Family fam = new Family();
fam.setMarried("5 JUN 2015");
Individual indi = new Individual();
indi.setBirthday("5 JAN 2016");
long beforeDay = DateComparison.differentValueDate(indi.getBirthday(), fam.getMarried());
assertEquals(false, beforeDay>270);
}
@Test
public void testPassNumberofSiblings(){
Family family = new Family();
ArrayList<String> children = new ArrayList<String>();
children.add("Kid1");
children.add("Kid2");
children.add("Kid3");
children.add("Kid4");
family.setChildren(children);
assertEquals(true, ReportingTool.numberOfSiblings(family));
}
@Test
public void testFailNumberofSiblings(){
Family family = new Family();
ArrayList<String> children = new ArrayList<String>();
String[] kids = {"Kid1", "Kid2", "Kid3", "Kid4", "Kid5", "Kid6", "Kid7", "Kid8", "Kid9", "Kid10", "Kid11", "Kid12", "Kid13", "Kid14", "Kid15", "Kid16"};
children.addAll(Arrays.asList(kids));
family.setChildren(children);
assertEquals(false, ReportingTool.numberOfSiblings(family));
}
@Test
public void testPassNotMarriedToDescendants() {
Family family = new Family("F12", "12 DEC 1988", "H1", "W1");
ArrayList<String> children = new ArrayList<String>();
String[] kids = {"C1", "C2", "C3"};
children.addAll(Arrays.asList(kids));
family.setChildren(children);
assertEquals(false, family.getChildren().contains(family.getHusbandId()));
assertEquals(false, family.getChildren().contains(family.getWifeId()));
}
@Test
public void testFailNotMarriedToDescendants() {
Family family = new Family("F12", "12 DEC 1988", "H1", "C2");
ArrayList<String> children = new ArrayList<String>();
String[] kids = {"C1", "C2", "C3"};
children.addAll(Arrays.asList(kids));
family.setChildren(children);
assertEquals(false, family.getChildren().contains(family.getHusbandId()));
assertEquals(true, family.getChildren().contains(family.getWifeId()));
}
@Test
public void testPassNotMarriedToSiblings() {
Family family = new Family("F12", "12 DEC 1988", "R1", "N2");
ArrayList<String> children = new ArrayList<String>();
String[] kids = {"N1", "N2", "N3", "N4"};
children.addAll(Arrays.asList(kids));
family.setChildren(children);
assertEquals(false, family.getChildren().contains(family.getHusbandId()));
}
@Test
public void testFailNotMarriedToSiblings() {
Family family = new Family("F12", "12 DEC 1988", "N4", "N2");
ArrayList<String> children = new ArrayList<String>();
String[] kids = {"N1", "N2", "N3", "N4"};
children.addAll(Arrays.asList(kids));
family.setChildren(children);
assertEquals(true, family.getChildren().contains(family.getHusbandId()));
}
public static boolean birthBeforeDeathOfparents(Individual child,Individual father,Individual mother){
if(father.getDeath().equals("N/A") && mother.getDeath().equals("N/A")){
return true;
}
else
if(!father.getDeath().equals("N/A") && DateComparison.beforeDate(child.getBirthday(), father.getDeath())){
return true;
}else if(!mother.getDeath().equals("N/A") && DateComparison.beforeDate(child.getBirthday(), mother.getDeath())){
return true;
}else{
return false;
}
}
@Test
public void testPassBirthBeforeDeathOfParents(){
Individual child = new Individual();
child.setBirthday("10 SEP 2007");
Individual father = new Individual();
Individual mother = new Individual();
assertEquals(true, birthBeforeDeathOfparents(child,father,mother));
}
@Test
public void testFailBirthBeforeDeathOfParents(){
Individual child = new Individual();
child.setBirthday("10 SEP 2007");
Individual father = new Individual();
father.setDeath("22 OCT 2004");
Individual mother = new Individual();
assertEquals(false, birthBeforeDeathOfparents(child,father,mother));
}
public static boolean multiPleBirthLessThan5(Individual[] children){
if(children.length<=5){
return true;
}else{
for(int i=0;i<children.length;i++){
int sameBirthDay = 0;
for(int j=0;j<children.length;j++){
if(children[i].getBirthday().equals(children[j].getBirthday())){
sameBirthDay+=1;
if(sameBirthDay>5){
return false;
}
}
}
}
}
return true;
}
@Test
public void testPassMultipleBirthsLessThan5(){
Individual kid1 = new Individual();
kid1.setBirthday("10 SEP 2007");
Individual kid2 = new Individual();
kid2.setBirthday("10 SEP 2005");
Individual kid3 = new Individual();
kid3.setBirthday("10 SEP 2007");
Individual kid4 = new Individual();
kid4.setBirthday("10 SEP 2007");
Individual kid5 = new Individual();
kid5.setBirthday("10 SEP 2007");
Individual kid6 = new Individual();
kid6.setBirthday("10 SEP 2007");
Individual[] children = {kid1,kid2,kid3,kid4,kid5,kid6};
assertEquals(true, multiPleBirthLessThan5(children));
}
@Test
public void testFailMultipleBirthsLessThan5(){
Individual kid1 = new Individual();
kid1.setBirthday("10 SEP 2007");
Individual kid2 = new Individual();
kid2.setBirthday("10 SEP 2007");
Individual kid3 = new Individual();
kid3.setBirthday("10 SEP 2007");
Individual kid4 = new Individual();
kid4.setBirthday("10 SEP 2007");
Individual kid5 = new Individual();
kid5.setBirthday("10 SEP 2007");
Individual kid6 = new Individual();
kid6.setBirthday("10 SEP 2007");
Individual[] children = {kid1,kid2,kid3,kid4,kid5,kid6};
assertEquals(false, multiPleBirthLessThan5(children));
}
@Test
public void testPassSiblingsSpacing() {
ParseGEDCOMFile.setMap();
Individual sibling1 = new Individual();
Individual sibling2 = new Individual();
sibling1.setId("N60001");
sibling1.setBirthday("12 DEC 2000");
sibling1.setFamcId("F50001");
sibling2.setId("N60002");
sibling2.setBirthday("20 DEC 2000");
sibling2.setFamcId("F50001");
Family family = new Family("F50001", "12 DEC 1988", "N60003", "N60004");
ArrayList<String> children = new ArrayList<String>();
String[] kids = {"N60001", "N60002"};
children.addAll(Arrays.asList(kids));
family.setChildren(children);
ParseGEDCOMFile.famList.put(50001, family);
ParseGEDCOMFile.indiList.put(60001, sibling1);
ParseGEDCOMFile.indiList.put(60002, sibling2);
assertEquals(true, ReportingTool.SiblingsSpacing(sibling2));
}
@Test
public void testFailSiblingsSpacing() {
ParseGEDCOMFile.setMap();
Individual sibling1 = new Individual();
Individual sibling2 = new Individual();
sibling1.setId("N60001");
sibling1.setBirthday("12 DEC 2000");
sibling1.setFamcId("F50001");
sibling2.setId("N60002");
sibling2.setBirthday("12 DEC 2000");
sibling2.setFamcId("F50001");
Family family = new Family("F50001", "12 DEC 1988", "N60003", "N60004");
ArrayList<String> children = new ArrayList<String>();
String[] kids = {"N60001", "N60002"};
children.addAll(Arrays.asList(kids));
family.setChildren(children);
ParseGEDCOMFile.famList.put(50001, family);
ParseGEDCOMFile.indiList.put(60001, sibling1);
ParseGEDCOMFile.indiList.put(60002, sibling2);
assertEquals(false, ReportingTool.SiblingsSpacing(sibling2));
}
@Test
public void testPassMarriageBeforeFourteen() {
ParseGEDCOMFile.setMap();
Individual indi = new Individual();
indi.setId("N60001");
indi.setFamsId("F50001");
indi.setBirthday("12 DEC 1995");
Family fam = new Family();
fam.setMarried("12 DEC 2000");
fam.setHusbandId("N60001");
ParseGEDCOMFile.famList.put(50001, fam);
assertEquals(true, ReportingTool.MarriageBeforeFourteen(indi));
}
@Test
public void testFailMarriageBeforeFourteen() {
ParseGEDCOMFile.setMap();
Individual indi = new Individual();
indi.setId("N60001");
indi.setFamsId("F50001");
indi.setBirthday("12 DEC 1975");
Family fam = new Family();
fam.setMarried("12 DEC 2000");
fam.setHusbandId("N60001");
ParseGEDCOMFile.famList.put(50001, fam);
assertEquals(false, ReportingTool.MarriageBeforeFourteen(indi));
}
}