001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jfreechart/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * ------------------------------
028: * TaskSeriesCollectionTests.java
029: * ------------------------------
030: * (C) Copyright 2004-2007, by Object Refinery Limited.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: TaskSeriesCollectionTests.java,v 1.1.2.2 2007/03/08 13:57:09 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 30-Jul-2004 : Version 1 (DG);
040: * 12-Jan-2005 : Added tests from TaskSeriesCollectionTests2.java (DG);
041: * 08-Mar-2007 : Added testRemove() (DG);
042: *
043: */
044:
045: package org.jfree.data.gantt.junit;
046:
047: import java.io.ByteArrayInputStream;
048: import java.io.ByteArrayOutputStream;
049: import java.io.ObjectInput;
050: import java.io.ObjectInputStream;
051: import java.io.ObjectOutput;
052: import java.io.ObjectOutputStream;
053: import java.util.Date;
054:
055: import junit.framework.Test;
056: import junit.framework.TestCase;
057: import junit.framework.TestSuite;
058:
059: import org.jfree.data.gantt.Task;
060: import org.jfree.data.gantt.TaskSeries;
061: import org.jfree.data.gantt.TaskSeriesCollection;
062: import org.jfree.data.time.SimpleTimePeriod;
063:
064: /**
065: * Tests for the {@link TaskSeriesCollection} class.
066: */
067: public class TaskSeriesCollectionTests extends TestCase {
068:
069: /**
070: * Returns the tests as a test suite.
071: *
072: * @return The test suite.
073: */
074: public static Test suite() {
075: return new TestSuite(TaskSeriesCollectionTests.class);
076: }
077:
078: /**
079: * Constructs a new set of tests.
080: *
081: * @param name the name of the tests.
082: */
083: public TaskSeriesCollectionTests(String name) {
084: super (name);
085: }
086:
087: /**
088: * Creates a sample collection for testing purposes.
089: *
090: * @return A sample collection.
091: */
092: private TaskSeriesCollection createCollection1() {
093: TaskSeriesCollection result = new TaskSeriesCollection();
094: TaskSeries s1 = new TaskSeries("S1");
095: s1.add(new Task("Task 1", new Date(1), new Date(2)));
096: s1.add(new Task("Task 2", new Date(3), new Date(4)));
097: result.add(s1);
098: TaskSeries s2 = new TaskSeries("S2");
099: s2.add(new Task("Task 3", new Date(5), new Date(6)));
100: result.add(s2);
101: return result;
102: }
103:
104: /**
105: * Creates a sample collection for testing purposes.
106: *
107: * @return A sample collection.
108: */
109: private TaskSeriesCollection createCollection2() {
110: TaskSeriesCollection result = new TaskSeriesCollection();
111: TaskSeries s1 = new TaskSeries("S1");
112: Task t1 = new Task("Task 1", new Date(10), new Date(20));
113: t1.addSubtask(new Task("Task 1A", new Date(10), new Date(15)));
114: t1.addSubtask(new Task("Task 1B", new Date(16), new Date(20)));
115: t1.setPercentComplete(0.10);
116: s1.add(t1);
117: Task t2 = new Task("Task 2", new Date(30), new Date(40));
118: t2.addSubtask(new Task("Task 2A", new Date(30), new Date(35)));
119: t2.addSubtask(new Task("Task 2B", new Date(36), new Date(40)));
120: t2.setPercentComplete(0.20);
121: s1.add(t2);
122: result.add(s1);
123: TaskSeries s2 = new TaskSeries("S2");
124: Task t3 = new Task("Task 3", new Date(50), new Date(60));
125: t3.addSubtask(new Task("Task 3A", new Date(50), new Date(55)));
126: t3.addSubtask(new Task("Task 3B", new Date(56), new Date(60)));
127: t3.setPercentComplete(0.30);
128: s2.add(t3);
129: result.add(s2);
130: return result;
131: }
132:
133: /**
134: * Creates a sample collection for testing purposes.
135: *
136: * @return A sample collection.
137: */
138: private TaskSeriesCollection createCollection3() {
139:
140: // define subtasks
141: Task sub1 = new Task("Sub1", new Date(11), new Date(111));
142: Task sub2 = new Task("Sub2", new Date(22), new Date(222));
143: Task sub3 = new Task("Sub3", new Date(33), new Date(333));
144: Task sub4 = new Task("Sub4", new Date(44), new Date(444));
145: Task sub5 = new Task("Sub5", new Date(55), new Date(555));
146: Task sub6 = new Task("Sub6", new Date(66), new Date(666));
147: sub1.setPercentComplete(0.111);
148: sub2.setPercentComplete(0.222);
149: sub3.setPercentComplete(0.333);
150: sub4.setPercentComplete(0.444);
151: sub5.setPercentComplete(0.555);
152: sub6.setPercentComplete(0.666);
153:
154: TaskSeries seriesA = new TaskSeries("Series A");
155: Task taskA1 = new Task("Task 1", new SimpleTimePeriod(new Date(
156: 100), new Date(200)));
157: taskA1.setPercentComplete(0.1);
158: taskA1.addSubtask(sub1);
159: Task taskA2 = new Task("Task 2", new SimpleTimePeriod(new Date(
160: 220), new Date(350)));
161: taskA2.setPercentComplete(0.2);
162: taskA2.addSubtask(sub2);
163: taskA2.addSubtask(sub3);
164: seriesA.add(taskA1);
165: seriesA.add(taskA2);
166:
167: TaskSeries seriesB = new TaskSeries("Series B");
168: // note that we don't define taskB1
169: Task taskB2 = new Task("Task 2", new SimpleTimePeriod(new Date(
170: 2220), new Date(3350)));
171: taskB2.setPercentComplete(0.3);
172: taskB2.addSubtask(sub4);
173: taskB2.addSubtask(sub5);
174: taskB2.addSubtask(sub6);
175: seriesB.add(taskB2);
176:
177: TaskSeriesCollection tsc = new TaskSeriesCollection();
178: tsc.add(seriesA);
179: tsc.add(seriesB);
180:
181: return tsc;
182: }
183:
184: /**
185: * A test for the getSeriesCount() method.
186: */
187: public void testGetSeriesCount() {
188: TaskSeriesCollection c = createCollection1();
189: assertEquals(2, c.getSeriesCount());
190: }
191:
192: /**
193: * Some tests for the getSeriesKey() method.
194: */
195: public void testGetSeriesKey() {
196: TaskSeriesCollection c = createCollection1();
197: assertEquals("S1", c.getSeriesKey(0));
198: assertEquals("S2", c.getSeriesKey(1));
199: }
200:
201: /**
202: * A test for the getRowCount() method.
203: */
204: public void testGetRowCount() {
205: TaskSeriesCollection c = createCollection1();
206: assertEquals(2, c.getRowCount());
207: }
208:
209: /**
210: * Some tests for the getRowKey() method.
211: */
212: public void testGetRowKey() {
213: TaskSeriesCollection c = createCollection1();
214: assertEquals("S1", c.getRowKey(0));
215: assertEquals("S2", c.getRowKey(1));
216: }
217:
218: /**
219: * Some tests for the getRowIndex() method.
220: */
221: public void testGetRowIndex() {
222: TaskSeriesCollection c = createCollection1();
223: assertEquals(0, c.getRowIndex("S1"));
224: assertEquals(1, c.getRowIndex("S2"));
225: }
226:
227: /**
228: * Some tests for the getValue() method.
229: */
230: public void testGetValue() {
231: TaskSeriesCollection c = createCollection1();
232: assertEquals(new Long(1L), c.getValue("S1", "Task 1"));
233: assertEquals(new Long(3L), c.getValue("S1", "Task 2"));
234: assertEquals(new Long(5L), c.getValue("S2", "Task 3"));
235:
236: assertEquals(new Long(1L), c.getValue(0, 0));
237: assertEquals(new Long(3L), c.getValue(0, 1));
238: assertEquals(null, c.getValue(0, 2));
239: assertEquals(null, c.getValue(1, 0));
240: assertEquals(null, c.getValue(1, 1));
241: assertEquals(new Long(5L), c.getValue(1, 2));
242: }
243:
244: /**
245: * Some tests for the getStartValue() method.
246: */
247: public void testGetStartValue() {
248: TaskSeriesCollection c = createCollection1();
249: assertEquals(new Long(1L), c.getStartValue("S1", "Task 1"));
250: assertEquals(new Long(3L), c.getStartValue("S1", "Task 2"));
251: assertEquals(new Long(5L), c.getStartValue("S2", "Task 3"));
252:
253: assertEquals(new Long(1L), c.getStartValue(0, 0));
254: assertEquals(new Long(3L), c.getStartValue(0, 1));
255: assertEquals(null, c.getStartValue(0, 2));
256: assertEquals(null, c.getStartValue(1, 0));
257: assertEquals(null, c.getStartValue(1, 1));
258: assertEquals(new Long(5L), c.getStartValue(1, 2));
259:
260: // test collection 3, which doesn't define all tasks in all series
261: TaskSeriesCollection c3 = createCollection3();
262: assertEquals(new Long(100), c3.getStartValue(0, 0));
263: assertEquals(new Long(220), c3.getStartValue(0, 1));
264: assertTrue(c3.getStartValue(1, 0) == null);
265: assertEquals(new Long(2220), c3.getStartValue(1, 1));
266: }
267:
268: /**
269: * Some tests for the getStartValue() method for sub-intervals.
270: */
271: public void testGetStartValue2() {
272: TaskSeriesCollection c = createCollection2();
273: assertEquals(new Long(10L), c.getStartValue("S1", "Task 1", 0));
274: assertEquals(new Long(16L), c.getStartValue("S1", "Task 1", 1));
275: assertEquals(new Long(30L), c.getStartValue("S1", "Task 2", 0));
276: assertEquals(new Long(36L), c.getStartValue("S1", "Task 2", 1));
277: assertEquals(new Long(50L), c.getStartValue("S2", "Task 3", 0));
278: assertEquals(new Long(56L), c.getStartValue("S2", "Task 3", 1));
279:
280: assertEquals(new Long(10L), c.getStartValue(0, 0, 0));
281: assertEquals(new Long(16L), c.getStartValue(0, 0, 1));
282: assertEquals(new Long(30L), c.getStartValue(0, 1, 0));
283: assertEquals(new Long(36L), c.getStartValue(0, 1, 1));
284: assertEquals(new Long(50L), c.getStartValue(1, 2, 0));
285: assertEquals(new Long(56L), c.getStartValue(1, 2, 1));
286:
287: TaskSeriesCollection c3 = createCollection3();
288: assertEquals(new Long(11), c3.getStartValue(0, 0, 0));
289: assertEquals(new Long(22), c3.getStartValue(0, 1, 0));
290: assertEquals(new Long(33), c3.getStartValue(0, 1, 1));
291: assertTrue(c3.getStartValue(1, 0, 0) == null);
292: assertEquals(new Long(44), c3.getStartValue(1, 1, 0));
293: assertEquals(new Long(55), c3.getStartValue(1, 1, 1));
294: assertEquals(new Long(66), c3.getStartValue(1, 1, 2));
295: }
296:
297: /**
298: * A check for a null task duration.
299: */
300: public void testGetStartValue3() {
301: TaskSeriesCollection c = new TaskSeriesCollection();
302: TaskSeries s = new TaskSeries("Series 1");
303: s.add(new Task("Task with null duration", null));
304: c.add(s);
305: Number millis = c.getStartValue("Series 1",
306: "Task with null duration");
307: assertTrue(millis == null);
308: }
309:
310: /**
311: * Some tests for the getEndValue() method.
312: */
313: public void testGetEndValue() {
314: TaskSeriesCollection c = createCollection1();
315: assertEquals(new Long(2L), c.getEndValue("S1", "Task 1"));
316: assertEquals(new Long(4L), c.getEndValue("S1", "Task 2"));
317: assertEquals(new Long(6L), c.getEndValue("S2", "Task 3"));
318:
319: assertEquals(new Long(2L), c.getEndValue(0, 0));
320: assertEquals(new Long(4L), c.getEndValue(0, 1));
321: assertEquals(null, c.getEndValue(0, 2));
322: assertEquals(null, c.getEndValue(1, 0));
323: assertEquals(null, c.getEndValue(1, 1));
324: assertEquals(new Long(6L), c.getEndValue(1, 2));
325:
326: // test collection 3, which doesn't define all tasks in all series
327: TaskSeriesCollection c3 = createCollection3();
328: assertEquals(new Long(200), c3.getEndValue(0, 0));
329: assertEquals(new Long(350), c3.getEndValue(0, 1));
330: assertTrue(c3.getEndValue(1, 0) == null);
331: assertEquals(new Long(3350), c3.getEndValue(1, 1));
332: }
333:
334: /**
335: * Some tests for the getEndValue() method for sub-intervals.
336: */
337: public void testGetEndValue2() {
338: TaskSeriesCollection c = createCollection2();
339: assertEquals(new Long(15L), c.getEndValue("S1", "Task 1", 0));
340: assertEquals(new Long(20L), c.getEndValue("S1", "Task 1", 1));
341: assertEquals(new Long(35L), c.getEndValue("S1", "Task 2", 0));
342: assertEquals(new Long(40L), c.getEndValue("S1", "Task 2", 1));
343: assertEquals(new Long(55L), c.getEndValue("S2", "Task 3", 0));
344: assertEquals(new Long(60L), c.getEndValue("S2", "Task 3", 1));
345:
346: assertEquals(new Long(15L), c.getEndValue(0, 0, 0));
347: assertEquals(new Long(20L), c.getEndValue(0, 0, 1));
348: assertEquals(new Long(35L), c.getEndValue(0, 1, 0));
349: assertEquals(new Long(40L), c.getEndValue(0, 1, 1));
350: assertEquals(new Long(55L), c.getEndValue(1, 2, 0));
351: assertEquals(new Long(60L), c.getEndValue(1, 2, 1));
352:
353: TaskSeriesCollection c3 = createCollection3();
354: assertEquals(new Long(111), c3.getEndValue(0, 0, 0));
355: assertEquals(new Long(222), c3.getEndValue(0, 1, 0));
356: assertEquals(new Long(333), c3.getEndValue(0, 1, 1));
357: assertTrue(c3.getEndValue(1, 0, 0) == null);
358: assertEquals(new Long(444), c3.getEndValue(1, 1, 0));
359: assertEquals(new Long(555), c3.getEndValue(1, 1, 1));
360: assertEquals(new Long(666), c3.getEndValue(1, 1, 2));
361: }
362:
363: /**
364: * A check for a null task duration.
365: */
366: public void testGetEndValue3() {
367: TaskSeriesCollection c = new TaskSeriesCollection();
368: TaskSeries s = new TaskSeries("Series 1");
369: s.add(new Task("Task with null duration", null));
370: c.add(s);
371: Number millis = c.getEndValue("Series 1",
372: "Task with null duration");
373: assertTrue(millis == null);
374: }
375:
376: /**
377: * Some tests for the getPercentComplete() method.
378: */
379: public void testGetPercentComplete() {
380: TaskSeriesCollection c = createCollection2();
381: assertEquals(new Double(0.10), c.getPercentComplete("S1",
382: "Task 1"));
383: assertEquals(new Double(0.20), c.getPercentComplete("S1",
384: "Task 2"));
385: assertEquals(new Double(0.30), c.getPercentComplete("S2",
386: "Task 3"));
387:
388: assertEquals(new Double(0.10), c.getPercentComplete(0, 0));
389: assertEquals(new Double(0.20), c.getPercentComplete(0, 1));
390: assertEquals(null, c.getPercentComplete(0, 2));
391: assertEquals(null, c.getPercentComplete(1, 0));
392: assertEquals(null, c.getPercentComplete(1, 1));
393: assertEquals(new Double(0.30), c.getPercentComplete(1, 2));
394:
395: // test collection 3, which doesn't define all tasks in all series
396: TaskSeriesCollection c3 = createCollection3();
397: assertEquals(new Double(0.1), c3.getPercentComplete(0, 0));
398: assertEquals(new Double(0.2), c3.getPercentComplete(0, 1));
399: assertTrue(c3.getPercentComplete(1, 0) == null);
400: assertEquals(new Double(0.3), c3.getPercentComplete(1, 1));
401:
402: assertEquals(new Double(0.111), c3.getPercentComplete(0, 0, 0));
403:
404: assertEquals(new Double(0.222), c3.getPercentComplete(0, 1, 0));
405: assertEquals(new Double(0.333), c3.getPercentComplete(0, 1, 1));
406:
407: assertEquals(new Double(0.444), c3.getPercentComplete(1, 1, 0));
408: assertEquals(new Double(0.555), c3.getPercentComplete(1, 1, 1));
409: assertEquals(new Double(0.666), c3.getPercentComplete(1, 1, 2));
410: }
411:
412: /**
413: * A test for the getColumnCount() method.
414: */
415: public void testGetColumnCount() {
416: TaskSeriesCollection c = createCollection1();
417: assertEquals(3, c.getColumnCount());
418: }
419:
420: /**
421: * Some tests for the getColumnKey() method.
422: */
423: public void testGetColumnKey() {
424: TaskSeriesCollection c = createCollection1();
425: assertEquals("Task 1", c.getColumnKey(0));
426: assertEquals("Task 2", c.getColumnKey(1));
427: assertEquals("Task 3", c.getColumnKey(2));
428: }
429:
430: /**
431: * Some tests for the getColumnIndex() method.
432: */
433: public void testGetColumnIndex() {
434: TaskSeriesCollection c = createCollection1();
435: assertEquals(0, c.getColumnIndex("Task 1"));
436: assertEquals(1, c.getColumnIndex("Task 2"));
437: assertEquals(2, c.getColumnIndex("Task 3"));
438: }
439:
440: /**
441: * Confirm that the equals method can distinguish all the required fields.
442: */
443: public void testEquals() {
444:
445: TaskSeries s1 = new TaskSeries("S");
446: s1.add(new Task("T1", new Date(1), new Date(2)));
447: s1.add(new Task("T2", new Date(11), new Date(22)));
448: TaskSeries s2 = new TaskSeries("S");
449: s2.add(new Task("T1", new Date(1), new Date(2)));
450: s2.add(new Task("T2", new Date(11), new Date(22)));
451: TaskSeriesCollection c1 = new TaskSeriesCollection();
452: c1.add(s1);
453: c1.add(s2);
454:
455: TaskSeries s1b = new TaskSeries("S");
456: s1b.add(new Task("T1", new Date(1), new Date(2)));
457: s1b.add(new Task("T2", new Date(11), new Date(22)));
458: TaskSeries s2b = new TaskSeries("S");
459: s2b.add(new Task("T1", new Date(1), new Date(2)));
460: s2b.add(new Task("T2", new Date(11), new Date(22)));
461: TaskSeriesCollection c2 = new TaskSeriesCollection();
462: c2.add(s1b);
463: c2.add(s2b);
464:
465: assertTrue(c1.equals(c2));
466: assertTrue(c2.equals(c1));
467:
468: }
469:
470: /**
471: * Confirm that cloning works.
472: */
473: public void testCloning() {
474: TaskSeries s1 = new TaskSeries("S");
475: s1.add(new Task("T1", new Date(1), new Date(2)));
476: s1.add(new Task("T2", new Date(11), new Date(22)));
477: TaskSeries s2 = new TaskSeries("S");
478: s2.add(new Task("T1", new Date(1), new Date(2)));
479: s2.add(new Task("T2", new Date(11), new Date(22)));
480: TaskSeriesCollection c1 = new TaskSeriesCollection();
481: c1.add(s1);
482: c1.add(s2);
483:
484: TaskSeriesCollection c2 = null;
485: try {
486: c2 = (TaskSeriesCollection) c1.clone();
487: } catch (CloneNotSupportedException e) {
488: System.err.println("Failed to clone.");
489: }
490: assertTrue(c1 != c2);
491: assertTrue(c1.getClass() == c2.getClass());
492: assertTrue(c1.equals(c2));
493: }
494:
495: /**
496: * Serialize an instance, restore it, and check for equality.
497: */
498: public void testSerialization() {
499:
500: TaskSeries s1 = new TaskSeries("S");
501: s1.add(new Task("T1", new Date(1), new Date(2)));
502: s1.add(new Task("T2", new Date(11), new Date(22)));
503: TaskSeries s2 = new TaskSeries("S");
504: s2.add(new Task("T1", new Date(1), new Date(2)));
505: s2.add(new Task("T2", new Date(11), new Date(22)));
506: TaskSeriesCollection c1 = new TaskSeriesCollection();
507: c1.add(s1);
508: c1.add(s2);
509: TaskSeriesCollection c2 = null;
510:
511: try {
512: ByteArrayOutputStream buffer = new ByteArrayOutputStream();
513: ObjectOutput out = new ObjectOutputStream(buffer);
514: out.writeObject(c1);
515: out.close();
516:
517: ObjectInput in = new ObjectInputStream(
518: new ByteArrayInputStream(buffer.toByteArray()));
519: c2 = (TaskSeriesCollection) in.readObject();
520: in.close();
521: } catch (Exception e) {
522: System.out.println(e.toString());
523: }
524: assertEquals(c1, c2);
525:
526: }
527:
528: /**
529: * A test for bug report 697153.
530: */
531: public void test697153() {
532:
533: TaskSeries s1 = new TaskSeries("S1");
534: s1.add(new Task("Task 1", new SimpleTimePeriod(new Date(),
535: new Date())));
536: s1.add(new Task("Task 2", new SimpleTimePeriod(new Date(),
537: new Date())));
538: s1.add(new Task("Task 3", new SimpleTimePeriod(new Date(),
539: new Date())));
540:
541: TaskSeries s2 = new TaskSeries("S2");
542: s2.add(new Task("Task 2", new SimpleTimePeriod(new Date(),
543: new Date())));
544: s2.add(new Task("Task 3", new SimpleTimePeriod(new Date(),
545: new Date())));
546: s2.add(new Task("Task 4", new SimpleTimePeriod(new Date(),
547: new Date())));
548:
549: TaskSeriesCollection tsc = new TaskSeriesCollection();
550: tsc.add(s1);
551: tsc.add(s2);
552:
553: s1.removeAll();
554:
555: int taskCount = tsc.getColumnCount();
556:
557: assertEquals(3, taskCount);
558:
559: }
560:
561: /**
562: * A test for bug report 800324.
563: */
564: public void test800324() {
565: TaskSeries s1 = new TaskSeries("S1");
566: s1.add(new Task("Task 1", new SimpleTimePeriod(new Date(),
567: new Date())));
568: s1.add(new Task("Task 2", new SimpleTimePeriod(new Date(),
569: new Date())));
570: s1.add(new Task("Task 3", new SimpleTimePeriod(new Date(),
571: new Date())));
572:
573: TaskSeriesCollection tsc = new TaskSeriesCollection();
574: tsc.add(s1);
575:
576: // these methods should throw an IndexOutOfBoundsException since the
577: // column is too high...
578: try {
579: /* Number start = */tsc.getStartValue(0, 3);
580: assertTrue(false);
581: } catch (IndexOutOfBoundsException e) {
582: // expected
583: }
584: try {
585: /* Number end = */tsc.getEndValue(0, 3);
586: assertTrue(false);
587: } catch (IndexOutOfBoundsException e) {
588: // expected
589: }
590: try {
591: /* int count = */tsc.getSubIntervalCount(0, 3);
592: assertTrue(false);
593: } catch (IndexOutOfBoundsException e) {
594: // expected
595: }
596: }
597:
598: /**
599: * Some tests for the bug report 1099331. We create a TaskSeriesCollection
600: * with two series - the first series has two tasks, but the second has
601: * only one. The key is to ensure that the methods in TaskSeriesCollection
602: * translate the index values to key values *before* accessing the tasks
603: * in the series.
604: */
605: public void testGetSubIntervalCount() {
606: TaskSeriesCollection tsc = createCollection3();
607: assertEquals(1, tsc.getSubIntervalCount(0, 0));
608: assertEquals(2, tsc.getSubIntervalCount(0, 1));
609: assertEquals(0, tsc.getSubIntervalCount(1, 0));
610: assertEquals(3, tsc.getSubIntervalCount(1, 1));
611: }
612:
613: /**
614: * Some basic tests for the getSeries() methods.
615: */
616: public void testGetSeries() {
617: TaskSeries s1 = new TaskSeries("S1");
618: TaskSeries s2 = new TaskSeries("S2");
619: TaskSeriesCollection c = new TaskSeriesCollection();
620: c.add(s1);
621:
622: assertEquals(c.getSeries(0), s1);
623: assertEquals(c.getSeries("S1"), s1);
624: assertEquals(c.getSeries("XX"), null);
625:
626: c.add(s2);
627: assertEquals(c.getSeries(1), s2);
628: assertEquals(c.getSeries("S2"), s2);
629:
630: boolean pass = false;
631: try {
632: c.getSeries(null);
633: } catch (NullPointerException e) {
634: pass = true;
635: }
636: assertTrue(pass);
637: }
638:
639: /**
640: * Some basic checks for the remove() method.
641: */
642: public void testRemove() {
643: TaskSeriesCollection c = new TaskSeriesCollection();
644: TaskSeries s1 = new TaskSeries("S1");
645: c.add(s1);
646: assertEquals("S1", c.getSeries(0).getKey());
647: c.remove(0);
648: assertEquals(0, c.getSeriesCount());
649: c.add(s1);
650:
651: boolean pass = false;
652: try {
653: c.remove(-1);
654: } catch (IllegalArgumentException e) {
655: pass = true;
656: }
657: assertTrue(pass);
658:
659: pass = false;
660: try {
661: c.remove(1);
662: } catch (IllegalArgumentException e) {
663: pass = true;
664: }
665: assertTrue(pass);
666: }
667:
668: }
|