4 using System
.Collections
;
10 public class SchedTests
12 WvLog log
= new WvLog("Tests");
16 [SetUp
] public void Init()
18 log
.print("Creating schedulator.");
19 reg
= new SourceRegistry();
20 s
= new Schedulator("test");
23 [Test
] public void person_project_fixfor_test()
25 reg
.create(s
, "ss", "test:");
26 // new TestSource(s, "ss");
27 s
.run_until(Schedulator
.Phase
.Sort1
);
30 Person p0
= s
.persons
[0];
31 WVPASSEQ(p0
.name
, "apenwarr");
32 WVPASSEQ(p0
.fullname
, "Avery Pennarun");
34 Person p1
= s
.persons
[1];
35 WVPASSEQ(p1
.name
, "bob");
36 WVPASSEQ(p1
.fullname
, "Bob McDobb");
38 Person p2
= s
.persons
[2];
39 WVPASSEQ(p2
.name
, "chrisk");
40 WVPASSEQ(p2
.fullname
, "chrisk"); // default fullname
42 Person p3
= s
.persons
[3];
43 WVPASSEQ(p3
.name
, "dcoombs");
44 WVPASSEQ(p3
.fullname
, "Dave Coombs");
46 FixFor f1
= s
.fixfors
[1];
47 WVPASSEQ("Wv 1.0", f1
.name
);
48 WVPASSEQ(wv
.date("2006-10-15"), f1
.final_release
);
49 WVPASSEQ(2, f1
.releases
.Count
);
51 WVPASSEQ(wv
.date("2006-10-15"),
52 f1
.release_after(wv
.date("2006-10-11")));
55 void check_tasks(Task
[] correct
)
57 WVPASSEQ(correct
.Length
, s
.tasks
.Count
);
58 for (int i
= 0; i
< correct
.Length
; i
++)
59 WVPASSEQ(correct
[i
].id
, s
.tasks
[i
].id
);
62 [Test
] [Category("basic")] public void task_test_sensible()
64 TestSource src
= new TestSource(s
, "ts");
66 s
.run_until(Schedulator
.Phase
.Basic
);
67 Task
[] correct
= src
.make_tasks();
68 s
.ran_phase
= Schedulator
.Phase
.Tasks
;
69 s
.run_until(Schedulator
.Phase
.Sort2
);
75 // this is actually pretty tricky: we create the tasks *before* the
76 // things (eg. fixfors) the tasks refer to, then fill the information
77 // into the other objects afterwards. This has to work so that you can
78 // load, say, a text schedule with extra tasks before the "real" bug
79 // tracking database with all the extra details.
80 [Test
] public void task_test_backwards()
82 TestSource src
= new TestSource(s
, "ts");
84 Task
[] correct
= src
.make_tasks();
86 s
.ran_phase
= Schedulator
.Phase
.Tasks
;
87 s
.run_until(Schedulator
.Phase
.Sort2
);
93 void dosplit(string input
, string expect
)
95 string output
= String
.Join("!", StringSource
.word_split(input
));
96 WVPASSEQ(expect
, output
);
99 [Test
] [Category("Silly")] public void wordsplit_test()
101 dosplit("hello world", "hello!world");
102 dosplit("hello world ", "hello!world!");
103 dosplit(" hello world ", "!hello!world!");
105 WVPASSEQ(1, StringSource
.word_split("").Length
);
107 dosplit("\"hello world\"", "\"hello world\"");
108 dosplit("'hello world'", "'hello world'");
109 dosplit("[hello world]", "[hello world]");
110 dosplit("(hello world)", "(hello world)");
111 dosplit("{hello world}", "{hello world}");
113 dosplit("\"a b\" \t c", "\"a b\"!c");
114 dosplit("'a\tb' c", "'a\tb'!c");
115 dosplit("\t'a b [c d]' [e f] (g h) {i j (} k) )} (l m) ",
116 "!'a b [c d]'![e f]!(g h)!{i j (} k) )}!(l m)!");
119 string[] merge(string[][] lists
)
122 foreach (string[] list
in lists
)
124 string[] outlist
= new string[max
];
126 foreach (string[] list
in lists
)
127 foreach (string s
in list
)
132 Task
[] lookup_all(TaskList tasks
, string[] list
)
134 Task
[] outlist
= new Task
[list
.Length
];
136 foreach (string name
in list
)
138 Task t
= tasks
.FindByName(name
);
140 t
= tasks
.FindById(name
);
142 throw new ArgumentException
143 ("can't find task named '" + name
+ "'");
149 [Test
] [Category("Silly2")] public void stringsource_test()
151 reg
.create(s
, "s1", "file:test1.sched");
152 s
.run_until(Schedulator
.Phase
.Sort2
);
155 FixFor ff
= s
.fixfors
.Find(s
.projects
.Find("Weaver"), "Wv 1.0");
156 WVPASSEQ(ff
.releases
.Count
, 4);
158 string[] finished
= {
161 string[] undecided
= {
163 "Bug without fixfor",
166 "Unestimated \"Wv 2.0\" stuff",
169 "More Unestimated Wv \"2.0\" stuff",
174 "Sub-bug two estimate \"in title [1d]\"",
175 "Sub-bug two and a half",
188 string[][] all
= {finished, undecided, v2_0, v1_0}
;
189 string[][] active
= {undecided, v2_0, v1_0}
;
191 Task
[] correct
= lookup_all(s
.tasks
, merge(all
));
192 check_tasks(correct
);
194 foreach (Task t
in lookup_all(s
.tasks
, finished
))
195 WVPASSEQ(t
.done
, true);
196 foreach (Task t
in lookup_all(s
.tasks
, merge(active
)))
197 WVPASSEQ(t
.done
, false);
199 // spot check some estimates
200 WVPASSEQ(s
.tasks
.FindByName("First").currest
.TotalHours
, 5.5*8);
201 WVPASSEQ(s
.tasks
.FindByName("First").elapsed
.TotalHours
, 4.33);
202 WVPASSEQ(s
.tasks
.FindByName("Second").currest
.TotalHours
, 6.0*8);
203 WVPASSEQ(s
.tasks
.FindByName("Second").elapsed
.TotalHours
, 8.0);
207 [Test
] [Category("Silly3")] public void stringtestsource_test()
209 // new TestSource(s, "t");
210 // new StringSource(s, "s1", get_file("test1.sched"));
211 reg
.create(s
, "t", "test:");
212 reg
.create(s
, "s1", "file:test1.sched");
214 s
.run_until(Schedulator
.Phase
.Sort2
);
217 FixFor ff
= s
.fixfors
.Find(s
.projects
.Find("Weaver"), "Wv 1.0");
218 WVPASSEQ(ff
.releases
.Count
, 5);
220 string[] finished
= {
221 // the ordering of "Third", t5, and t6 is purely because of
222 // the order they were created, so this tests that the sources
223 // are creating tasks in the right phases, and schedulator
224 // runs multiple sources in the right order.
226 "t:8", "t:7", // done dates come after no done dates
229 string[] undecided
= {
230 "t:4", "t:200", "t:100",
233 "t:3", // because it was created first
236 "Sub-bug two estimate \"in title [1d]\"",
237 "Sub-bug two and a half",
239 "Do some stuff", // low priority bug
244 "One", // child of a lower-priority bug than t3
248 "t:2", // because it was created first
249 "Bug without fixfor", // lower priority
250 "Unestimated \"Wv 2.0\" stuff",
253 "More Unestimated Wv \"2.0\" stuff",
254 "t:1", // because it has nonzero priority
257 string[][] all
= {finished, undecided, v1_0, v2_0}
;
258 Task
[] correct
= lookup_all(s
.tasks
, merge(all
));
259 check_tasks(correct
);
262 [Test
] [Category("Silly4")] public void stringimport_test()
264 reg
.create(s
, "file2", "file:test2.sched");
265 s
.run_until(Schedulator
.Phase
.Sort2
);
269 "t:5", "t:6", "t:8", "t:7",
270 "t:4", "t:200", "t:100",
279 check_tasks(lookup_all(s
.tasks
, all
));
282 [Test
] [Category("sort")] public void sort_test()
284 reg
.create(s
, "t", "file:test3.sched");
285 s
.run_until(Schedulator
.Phase
.Sort2
);
290 "1.1", "1.1.1", "1.1.2",
291 "1.2", "1.2.1", "1.2.2",
295 check_tasks(lookup_all(s
.tasks
, all
));
298 [Test
] public void fogbugz_test()
300 string odbcstr
= String
.Format
301 ("driver={{MySQL}};" +
302 "server={0};database={1};" +
304 "localhost", "fogbugz", "root", "scs");
305 reg
.create(s
, "bug", "fogbugz:" + odbcstr
+ ":apenwarr");
306 s
.run_until(Schedulator
.Phase
.Sort2
);
310 [Test
] [Category("mantis")] public void mantis_test()
312 string odbcstr
= String
.Format
313 ("driver={{MySQL}};" +
314 "server={0};database={1};" +
316 "localhost", "mantis", "root", "scs");
317 reg
.create(s
, "bug", "mantis:" + odbcstr
+ ":wooi");
318 s
.run_until(Schedulator
.Phase
.Sort2
);
322 [Test
] [Category("Silly10")] public void schedule_test()
324 reg
.create(s
, "ts", "file:test10.sched");
327 s
.dump_schedule(log
);
330 [Test
] [Category("Silly11")] public void schedule_test2()
332 reg
.create(s
, "ts", "file:test11.sched");
335 s
.dump_schedule(log
);
337 TaskTimeSlot
[] slots
= new TaskTimeSlot
[s
.schedule
.Count
];
339 foreach (TimeSlot ts
in s
.schedule
)
341 if (ts
is TaskTimeSlot
)
342 slots
[total
++] = (TaskTimeSlot
)ts
;
345 WVPASSEQ(total
, 9+2);
346 WVPASSEQ(slots
[0].name
, "f1");
347 WVPASSEQ(slots
[0].start
, wv
.date("2006-10-09 06:00:00"));
349 // start is exactly equal to aligndate, but f4, while done, was
350 // finished after the aligndate, so it comes before the unfinished
351 // tasks but after the aligndate.
352 WVPASSEQ(slots
[3].name
, "f5");
353 WVPASSEQ(slots
[3].start
, wv
.date("2006-10-10"));
354 WVPASSEQ(slots
[4].name
, "f4");
356 // correction factor for elapsed time on unfinished bugs
357 WVPASSEQ(slots
[5].done
, true);
358 WVPASSEQ(slots
[5].task
.done
, false);
360 // make sure all the unfinished bugs add up correctly
361 WVPASSEQ(slots
[total
-1].end
, wv
.date("2006-10-12 18:00:00"));
364 [Test
] [Category("result")] public void result_test()
366 reg
.create(s
, "t", "file:test10.sched");
367 reg
.create(s
, "result",
368 "result:dsn=schedulator;uid=root;pwd=scs:test");
372 [Test
] [Category("googlecode")] public void googlecode_test()
374 //reg.create(s, "gc", "googlecode:pixeltoaster:glenn*fiedler");
375 reg
.create(s
, "gc", "googlecode:versabox:apenwarr");
378 s
.dump_schedule(log
);
380 // not much of a test, but oh well, it proves *something* :)
381 WVPASS(s
.tasks
.Count
> 0);
384 public static void Main()