Source code: com/eireneh/bible/passage/ZTestBiblePassage.java
1
2 package com.eireneh.bible.passage;
3
4 import java.io.*;
5 import java.util.*;
6
7 import com.eireneh.util.TestBase;
8
9 /**
10 * Attepmted 100% code coverage testing.
11 *
12 * <table border='1' cellPadding='3' cellSpacing='0' width="100%">
13 * <tr><td bgColor='white'class='TableRowColor'><font size='-7'>
14 * Distribution Licence:<br />
15 * Project B is free software; you can redistribute it
16 * and/or modify it under the terms of the GNU General Public License,
17 * version 2 as published by the Free Software Foundation.<br />
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * General Public License for more details.<br />
22 * The License is available on the internet
23 * <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, by writing to
24 * <i>Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25 * MA 02111-1307, USA</i>, Or locally at the Licence link below.<br />
26 * The copyright to this program is held by it's authors.
27 * </font></td></tr></table>
28 * @see <a href='http://www.eireneh.com/servlets/Web'>Project B Home</a>
29 * @see docs.Licence
30 * @author Joe Walker
31 */
32 public class ZTestBiblePassage extends TestBase
33 {
34 /**
35 * A basic are we OK type test, for the Passage package.
36 */
37 public void test(PrintWriter out, boolean fatal)
38 {
39 logPackageStart(out, fatal, ZTestBiblePassage.class);
40
41 PassageFactory.setDefaultPassage(PassageFactory.SIZE);
42 testReadPassage(false);
43
44 PassageFactory.setDefaultPassage(PassageFactory.WRITE_SPEED);
45 testReadPassage(false);
46
47 PassageFactory.setDefaultPassage(PassageFactory.SPEED);
48 testReadPassage(false);
49
50 PassageFactory.setDefaultPassage(PassageFactory.MIX);
51 testReadPassage(false);
52
53 PassageFactory.setDefaultPassage(PassageFactory.TALLY);
54 testReadPassage(false);
55
56 PassageFactory.setDefaultPassage(PassageFactory.SPEED);
57 testReadPassage(true);
58
59 testPassageConstants();
60 testPassageUtil();
61
62 testBooks();
63 testVerse();
64 testVerseRange();
65
66 PassageFactory.setDefaultPassage(PassageFactory.SIZE);
67 testWritePassage(false);
68
69 PassageFactory.setDefaultPassage(PassageFactory.WRITE_SPEED);
70 testWritePassage(false);
71
72 PassageFactory.setDefaultPassage(PassageFactory.SPEED);
73 testWritePassage(false);
74
75 PassageFactory.setDefaultPassage(PassageFactory.MIX);
76 testWritePassage(false);
77
78 PassageFactory.setDefaultPassage(PassageFactory.TALLY);
79 testWritePassage(false);
80
81 PassageFactory.setDefaultPassage(PassageFactory.SPEED);
82 testWritePassage(true);
83
84 PassageFactory.setDefaultPassage(PassageFactory.SPEED);
85
86 testPassageTally();
87 testStrongs();
88
89 logPackageStop();
90 }
91
92 /**
93 * Some integration testing.
94 */
95 public static void testPassageConstants()
96 {
97 try
98 {
99 log("PassageConstants.*_ALLOWED_DELIMS");
100
101 // Check that we're not re-using delimitters
102 for (int i=0; i<Passage.VERSE_ALLOWED_DELIMS.length(); i++)
103 {
104 test(Passage.REF_ALLOWED_DELIMS.indexOf(Passage.VERSE_ALLOWED_DELIMS.charAt(i)), -1);
105 test(Passage.RANGE_ALLOWED_DELIMS.indexOf(Passage.VERSE_ALLOWED_DELIMS.charAt(i)), -1);
106 }
107 for (int i=0; i<Passage.REF_ALLOWED_DELIMS.length(); i++)
108 {
109 test(Passage.RANGE_ALLOWED_DELIMS.indexOf(Passage.REF_ALLOWED_DELIMS.charAt(i)), -1);
110 }
111
112 out.flush();
113 }
114 catch (Exception ex)
115 {
116 fail(ex);
117 }
118 }
119
120 /**
121 * Test the Case class.
122 */
123 public static void testPassageUtil()
124 {
125 try
126 {
127 // Need to add:
128 /*
129 log("PassageUtil.[s|g]etBlurRestriction()");
130 log("PassageUtil.isValidBlurRestriction()");
131 log("PassageUtil.getBlurRestrictions()");
132 log("PassageUtil.isValidCase()");
133 log("PassageUtil.getCases()");
134 log("PassageUtil.isValidAccuracy()");
135 Should there be getAccuracies()
136 */
137
138 log("PassageUtil.getCase()");
139 test(PassageUtil.getCase("FRED"), Passage.CASE_UPPER);
140 test(PassageUtil.getCase("F-ED"), Passage.CASE_UPPER);
141 test(PassageUtil.getCase("F00D"), Passage.CASE_UPPER);
142 test(PassageUtil.getCase("fred"), Passage.CASE_LOWER);
143 test(PassageUtil.getCase("f-ed"), Passage.CASE_LOWER);
144 test(PassageUtil.getCase("f00d"), Passage.CASE_LOWER);
145 test(PassageUtil.getCase("Fred"), Passage.CASE_SENTANCE);
146 test(PassageUtil.getCase("F-ed"), Passage.CASE_SENTANCE);
147 test(PassageUtil.getCase("F00d"), Passage.CASE_SENTANCE);
148 test(PassageUtil.getCase("fRED"), Passage.CASE_MIXED);
149 test(PassageUtil.getCase("frED"), Passage.CASE_MIXED);
150 test(PassageUtil.getCase("freD"), Passage.CASE_MIXED);
151 test(PassageUtil.getCase("LORD's"), Passage.CASE_MIXED);
152 test(PassageUtil.getCase(""), Passage.CASE_LOWER);
153 try { PassageUtil.getCase(null); fail(); }
154 catch (NullPointerException ex) { }
155 // The results of this are undefined so
156 // test(PassageUtil.getCase("FreD"), Passage.CASE_SENTANCE);
157
158 log("PassageUtil.setCase()");
159 test(PassageUtil.setCase("FRED", Passage.CASE_UPPER), "FRED");
160 test(PassageUtil.setCase("Fred", Passage.CASE_UPPER), "FRED");
161 test(PassageUtil.setCase("fred", Passage.CASE_UPPER), "FRED");
162 test(PassageUtil.setCase("frED", Passage.CASE_UPPER), "FRED");
163 test(PassageUtil.setCase("fr00", Passage.CASE_UPPER), "FR00");
164 test(PassageUtil.setCase("fr=_", Passage.CASE_UPPER), "FR=_");
165 test(PassageUtil.setCase("FRED", Passage.CASE_LOWER), "fred");
166 test(PassageUtil.setCase("Fred", Passage.CASE_LOWER), "fred");
167 test(PassageUtil.setCase("fred", Passage.CASE_LOWER), "fred");
168 test(PassageUtil.setCase("frED", Passage.CASE_LOWER), "fred");
169 test(PassageUtil.setCase("fr00", Passage.CASE_LOWER), "fr00");
170 test(PassageUtil.setCase("fr=_", Passage.CASE_LOWER), "fr=_");
171 test(PassageUtil.setCase("FRED", Passage.CASE_SENTANCE), "Fred");
172 test(PassageUtil.setCase("Fred", Passage.CASE_SENTANCE), "Fred");
173 test(PassageUtil.setCase("fred", Passage.CASE_SENTANCE), "Fred");
174 test(PassageUtil.setCase("frED", Passage.CASE_SENTANCE), "Fred");
175 test(PassageUtil.setCase("fr00", Passage.CASE_SENTANCE), "Fr00");
176 test(PassageUtil.setCase("fr=_", Passage.CASE_SENTANCE), "Fr=_");
177 test(PassageUtil.setCase("lord's", Passage.CASE_MIXED), "LORD's");
178 test(PassageUtil.setCase("LORD's", Passage.CASE_MIXED), "LORD's");
179 test(PassageUtil.setCase("no-one", Passage.CASE_LOWER), "no-one");
180 test(PassageUtil.setCase("no-one", Passage.CASE_UPPER), "NO-ONE");
181 test(PassageUtil.setCase("no-one", Passage.CASE_SENTANCE), "No-one");
182 test(PassageUtil.setCase("xx-one", Passage.CASE_LOWER), "xx-one");
183 test(PassageUtil.setCase("xx-one", Passage.CASE_UPPER), "XX-ONE");
184 test(PassageUtil.setCase("xx-one", Passage.CASE_SENTANCE), "Xx-One");
185 test(PassageUtil.setCase("god-inspired", Passage.CASE_SENTANCE), "God-inspired");
186 test(PassageUtil.setCase("god-breathed", Passage.CASE_SENTANCE), "God-breathed");
187 test(PassageUtil.setCase("maher-shalal-hash-baz", Passage.CASE_SENTANCE), "Maher-Shalal-Hash-Baz");
188 test(PassageUtil.setCase("", Passage.CASE_LOWER), "");
189 test(PassageUtil.setCase("", Passage.CASE_UPPER), "");
190 test(PassageUtil.setCase("", Passage.CASE_SENTANCE), "");
191 try { PassageUtil.setCase("god-inspired", Passage.CASE_MIXED); fail(); }
192 catch (IllegalArgumentException ex) { }
193 try { PassageUtil.setCase("fred", -1); fail(); }
194 catch (IllegalArgumentException ex) { }
195 try { PassageUtil.setCase("fred", 4); fail(); }
196 catch (IllegalArgumentException ex) { }
197
198 log("PassageUtil.*PersistentNaming()");
199 boolean stored_naming = PassageUtil.isPersistentNaming();
200 PassageUtil.setPersistentNaming(false);
201 test(!PassageUtil.isPersistentNaming());
202 test(new Verse("Genesis 1 1").toString(), "Gen 1:1");
203 test(new Verse("Gen 1 1").toString(), "Gen 1:1");
204 test(new Verse("Genesis 1:1").toString(), "Gen 1:1");
205 test(new Verse("Gen 1 1").toString(), "Gen 1:1");
206 test(new Verse("g 1 1").toString(), "Gen 1:1");
207 test(new Verse("g").toString(), "Gen 1:1");
208 test(new Verse("G:1:1").toString(), "Gen 1:1");
209 PassageUtil.setPersistentNaming(true);
210 test(PassageUtil.isPersistentNaming());
211 test(new Verse("Genesis 1 1").toString(), "Genesis 1 1");
212 test(new Verse("Gen 1 1").toString(), "Gen 1 1");
213 test(new Verse("Genesis 1:1").toString(), "Genesis 1:1");
214 test(new Verse("Gen 1 1").toString(), "Gen 1 1");
215 test(new Verse("g 1 1").toString(), "g 1 1");
216 test(new Verse("g").toString(), "g");
217 test(new Verse("G:1:1").toString(), "G:1:1");
218 PassageUtil.setPersistentNaming(stored_naming);
219
220 /*
221 log("PassageUtil.tokenize()");
222 String[] temp = PassageUtil.tokenize(" one two three ", " ");
223 test(temp.length, 3);
224 test(temp[0], "one");
225 test(temp[1], "two");
226 test(temp[2], "three");
227 */
228
229 log("PassageUtil.toSentanceCase()");
230 test(PassageUtil.toSentanceCase("one"), "One");
231 test(PassageUtil.toSentanceCase("one two"), "One two");
232 test(PassageUtil.toSentanceCase("ONE"), "One");
233 test(PassageUtil.toSentanceCase("ONE TWO"), "One two");
234 test(PassageUtil.toSentanceCase("onE"), "One");
235 test(PassageUtil.toSentanceCase("onE twO"), "One two");
236 test(PassageUtil.toSentanceCase("12345"), "12345");
237 test(PassageUtil.toSentanceCase("1 two"), "1 two");
238 test(PassageUtil.toSentanceCase("1 TWO"), "1 two");
239 try { PassageUtil.toSentanceCase(null); fail(); }
240 catch (NullPointerException ex) { }
241
242 log("PassageUtil.toBinary(byte[], int, int, int)");
243 log("PassageUtil.fromBinary(byte[], int[], int)");
244 byte[] buffer;
245 int[] index;
246
247 index = new int[] { 0 };
248 buffer = new byte[] { (byte) -1, (byte) -1, (byte) -1, (byte) -1, };
249 test(1, PassageUtil.toBinary(buffer, 0, 0, 0));
250 test(buffer[0], 0);
251 test(buffer[1], -1);
252 test(buffer[2], -1);
253 test(buffer[3], -1);
254 test(0, PassageUtil.fromBinary(buffer, index, 0));
255 test(1, index[0]);
256
257 index = new int[] { 0 };
258 buffer = new byte[] { (byte) -1, (byte) -1, (byte) -1, (byte) -1, };
259 test(1, PassageUtil.toBinary(buffer, 0, 0, 1));
260 test(buffer[0], 0);
261 test(buffer[1], -1);
262 test(buffer[2], -1);
263 test(buffer[3], -1);
264 test(0, PassageUtil.fromBinary(buffer, index, 1));
265 test(1, index[0]);
266
267 index = new int[] { 0 };
268 buffer = new byte[] { (byte) -1, (byte) -1, (byte) -1, (byte) -1, };
269 test(1, PassageUtil.toBinary(buffer, 0, 0, 255));
270 test(buffer[0], 0);
271 test(buffer[1], -1);
272 test(buffer[2], -1);
273 test(buffer[3], -1);
274 test(0, PassageUtil.fromBinary(buffer, index, 255));
275 test(1, index[0]);
276
277 index = new int[] { 0 };
278 buffer = new byte[] { (byte) -1, (byte) -1, (byte) -1, (byte) -1, };
279 test(2, PassageUtil.toBinary(buffer, 0, 0, 256));
280 test(buffer[0], 0);
281 test(buffer[1], 0);
282 test(buffer[2], -1);
283 test(buffer[3], -1);
284 test(0, PassageUtil.fromBinary(buffer, index, 256));
285 test(2, index[0]);
286
287 index = new int[] { 0 };
288 buffer = new byte[] { (byte) -1, (byte) -1, (byte) -1, (byte) -1, };
289 test(2, PassageUtil.toBinary(buffer, 0, 0, 65535));
290 test(buffer[0], 0);
291 test(buffer[1], 0);
292 test(buffer[2], -1);
293 test(buffer[3], -1);
294 test(0, PassageUtil.fromBinary(buffer, index, 65535));
295 test(2, index[0]);
296
297 index = new int[] { 0 };
298 buffer = new byte[] { (byte) -1, (byte) -1, (byte) -1, (byte) -1, };
299 test(3, PassageUtil.toBinary(buffer, 0, 0, 65536));
300 test(buffer[0], 0);
301 test(buffer[1], 0);
302 test(buffer[2], 0);
303 test(buffer[3], -1);
304 test(0, PassageUtil.fromBinary(buffer, index, 65536));
305 test(3, index[0]);
306
307 index = new int[] { 0 };
308 buffer = new byte[] { (byte) -1, (byte) -1, (byte) -1, (byte) -1, };
309 test(3, PassageUtil.toBinary(buffer, 0, 0, 16777215));
310 test(buffer[0], 0);
311 test(buffer[1], 0);
312 test(buffer[2], 0);
313 test(buffer[3], -1);
314 test(0, PassageUtil.fromBinary(buffer, index, 16777215));
315 test(3, index[0]);
316
317 index = new int[] { 0 };
318 buffer = new byte[] { (byte) -1, (byte) -1, (byte) -1, (byte) -1, };
319 test(4, PassageUtil.toBinary(buffer, 0, 0, 16777216));
320 test(buffer[0], 0);
321 test(buffer[1], 0);
322 test(buffer[2], 0);
323 test(buffer[3], 0);
324 test(0, PassageUtil.fromBinary(buffer, index, 16777216));
325 test(4, index[0]);
326
327 index = new int[] { 0 };
328 buffer = new byte[] { (byte) -1, (byte) -1, (byte) -1, (byte) -1, };
329 test(4, PassageUtil.toBinary(buffer, 0, 0, 2147483647));
330 test(buffer[0], 0);
331 test(buffer[1], 0);
332 test(buffer[2], 0);
333 test(buffer[3], 0);
334 test(0, PassageUtil.fromBinary(buffer, index, 2147483647));
335 test(4, index[0]);
336
337 index = new int[] { 0 };
338 buffer = new byte[] { (byte) 0, (byte) 0, (byte) 0, (byte) 0, };
339 test(1, PassageUtil.toBinary(buffer, 0, 1, 1));
340 test(buffer[0], 1);
341 test(buffer[1], 0);
342 test(buffer[2], 0);
343 test(buffer[3], 0);
344 test(1, PassageUtil.fromBinary(buffer, index, 1));
345 test(1, index[0]);
346
347 index = new int[] { 0 };
348 buffer = new byte[] { (byte) 0, (byte) 0, (byte) 0, (byte) 0, };
349 test(1, PassageUtil.toBinary(buffer, 0, 255, 255));
350 test(buffer[0], -1);
351 test(buffer[1], 0);
352 test(buffer[2], 0);
353 test(buffer[3], 0);
354 test(255, PassageUtil.fromBinary(buffer, index, 255));
355 test(1, index[0]);
356
357 index = new int[] { 0 };
358 buffer = new byte[] { (byte) 0, (byte) 0, (byte) 0, (byte) 0, };
359 test(2, PassageUtil.toBinary(buffer, 0, 65535, 65535));
360 test(buffer[0], -1);
361 test(buffer[1], -1);
362 test(buffer[2], 0);
363 test(buffer[3], 0);
364 test(65535, PassageUtil.fromBinary(buffer, index, 65535));
365 test(2, index[0]);
366
367 index = new int[] { 0 };
368 buffer = new byte[] { (byte) 0, (byte) 0, (byte) 0, (byte) 0, };
369 test(3, PassageUtil.toBinary(buffer, 0, 16777215, 16777215));
370 test(buffer[0], -1);
371 test(buffer[1], -1);
372 test(buffer[2], -1);
373 test(buffer[3], 0);
374 test(16777215, PassageUtil.fromBinary(buffer, index, 16777215));
375 test(3, index[0]);
376
377 index = new int[] { 0 };
378 buffer = new byte[] { (byte) 0, (byte) 0, (byte) 0, (byte) 0, };
379 test(4, PassageUtil.toBinary(buffer, 0, 2147483647, 2147483647));
380 test(buffer[0], 127);
381 test(buffer[1], -1);
382 test(buffer[2], -1);
383 test(buffer[3], -1);
384 test(2147483647, PassageUtil.fromBinary(buffer, index, 2147483647));
385 test(4, index[0]);
386
387 index = new int[] { 2 };
388 buffer = new byte[] { (byte) -1, (byte) -1, (byte) -1, (byte) -1, };
389 test(1, PassageUtil.toBinary(buffer, 2, 10, 11));
390 test(buffer[0], -1);
391 test(buffer[1], -1);
392 test(buffer[2], 10);
393 test(buffer[3], -1);
394 test(10, PassageUtil.fromBinary(buffer, index, 11));
395 test(3, index[0]);
396
397 for (int i=0; i<2147400000; i+=10000)
398 {
399 index = new int[] { 0 };
400 buffer = new byte[] { (byte) 0, (byte) 0, (byte) 0, (byte) 0, };
401 test(4, PassageUtil.toBinary(buffer, 0, i, 2147483647));
402 test(i, PassageUtil.fromBinary(buffer, index, 2147483647));
403 test(4, index[0]);
404 }
405
406 log("PassageUtil.toBinaryRepresentation(Passage)");
407 log("PassageUtil.fromBinaryRepresentation(byte[])");
408 Passage gen1_135 = PassageFactory.createPassage("Gen 1:1, Gen 1:3, Gen 1:5");
409 Passage exo2a_3b = PassageFactory.createPassage("Exo 2:1-10, Exo 3:1-11");
410 Passage gen_rev = PassageFactory.createPassage("Gen 1:1-Rev 22:21");
411 Passage hard = PassageFactory.createPassage();
412 Passage empty = PassageFactory.createPassage();
413 for (int i=1; i<Books.versesInBible(); i+=10)
414 {
415 hard.add(new Verse(i));
416 }
417 byte[] temp = PassageUtil.toBinaryRepresentation(gen1_135);
418 Passage gen1_135_copy = PassageUtil.fromBinaryRepresentation(temp);
419 test(gen1_135_copy, gen1_135);
420 temp = PassageUtil.toBinaryRepresentation(exo2a_3b);
421 Passage exo2a_3b_copy = PassageUtil.fromBinaryRepresentation(temp);
422 test(exo2a_3b_copy, exo2a_3b);
423 temp = PassageUtil.toBinaryRepresentation(gen_rev);
424 Passage gen_rev_copy = PassageUtil.fromBinaryRepresentation(temp);
425 test(gen_rev_copy, gen_rev);
426 temp = PassageUtil.toBinaryRepresentation(hard);
427 Passage hard_copy = PassageUtil.fromBinaryRepresentation(temp);
428 test(hard_copy, hard);
429 temp = PassageUtil.toBinaryRepresentation(empty);
430 Passage empty_copy = PassageUtil.fromBinaryRepresentation(temp);
431 test(empty_copy, empty);
432 }
433 catch (Exception ex)
434 {
435 fail(ex);
436 }
437 }
438
439 /**
440 * Test the Books class.
441 */
442 public static void testBooks()
443 {
444 try
445 {
446 int stored_case = Books.getCase();
447
448 log("Books.[g|s]etCase()");
449 Books.setCase(Passage.CASE_LOWER);
450 test(Books.getCase(), Passage.CASE_LOWER);
451 Books.setCase(Passage.CASE_UPPER);
452 test(Books.getCase(), Passage.CASE_UPPER);
453 Books.setCase(Passage.CASE_SENTANCE);
454 test(Books.getCase(), Passage.CASE_SENTANCE);
455 try { Books.setCase(Passage.CASE_MIXED); fail(); }
456 catch (IllegalArgumentException ex) { }
457 try { Books.setCase(-1); fail(); }
458 catch (IllegalArgumentException ex) { }
459
460 log("Books.getLongBookName()");
461 Books.setCase(Passage.CASE_SENTANCE);
462 test(Books.getLongBookName(1), "Genesis");
463 test(Books.getLongBookName(66), "Revelation");
464 Books.setCase(Passage.CASE_LOWER);
465 test(Books.getLongBookName(1), "genesis");
466 test(Books.getLongBookName(66), "revelation");
467 Books.setCase(Passage.CASE_UPPER);
468 test(Books.getLongBookName(1), "GENESIS");
469 test(Books.getLongBookName(66), "REVELATION");
470 try { Books.getShortBookName(0); fail(); }
471 catch (NoSuchVerseException ex) { }
472 try { Books.getShortBookName(67); fail(); }
473 catch (NoSuchVerseException ex) { }
474
475 log("Books.getShortBookName()");
476 Books.setCase(Passage.CASE_SENTANCE);
477 try { Books.getShortBookName(0); fail(); }
478 catch (NoSuchVerseException ex) { }
479 test(Books.getShortBookName(1), "Gen");
480 test(Books.getShortBookName(7), "Judg");
481 test(Books.getShortBookName(39), "Mal");
482 test(Books.getShortBookName(40), "Mat");
483 test(Books.getShortBookName(50), "Phili");
484 test(Books.getShortBookName(57), "Phile");
485 test(Books.getShortBookName(65), "Jude");
486 test(Books.getShortBookName(66), "Rev");
487 try { Books.getShortBookName(67); fail(); }
488 catch (NoSuchVerseException ex) { }
489 Books.setCase(Passage.CASE_LOWER);
490 try { Books.getShortBookName(0); fail(); }
491 catch (NoSuchVerseException ex) { }
492 test(Books.getShortBookName(1), "gen");
493 test(Books.getShortBookName(7), "judg");
494 test(Books.getShortBookName(39), "mal");
495 test(Books.getShortBookName(40), "mat");
496 test(Books.getShortBookName(50), "phili");
497 test(Books.getShortBookName(57), "phile");
498 test(Books.getShortBookName(65), "jude");
499 test(Books.getShortBookName(66), "rev");
500 try { Books.getShortBookName(67); fail(); }
501 catch (NoSuchVerseException ex) { }
502 Books.setCase(Passage.CASE_UPPER);
503 try { Books.getShortBookName(0); fail(); }
504 catch (NoSuchVerseException ex) { }
505 test(Books.getShortBookName(1), "GEN");
506 test(Books.getShortBookName(7), "JUDG");
507 test(Books.getShortBookName(39), "MAL");
508 test(Books.getShortBookName(40), "MAT");
509 test(Books.getShortBookName(50), "PHILI");
510 test(Books.getShortBookName(57), "PHILE");
511 test(Books.getShortBookName(65), "JUDE");
512 test(Books.getShortBookName(66), "REV");
513 try { Books.getShortBookName(67); fail(); }
514 catch (NoSuchVerseException ex) { }
515
516 log("Books.getBookJogger()");
517 test(Books.getBookJogger(1), "LT");
518 test(Books.getBookJogger(66), "DB");
519 try { Books.getBookJogger(0); fail(); }
520 catch (NoSuchVerseException ex) { }
521 try { Books.getBookJogger(67); fail(); }
522 catch (NoSuchVerseException ex) { }
523
524 log("Books.getNumberJogger()");
525 test(Books.getNumberJogger(0), "S");
526 test(Books.getNumberJogger(1), "T");
527 test(Books.getNumberJogger(9), "P");
528 test(Books.getNumberJogger(10), "TS");
529 test(Books.getNumberJogger(99), "PP");
530 test(Books.getNumberJogger(100), "TSS");
531 test(Books.getNumberJogger(65536), "GLLMG");
532
533 log("Books.getBookNumber()");
534 test(Books.getBookNumber("Genesis"), 1);
535 test(Books.getBookNumber("Gene"), 1);
536 test(Books.getBookNumber("Gen"), 1);
537 test(Books.getBookNumber("G"), 1);
538 test(Books.getBookNumber("GEN"), 1);
539 test(Books.getBookNumber("genesis"), 1);
540 test(Books.getBookNumber("revelations"), 66);
541 test(Books.getBookNumber("rev"), 66);
542 test(Books.getBookNumber("phi"), 50);
543 test(Books.getBookNumber("phil"), 50);
544 test(Books.getBookNumber("phili"), 50);
545 test(Books.getBookNumber("phile"), 57);
546 try { Books.getBookNumber("b"); fail(); }
547 catch (NoSuchVerseException ex) { }
548 try { Books.getBookNumber("1"); fail(); }
549 catch (NoSuchVerseException ex) { }
550
551 log("Books.*In*()");
552 test(Books.versesInBook(1), 1533);
553 test(Books.versesInBook(66), 404);
554 // Counts using loops
555 int viw_b = 0;
556 int viw_c = 0;
557 int ciw = 0;
558 // For all the books
559 for (int b=1; b<=Books.booksInBible(); b++)
560 {
561 // Count and check the verses in this book
562 int vib = 0;
563 for (int c=1; c<=Books.chaptersInBook(b); c++) vib += Books.versesInChapter(b, c);
564 test(vib, Books.versesInBook(b));
565
566 // Continue the verse counts for the whole Bible
567 for (int c=1; c<=Books.chaptersInBook(b); c++) viw_c += Books.versesInChapter(b, c);
568 viw_b += Books.versesInBook(b);
569
570 // Continue the chapter count for the whole Bible
571 ciw += Books.chaptersInBook(b);
572 }
573 test(Books.versesInBible(), viw_b);
574 test(Books.versesInBible(), viw_c);
575 test(Books.chaptersInBible(), ciw);
576 test(Books.booksInBible(), 66);
577
578 log("Books.verseOrdinal()");
579 log("Books.decodeOrdinal()");
580 int first_verse_ord = 1;
581 int last_verse_ord = 1;
582 for (int b=1; b<=Books.booksInBible(); b++)
583 {
584 for (int c=1; c<=Books.chaptersInBook(b); c++)
585 {
586 last_verse_ord = first_verse_ord + Books.versesInChapter(b, c) - 1;
587
588 test(first_verse_ord, Books.verseOrdinal(b, c, 1));
589 test(first_verse_ord, Books.verseOrdinal(new int[]{b,c,1}));
590 test(first_verse_ord+1, Books.verseOrdinal(b, c, 2));
591 test(first_verse_ord+1, Books.verseOrdinal(new int[]{b,c,2}));
592 test(last_verse_ord, Books.verseOrdinal(b, c, Books.versesInChapter(b, c)));
593 test(last_verse_ord, Books.verseOrdinal(new int[]{b,c,Books.versesInChapter(b, c)}));
594
595 test(Books.verseCount(new int[]{b,c,1}, Books.decodeOrdinal(first_verse_ord)), 1);
596 test(Books.verseCount(new int[]{b,c,2}, Books.decodeOrdinal(first_verse_ord+1)), 1);
597 test(Books.verseCount(new int[]{b,c,Books.versesInChapter(b, c)}, Books.decodeOrdinal(last_verse_ord)), 1);
598
599 first_verse_ord += Books.versesInChapter(b, c);
600 }
601 }
602
603 log("Books.validate()");
604 try { Books.validate(0, 1, 1); fail(); }
605 catch (NoSuchVerseException ex) { }
606 for (int b=1; b<Books.booksInBible(); b++)
607 {
608 try { Books.validate(b, 0, 1); fail(); }
609 catch (NoSuchVerseException ex) { }
610 try { Books.validate(b, 1, 0); fail(); }
611 catch (NoSuchVerseException ex) { }
612
613 for (int c=1; c<=Books.chaptersInBook(b); c++)
614 {
615 try { Books.validate(b, c, 0); fail(); }
616 catch (NoSuchVerseException ex) { }
617
618 for (int v=1; v<=Books.versesInChapter(b, c); v++)
619 {
620 Books.validate(b, c, v);
621 // This fn is tested as exhaustivly as the validate(int, int, int)
622 // version however since is is only a bit of sugar this is OK
623 Books.validate(new int[] {b, c, v});
624 }
625 try { Books.validate(b, c, Books.versesInChapter(b, c)+1); fail(); }
626 catch (NoSuchVerseException ex) { }
627 }
628
629 try { Books.validate(67, Books.chaptersInBook(b)+1, 1); fail(); }
630 catch (NoSuchVerseException ex) { }
631 try { Books.validate(67, 1, Books.versesInBook(b)+1); fail(); }
632 catch (NoSuchVerseException ex) { }
633 }
634 try { Books.validate(67, 1, 1); fail(); }
635 catch (NoSuchVerseException ex) { }
636
637 log("Books.patch()");
638 int all = 1;
639 for (int b=1; b<Books.booksInBible(); b++)
640 {
641 for (int c=1; c<=Books.chaptersInBook(b); c++)
642 {
643 for (int v=1; v<=Books.versesInChapter(b, c); v++)
644 {
645 int[] simple = { 1, 1, all++ };
646 int[] complex = { b, c, v };
647 Books.patch(simple);
648
649 test(simple[Books.BOOK], complex[Books.BOOK]);
650 test(simple[Books.CHAPTER], complex[Books.CHAPTER]);
651 test(simple[Books.VERSE], complex[Books.VERSE]);
652 }
653 }
654 }
655 int[] v111 = { 1, 1, 1 };
656 int[] test = null;
657 test(Books.verseCount(v111, Books.patch(new int[]{1,1,1})), 1);
658 test(Books.verseCount(v111, Books.patch(new int[]{1,1,0})), 1);
659 test(Books.verseCount(v111, Books.patch(new int[]{1,0,1})), 1);
660 test(Books.verseCount(v111, Books.patch(new int[]{1,0,0})), 1);
661 test(Books.verseCount(v111, Books.patch(new int[]{0,1,1})), 1);
662 test(Books.verseCount(v111, Books.patch(new int[]{0,1,0})), 1);
663 test(Books.verseCount(v111, Books.patch(new int[]{0,0,1})), 1);
664 test(Books.verseCount(v111, Books.patch(new int[]{0,0,0})), 1);
665
666 log("Books.verseCount()");
667 int count_up = 0;
668 int count_down = 31102;
669 for (int b=1; b<Books.booksInBible(); b++)
670 {
671 for (int c=1; c<=Books.chaptersInBook(b); c++)
672 {
673 for (int v=1; v<=Books.versesInChapter(b, c); v++)
674 {
675 int up = Books.verseCount(1, 1, 1, b, c, v);
676 int down = Books.verseCount(b, c, v, 66, 22, 21);
677
678 test(up, ++count_up);
679 test(down, count_down--);
680
681 test(Books.verseCount(new int[] {1, 1, 1}, new int[] {b, c, v}), verseCountSlow(1, 1, 1, b, c, v));
682 }
683 }
684
685 test(Books.verseCount(b, 1, 1, b, Books.chaptersInBook(b), Books.versesInChapter(b, Books.chaptersInBook(b))), Books.versesInBook(b));
686 }
687 test(Books.verseCount(1, 1, 1, 2, 1, 1), Books.versesInBook(1)+1);
688 test(Books.verseCount(1, 1, 1, 1, 1, 10), 10);
689
690 log("Books.Names");
691 test(Books.Names.Genesis, 1);
692 test(Books.Names.Revelation, 66);
693
694 Books.setCase(stored_case);
695 out.flush();
696 }
697 catch (Exception ex)
698 {
699 ex.printStackTrace(out);
700 }
701 }
702
703 /**
704 * This is code from Books that was needed only as part of testing, so I
705 * Moved it here. How many verses between ref1 and ref2 (inclusive).
706 * @param book1 The book part of the first reference.
707 * @param chapter1 The chapter part of the first reference.
708 * @param verse1 The verse part of the first reference.
709 * @param book2 The book part of the second reference.
710 * @param chapter2 The chapter part of the second reference.
711 * @param verse2 The verse part of the second reference.
712 * @exception com.eireneh.bible.NoSuchVerseException If either reference is illegal
713 */
714 protected static int verseCountSlow(int book1, int chapter1, int verse1, int book2, int chapter2, int verse2) throws NoSuchVerseException
715 {
716 Books.validate(book1, chapter1, verse1);
717 Books.validate(book2, chapter2, verse2);
718
719 int count = 0;
720
721 // If we are in different books, count the verses until the books are the same
722 if (book1 != book2)
723 {
724 // 1st count to the end of the chapter
725 count += Books.versesInChapter(book1, chapter1) - verse1 + 1;
726
727 // Then count from the end of the chapter to the end of the book
728 for (int c=chapter1+1; c<=Books.chaptersInBook(book1); c++)
729 count += Books.versesInChapter(book1, c);
730
731 // Then count until the books are the same
732 for (int b=book1+1; b<book2; b++)
733 count += Books.versesInBook(b);
734
735 // The new position
736 book1 = book2;
737 chapter1 = 1;
738 verse1 = 1;
739 }
740
741 // Count the verses in the chapters so that we are in the same chapter
742 for (int c=chapter1; c<chapter2; c++)
743 count += Books.versesInChapter(book2, c);
744
745 // And finally the verses in the final chapter
746 count += verse2 - verse1 + 1;
747
748 return count;
749 }
750
751 /**
752 * Test the Verse class.
753 */
754 public static void testVerse()
755 {
756 try
757 {
758 Verse gen11 = new Verse(1, 1, 1);
759 Verse gen11a = new Verse(1, 1, 1);
760 Verse gen12 = new Verse(1, 1, 2);
761 Verse gen21 = new Verse(1, 2, 1);
762 Verse gen22 = new Verse(1, 2, 2);
763 Verse rev11 = new Verse(66, 1, 1);
764 Verse rev12 = new Verse(66, 1, 2);
765 Verse rev21 = new Verse(66, 2, 1);
766 Verse rev22 = new Verse(66, 2, 2);
767 Verse rev99 = new Verse(66, 22, 21);
768 Verse jude1 = new Verse(65, 1, 1);
769 Verse jude2 = new Verse(65, 1, 2);
770 Verse jude9 = new Verse(65, 1, 25);
771 Verse ssa11 = new Verse(10, 1, 1);
772 Verse pro11 = new Verse(20, 1, 1);
773 Verse ch111 = new Verse(13, 1, 1);
774
775 log("Verse.new Verse(String)");
776 test(gen11, new Verse());
777 test(gen11, new Verse("Genesis 1 1"));
778 test(gen11, new Verse("Gen 1 1"));
779 test(gen11, new Verse("G 1 1"));
780 test(gen11, new Verse("genesis 1 1"));
781 test(gen11, new Verse("genesi 1 1"));
782 test(gen11, new Verse("GENESIS 1 1"));
783 test(gen11, new Verse("GENESI 1 1"));
784 test(gen11, new Verse("g 1 1"));
785 test(gen11, new Verse("g 1"));
786 test(gen11, new Verse("g"));
787 test(gen11, new Verse("gen"));
788 test(rev99, new Verse("rev 22 21"));
789 test(rev99, new Verse("REVE 22 21"));
790 test(rev99, new Verse("REVELATIONS 22 21"));
791 test(gen21, new Verse("g 2"));
792 test(gen11, new Verse("g.1.1"));
793 test(gen11, new Verse("g 1.1"));
794 test(gen11, new Verse("g.1 1"));
795 test(gen11, new Verse("g.1:1"));
796 test(gen11, new Verse("g:1:1"));
797 test(gen11, new Verse("g:1 1"));
798 test(gen11, new Verse(" g 1 1 "));
799 test(gen11, new Verse(""));
800 test(gen11, new Verse("gen1"));
801 test(gen11, new Verse("GEN1"));
802 test(gen11, new Verse("GENESIS1:1"));
803 test(gen11, new Verse("G1 1"));
804 test(gen11, new Verse(" GEN 1 1 "));
805 test(gen11, new Verse("gen1v1"));
806 test(gen11, new Verse("gen 1 v 1"));
807 test(gen11, new Verse("gen 1v1"));
808 test(gen11, new Verse("gen 1 v 1"));
809 test(gen11, new Verse("gen 1 v 1 "));
810 test(gen11, new Verse(" gen 1 v 1 "));
811 test(gen11, new Verse("gen ch1 1"));
812 test(gen11, new Verse("gen ch 1 1"));
813 test(gen11, new Verse("gen ch 1 1"));
814 test(gen11, new Verse("gen ch1v1"));
815 test(gen11, new Verse(" gen ch 1 v 1 "));
816 test(gen11, new Verse(" gen 1 1 "));
817 test(pro11, new Verse("proverbs 1v1"));
818 test(ch111, new Verse("1chronicles ch1 1"));
819 test(ssa11, new Verse("2Sa 1:1"));
820 test(ssa11, new Verse("2Sa 1 1"));
821 test(ssa11, new Verse("2Sa1 1"));
822 test(ssa11, new Verse("2 Sa 1 1"));
823 test(ssa11, new Verse("2 Sa1 1"));
824 test(ssa11, new Verse("2Sa1:1"));
825 test(ssa11, new Verse("2 Sa 1 1"));
826 test(ssa11, new Verse(" 2 Sa 1 "));
827 test(ssa11, new Verse(" 2 Sa "));
828 test(ssa11, new Verse(" 2 Sa1 "));
829 test(ssa11, new Verse(" 2 Sa1 1 "));
830 test(ssa11, new Verse(" 2 : Sa1 1 "));
831 test(rev99, new Verse("Rev 22:$"));
832 test(rev99, new Verse(" Rev 22 ff "));
833 test(rev99, new Verse(" Rev 22 ff "));
834 test(rev99, new Verse(" Rev 22 $ "));
835 test(jude9, new Verse("Jude $"));
836 test(jude9, new Verse(" Jude $ "));
837 test(jude9, new Verse("Jude ff"));
838 test(jude9, new Verse(" Jude ff "));
839 test(new Verse("Deu 1:1"), new Verse("Dt 1:1"));
840 test(new Verse("Mat 1:1"), new Verse("Mt 1:1"));
841 try { new Verse("gen 1 1 1"); fail(); }
842 catch (NoSuchVerseException ex) { }
843 try { new Verse("gen.1.1.1"); fail(); }
844 catch (NoSuchVerseException ex) { }
845 try { new Verse("gen.1.1:1"); fail(); }
846 catch (NoSuchVerseException ex) { }
847 try { new Verse("gen 1 1 1", gen11); fail(); }
848 catch (NoSuchVerseException ex) { }
849 try { new Verse("gen 1 1 1", gen11); fail(); }
850 catch (NoSuchVerseException ex) { }
851 try { new Verse("gen 1 1 1", gen11); fail(); }
852 catch (NoSuchVerseException ex) { }
853 try { new Verse((String) null); fail(); }
854 catch (Exception ex) { }
855 test(jude1, new Verse("jude 1"));
856 test(jude2, new Verse("jude 2"));
857 test(jude9, new Verse("jude 25"));
858
859 log("Verse.getName()");
860 test(new Verse("Genesis 1 1").getName(), "Gen 1:1");
861 test(new Verse("Gen 1 1").getName(), "Gen 1:1");
862 test(new Verse("Genesis 1:1").getName(), "Gen 1:1");
863 test(new Verse("Gen 1 1").getName(), "Gen 1:1");
864 test(new Verse("g 1 1").getName(), "Gen 1:1");
865 test(new Verse("g").getName(), "Gen 1:1");
866 test(new Verse("G:1:1").getName(), "Gen 1:1");
867 test(new Verse("Jude 1").getName(), "Jude 1");
868 test(new Verse("Jude").getName(), "Jude 1");
869 test(new Verse("Jude 1:1").getName(), "Jude 1");
870
871 log("Verse.getName(Verse)");
872 test(new Verse("Gen 1:2").getName(gen11), "2");
873 test(new Verse("Gen 2:1").getName(gen11), "2:1");
874 test(new