KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > usertasks > schedule > ScheduleUtilsTest


1 /*
2  * ScheduleUtilsTest.java
3  * JUnit based test
4  *
5  * Created on 30. Januar 2007, 11:38
6  */

7
8 package org.netbeans.modules.tasklist.usertasks.schedule;
9
10 import java.util.ArrayList JavaDoc;
11 import java.util.List JavaDoc;
12 import junit.framework.TestCase;
13 import org.netbeans.modules.tasklist.usertasks.model.Dependency;
14 import org.netbeans.modules.tasklist.usertasks.model.UserTask;
15 import org.netbeans.modules.tasklist.usertasks.model.UserTaskList;
16
17 /**
18  * Tests for ScheduleUtils
19  *
20  * @author tim
21  */

22 public class ScheduleUtilsTest extends TestCase {
23     public ScheduleUtilsTest(String JavaDoc testName) {
24         super(testName);
25     }
26     
27     /**
28      * Tests sortForDependencies.
29      * a->b->c
30      */

31     public void testSortForDependencies() {
32         UserTaskList utl = new UserTaskList();
33         UserTask a = new UserTask("a", utl);
34         UserTask b = new UserTask("b", utl);
35         UserTask c = new UserTask("c", utl);
36         
37         c.getDependencies().add(new Dependency(b, Dependency.END_BEGIN));
38         b.getDependencies().add(new Dependency(a, Dependency.END_BEGIN));
39
40         List JavaDoc<UserTask> tasks = new ArrayList JavaDoc<UserTask>();
41         tasks.add(c);
42         tasks.add(a);
43         tasks.add(b);
44         
45         ScheduleUtils.sortForDependencies(tasks);
46         
47         assertEquals(tasks.get(0), a);
48         assertEquals(tasks.get(1), b);
49         assertEquals(tasks.get(2), c);
50     }
51     
52     /**
53      * 4 tasks:
54      * A: 3 minutes
55      * B: 2 minutes
56      * C: 4 minutes
57      * D: 2 minutes
58      * A depends on B
59      * C depends on B
60      * A depends on C
61      * D depends on C
62      *
63      * Dependency matrix:
64      * A B C D
65      * A t t
66      * B
67      * C t
68      * D t
69      */

70     public void testBackflow() {
71         boolean[][] deps = new boolean[][] {
72             {false, true, true, false},
73             {false, false, false, false},
74             {false, true, false, false},
75             {false, false, true, false}
76         };
77         float[] durations = new float[] {3, 2, 4, 2};
78         float[] ct = ScheduleUtils.backflow(deps, durations);
79         assertEquals(ct.length, 4);
80         assertEquals(ct[0], 3, 1e-5);
81         assertEquals(ct[1], 9, 1e-5);
82         assertEquals(ct[2], 7, 1e-5);
83         assertEquals(ct[3], 2, 1e-5);
84     }
85
86     /**
87      * Test for createPriorityListBackflow (see testBackflow for data
88      * definition)
89      */

90     public void testCreatePriorityListBackflow() {
91         UserTaskList utl = new UserTaskList();
92         UserTask a = new UserTask("A", utl);
93         UserTask b = new UserTask("B", utl);
94         UserTask c = new UserTask("C", utl);
95         UserTask d = new UserTask("D", utl);
96         a.getDependencies().add(new Dependency(b, Dependency.END_BEGIN));
97         c.getDependencies().add(new Dependency(b, Dependency.END_BEGIN));
98         a.getDependencies().add(new Dependency(c, Dependency.END_BEGIN));
99         d.getDependencies().add(new Dependency(c, Dependency.END_BEGIN));
100         a.setEffort(3);
101         b.setEffort(2);
102         c.setEffort(4);
103         d.setEffort(2);
104         
105         List JavaDoc<UserTask> v = new ArrayList JavaDoc<UserTask>();
106         v.add(a);
107         v.add(b);
108         v.add(c);
109         v.add(d);
110         
111         ScheduleUtils.createPriorityListBackflow(v);
112         
113         assertEquals("B", v.get(0).getSummary());
114         assertEquals("C", v.get(1).getSummary());
115         assertEquals("A", v.get(2).getSummary());
116         assertEquals("D", v.get(3).getSummary());
117     }
118 }
119
Popular Tags