001: /*
002: (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: All rights reserved - see end of file.
004: $Id: NewRegressionSeqMethods.java,v 1.4 2008/01/02 12:07:03 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.regression;
008:
009: import junit.framework.TestSuite;
010:
011: import com.hp.hpl.jena.rdf.model.*;
012: import com.hp.hpl.jena.regression.Regression.*;
013: import com.hp.hpl.jena.vocabulary.RDF;
014:
015: public class NewRegressionSeqMethods extends
016: NewRegressionContainerMethods {
017: public NewRegressionSeqMethods(String name) {
018: super (name);
019: }
020:
021: public static TestSuite suite() {
022: return new TestSuite(NewRegressionSeqMethods.class);
023: }
024:
025: protected Container createContainer() {
026: return m.createSeq();
027: }
028:
029: protected Resource getContainerType() {
030: return RDF.Seq;
031: }
032:
033: public void error(String test, int n) {
034: fail(test + " -- " + n);
035: }
036:
037: protected LitTestObj tvObject;
038: protected Literal tvLiteral;
039: protected Resource tvResource;
040: protected Resource tvResObj;
041: protected Object tvLitObj;
042: protected Bag tvBag;
043: protected Alt tvAlt;
044: protected Seq tvSeq;
045:
046: protected static final String lang = "fr";
047: protected static final int num = 10;
048:
049: public void setUp() {
050: super .setUp();
051: tvObject = new LitTestObj(12345);
052: tvLiteral = m.createLiteral("test 12 string 2");
053: tvResource = m.createResource();
054: tvResObj = m.createResource(new ResTestObjF());
055: tvLitObj = new LitTestObj(1234);
056: tvBag = m.createBag();
057: tvAlt = m.createAlt();
058: tvSeq = m.createSeq();
059: }
060:
061: public void testSeq7() {
062: Seq seq7 = m.createSeq();
063: String test = "seq7";
064: int n = 0;
065: n = (n / 100) * 100 + 100;
066: for (int i = 0; i < num; i++) {
067: seq7.add(i);
068: }
069: n = (n / 100) * 100 + 100;
070: seq7.set(5, tvBoolean);
071: n++;
072: if (!(seq7.getBoolean(5) == tvBoolean))
073: error(test, n);
074: n++;
075: if (!(seq7.getInt(4) == 3))
076: error(test, n);
077: n++;
078: if (!(seq7.getInt(6) == 5))
079: error(test, n);
080: n++;
081: if (!(seq7.size() == num))
082: error(test, n);
083: n = (n / 100) * 100 + 100;
084: seq7.set(5, tvByte);
085: n++;
086: if (!(seq7.getByte(5) == tvByte))
087: error(test, n);
088: n++;
089: if (!(seq7.getInt(4) == 3))
090: error(test, n);
091: n++;
092: if (!(seq7.getInt(6) == 5))
093: error(test, n);
094: n++;
095: if (!(seq7.size() == num))
096: error(test, n);
097: n = (n / 100) * 100 + 100;
098: seq7.set(5, tvShort);
099: n++;
100: if (!(seq7.getShort(5) == tvShort))
101: error(test, n);
102: n++;
103: if (!(seq7.getInt(4) == 3))
104: error(test, n);
105: n++;
106: if (!(seq7.getInt(6) == 5))
107: error(test, n);
108: n++;
109: if (!(seq7.size() == num))
110: error(test, n);
111: n = (n / 100) * 100 + 100;
112: seq7.set(5, tvInt);
113: n++;
114: if (!(seq7.getInt(5) == tvInt))
115: error(test, n);
116: n++;
117: if (!(seq7.getInt(4) == 3))
118: error(test, n);
119: n++;
120: if (!(seq7.getInt(6) == 5))
121: error(test, n);
122: n++;
123: if (!(seq7.size() == num))
124: error(test, n);
125: n = (n / 100) * 100 + 100;
126: seq7.set(5, tvLong);
127: n++;
128: if (!(seq7.getLong(5) == tvLong))
129: error(test, n);
130: n++;
131: if (!(seq7.getInt(4) == 3))
132: error(test, n);
133: n++;
134: if (!(seq7.getInt(6) == 5))
135: error(test, n);
136: n++;
137: if (!(seq7.size() == num))
138: error(test, n);
139: n = (n / 100) * 100 + 100;
140: seq7.set(5, tvChar);
141: n++;
142: if (!(seq7.getChar(5) == tvChar))
143: error(test, n);
144: n++;
145: if (!(seq7.getInt(4) == 3))
146: error(test, n);
147: n++;
148: if (!(seq7.getInt(6) == 5))
149: error(test, n);
150: n++;
151: if (!(seq7.size() == num))
152: error(test, n);
153: n = (n / 100) * 100 + 100;
154: seq7.set(5, tvFloat);
155: n++;
156: if (!(seq7.getFloat(5) == tvFloat))
157: error(test, n);
158: n++;
159: if (!(seq7.getInt(4) == 3))
160: error(test, n);
161: n++;
162: if (!(seq7.getInt(6) == 5))
163: error(test, n);
164: n++;
165: if (!(seq7.size() == num))
166: error(test, n);
167: n = (n / 100) * 100 + 100;
168: seq7.set(5, tvDouble);
169: n++;
170: if (!(seq7.getDouble(5) == tvDouble))
171: error(test, n);
172: n++;
173: if (!(seq7.getInt(4) == 3))
174: error(test, n);
175: n++;
176: if (!(seq7.getInt(6) == 5))
177: error(test, n);
178: n++;
179: if (!(seq7.size() == num))
180: error(test, n);
181: n = (n / 100) * 100 + 100;
182: seq7.set(5, tvString);
183: n++;
184: if (!(seq7.getString(5).equals(tvString)))
185: error(test, n);
186: n++;
187: if (!(seq7.getLanguage(5).equals("")))
188: error(test, n);
189: n++;
190: if (!(seq7.getInt(4) == 3))
191: error(test, n);
192: n++;
193: if (!(seq7.getInt(6) == 5))
194: error(test, n);
195: n++;
196: if (!(seq7.size() == num))
197: error(test, n);
198: seq7.set(5, tvString, lang);
199: n++;
200: if (!(seq7.getString(5).equals(tvString)))
201: error(test, n);
202: n++;
203: if (!(seq7.getLanguage(5).equals(lang)))
204: error(test, n);
205: n++;
206: if (!(seq7.getInt(4) == 3))
207: error(test, n);
208: n++;
209: if (!(seq7.getInt(6) == 5))
210: error(test, n);
211: n++;
212: if (!(seq7.size() == num))
213: error(test, n);
214: n = (n / 100) * 100 + 100;
215: seq7.set(5, tvLiteral);
216: n++;
217: if (!(seq7.getLiteral(5).equals(tvLiteral)))
218: error(test, n);
219: n++;
220: if (!(seq7.getInt(4) == 3))
221: error(test, n);
222: n++;
223: if (!(seq7.getInt(6) == 5))
224: error(test, n);
225: n++;
226: if (!(seq7.size() == num))
227: error(test, n);
228: n = (n / 100) * 100 + 100;
229: seq7.set(5, tvResource);
230: n++;
231: if (!(seq7.getResource(5).equals(tvResource)))
232: error(test, n);
233: n++;
234: if (!(seq7.getInt(4) == 3))
235: error(test, n);
236: n++;
237: if (!(seq7.getInt(6) == 5))
238: error(test, n);
239: n++;
240: if (!(seq7.size() == num))
241: error(test, n);
242: n = (n / 100) * 100 + 100;
243: seq7.set(5, tvLitObj);
244: n++;
245: if (!(seq7.getObject(5, new LitTestObjF())).equals(tvLitObj))
246: error(test, n);
247: n++;
248: if (!(seq7.getInt(4) == 3))
249: error(test, n);
250: n++;
251: if (!(seq7.getInt(6) == 5))
252: error(test, n);
253: n++;
254: if (!(seq7.size() == num))
255: error(test, n);
256: n = (n / 100) * 100 + 100;
257: seq7.set(5, tvResObj);
258: n++;
259: if (!(seq7.getResource(5, new ResTestObjF()).equals(tvResObj)))
260: error(test, n);
261: n++;
262: if (!(seq7.getInt(4) == 3))
263: error(test, n);
264: n++;
265: if (!(seq7.getInt(6) == 5))
266: error(test, n);
267: n++;
268: if (!(seq7.size() == num))
269: error(test, n);
270: }
271:
272: public void testSeq6() {
273: String test = "seq6";
274: int n = 0;
275: Seq seq6 = m.createSeq();
276: seq6.add(m.createResource());
277: seq6.add(1, tvBoolean);
278: n++;
279: if (!(seq6.getBoolean(1) == tvBoolean))
280: error(test, n);
281: seq6.add(1, tvByte);
282: n++;
283: if (!(seq6.getByte(1) == tvByte))
284: error(test, n);
285: seq6.add(1, tvShort);
286: n++;
287: if (!(seq6.getShort(1) == tvShort))
288: error(test, n);
289: seq6.add(1, tvInt);
290: n++;
291: if (!(seq6.getInt(1) == tvInt))
292: error(test, n);
293: seq6.add(1, tvLong);
294: n++;
295: if (!(seq6.getLong(1) == tvLong))
296: error(test, n);
297: seq6.add(1, tvChar);
298: n++;
299: if (!(seq6.getChar(1) == tvChar))
300: error(test, n);
301: seq6.add(1, tvFloat);
302: n++;
303: if (!(seq6.getFloat(1) == tvFloat))
304: error(test, n);
305: seq6.add(1, tvDouble);
306: n++;
307: if (!(seq6.getDouble(1) == tvDouble))
308: error(test, n);
309: seq6.add(1, tvString);
310: n++;
311: if (!(seq6.getString(1).equals(tvString)))
312: error(test, n);
313: seq6.add(1, tvString, lang);
314: n++;
315: if (!(seq6.getString(1).equals(tvString)))
316: error(test, n);
317: seq6.add(1, tvResource);
318: n++;
319: if (!(seq6.getResource(1).equals(tvResource)))
320: error(test, n);
321: seq6.add(1, tvLiteral);
322: n++;
323: if (!(seq6.getLiteral(1).equals(tvLiteral)))
324: error(test, n);
325: seq6.add(1, tvLitObj);
326: n++;
327: if (!(seq6.getObject(1, new LitTestObjF()).equals(tvLitObj)))
328: error(test, n);
329:
330: n = (n / 100) * 100 + 100;
331: n++;
332: if (!(seq6.indexOf(tvLitObj) == 1))
333: error(test, n);
334: n++;
335: if (!(seq6.indexOf(tvLiteral) == 2))
336: error(test, n);
337: n++;
338: if (!(seq6.indexOf(tvResource) == 3))
339: error(test, n);
340: n++;
341: if (!(seq6.indexOf(tvString, lang) == 4))
342: error(test, n);
343: n++;
344: if (!(seq6.indexOf(tvString) == 5))
345: error(test, n);
346: n++;
347: if (!(seq6.indexOf(tvDouble) == 6))
348: error(test, n);
349: n++;
350: if (!(seq6.indexOf(tvFloat) == 7))
351: error(test, n);
352: n++;
353: if (!(seq6.indexOf(tvChar) == 8))
354: error(test, n);
355: n++;
356: if (!(seq6.indexOf(tvLong) == 9))
357: error(test, n);
358: n++;
359: if (!(seq6.indexOf(tvInt) == 10))
360: error(test, n);
361: n++;
362: if (!(seq6.indexOf(tvShort) == 11))
363: error(test, n);
364: n++;
365: if (!(seq6.indexOf(tvByte) == 12))
366: error(test, n);
367: n++;
368: if (!(seq6.indexOf(tvBoolean) == 13))
369: error(test, n);
370: n++;
371: if (!(seq6.indexOf(1234543) == 0))
372: error(test, n);
373: }
374:
375: public void testSeq5() {
376: Seq seq5 = m.createSeq();
377: String test = "seq5";
378: int n = 0;
379: for (int i = 0; i < num; i++) {
380: seq5.add(i);
381: }
382:
383: try {
384: n++;
385: seq5.add(0, false);
386: error(test, n);
387: } catch (SeqIndexBoundsException e) {
388: // as required
389: }
390: seq5.add(num + 1, false);
391: if (seq5.size() != num + 1)
392: error(test, n);
393: seq5.remove(num + 1);
394: try {
395: n++;
396: seq5.add(num + 2, false);
397: error(test, n);
398: } catch (SeqIndexBoundsException e) {
399: // as required
400: }
401:
402: n = (n / 100) * 100 + 100;
403: int size = seq5.size();
404: for (int i = 1; i <= num - 1; i++) {
405: n++;
406: seq5.add(i, 1000 + i);
407: n++;
408: if (!(seq5.getInt(i) == 1000 + i))
409: error(test, n);
410: n++;
411: if (!(seq5.getInt(i + 1) == 0))
412: error(test, n);
413: n++;
414: if (!(seq5.size() == (size + i)))
415: error(test, n);
416: n++;
417: if (!(seq5.getInt(size) == (num - i - 1)))
418: error(test, n);
419: }
420: }
421:
422: public void testSeq4() {
423: String test = "temp";
424: int n = 58305;
425: Seq seq4 = m.createSeq();
426: n = (n / 100) * 100 + 100;
427: n++;
428: seq4.add(tvBoolean);
429: n++;
430: if (!(seq4.getBoolean(1) == tvBoolean))
431: error(test, n);
432: n++;
433: seq4.add(tvByte);
434: n++;
435: if (!(seq4.getByte(2) == tvByte))
436: error(test, n);
437: n++;
438: seq4.add(tvShort);
439: n++;
440: if (!(seq4.getShort(3) == tvShort))
441: error(test, n);
442: n++;
443: seq4.add(tvInt);
444: n++;
445: if (!(seq4.getInt(4) == tvInt))
446: error(test, n);
447: n++;
448: seq4.add(tvLong);
449: n++;
450: if (!(seq4.getLong(5) == tvLong))
451: error(test, n);
452: n++;
453: seq4.add(tvChar);
454: n++;
455: if (!(seq4.getChar(6) == tvChar))
456: error(test, n);
457: n++;
458: seq4.add(tvFloat);
459: n++;
460: if (!(seq4.getFloat(7) == tvFloat))
461: error(test, n);
462: n++;
463: seq4.add(tvDouble);
464: n++;
465: if (!(seq4.getDouble(8) == tvDouble))
466: error(test, n);
467: n++;
468: seq4.add(tvString);
469: n++;
470: if (!(seq4.getString(9).equals(tvString)))
471: error(test, n);
472: n++;
473: if (!(seq4.getLanguage(9).equals("")))
474: error(test, n);
475: n++;
476: seq4.add(tvString, lang);
477: n++;
478: if (!(seq4.getString(10).equals(tvString)))
479: error(test, n);
480: n++;
481: if (!(seq4.getLanguage(10).equals(lang)))
482: error(test, n);
483: n++;
484: seq4.add(tvLitObj);
485: n++;
486: if (!(seq4.getObject(11, new LitTestObjF()).equals(tvLitObj)))
487: error(test, n);
488: n++;
489: seq4.add(tvResource);
490: n++;
491: if (!(seq4.getResource(12).equals(tvResource)))
492: error(test, n);
493: n++;
494: seq4.add(tvLiteral);
495: n++;
496: if (!(seq4.getLiteral(13).equals(tvLiteral)))
497: error(test, n);
498: n++;
499: seq4.add(tvResObj);
500: n++;
501: if (!(seq4.getResource(14, new ResTestObjF()).equals(tvResObj)))
502: error(test, n);
503: n++;
504: seq4.add(tvBag);
505: n++;
506: if (!(seq4.getBag(15).equals(tvBag)))
507: error(test, n);
508: n++;
509: seq4.add(tvAlt);
510: n++;
511: if (!(seq4.getAlt(16).equals(tvAlt)))
512: error(test, n);
513: n++;
514: seq4.add(tvSeq);
515: n++;
516: if (!(seq4.getSeq(17).equals(tvSeq)))
517: error(test, n);
518: n++;
519: try {
520: seq4.getInt(18);
521: error(test, n);
522: } catch (SeqIndexBoundsException e) {
523: // as required
524: }
525: n++;
526: try {
527: seq4.getInt(0);
528: error(test, n);
529: } catch (SeqIndexBoundsException e) {
530: // as required
531: }
532: }
533: }
534:
535: /*
536: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
537: * All rights reserved.
538: *
539: * Redistribution and use in source and binary forms, with or without
540: * modification, are permitted provided that the following conditions
541: * are met:
542: * 1. Redistributions of source code must retain the above copyright
543: * notice, this list of conditions and the following disclaimer.
544: * 2. Redistributions in binary form must reproduce the above copyright
545: * notice, this list of conditions and the following disclaimer in the
546: * documentation and/or other materials provided with the distribution.
547: * 3. The name of the author may not be used to endorse or promote products
548: * derived from this software without specific prior written permission.
549: *
550: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
551: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
552: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
553: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
554: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
555: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
556: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
557: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
558: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
559: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
560: */
|