Beginnings of a switch to use latest wvdotnet library.
[schedulator.git] / schedulator.t.cs
blob2a425708c61cdbfb5cd7297e7b04d853175ead68
1 #include "wvtest.cs.h"
2 using System;
3 using System.IO;
4 using System.Collections;
5 using Wv;
6 using Wv.Test;
7 using Wv.Schedulator;
9 [TestFixture]
10 public class SchedTests
12 WvLog log = new WvLog("Tests");
13 Schedulator s;
14 SourceRegistry reg;
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);
28 // s.dump(log);
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);
71 //s.dump(log);
72 check_tasks(correct);
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();
85 src.make_basic();
86 s.ran_phase = Schedulator.Phase.Tasks;
87 s.run_until(Schedulator.Phase.Sort2);
89 //s.dump(log);
90 check_tasks(correct);
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!");
104 dosplit("", "");
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)
121 int max = 0;
122 foreach (string[] list in lists)
123 max += list.Length;
124 string[] outlist = new string[max];
125 int i = 0;
126 foreach (string[] list in lists)
127 foreach (string s in list)
128 outlist[i++] = s;
129 return outlist;
132 Task[] lookup_all(TaskList tasks, string[] list)
134 Task[] outlist = new Task[list.Length];
135 int i = 0;
136 foreach (string name in list)
138 Task t = tasks.FindByName(name);
139 if (t == null)
140 t = tasks.FindById(name);
141 if (t == null)
142 throw new ArgumentException
143 ("can't find task named '" + name + "'");
144 outlist[i++] = t;
146 return outlist;
149 [Test] [Category("Silly2")] public void stringsource_test()
151 reg.create(s, "s1", "file:test1.sched");
152 s.run_until(Schedulator.Phase.Sort2);
153 s.dump(log);
155 FixFor ff = s.fixfors.Find(s.projects.Find("Weaver"), "Wv 1.0");
156 WVPASSEQ(ff.releases.Count, 4);
158 string[] finished = {
159 "Third",
161 string[] undecided = {
162 "t:2",
163 "Bug without fixfor",
165 string[] v2_0 = {
166 "Unestimated \"Wv 2.0\" stuff",
167 "Unestimated one",
168 "Unestimated two",
169 "More Unestimated Wv \"2.0\" stuff",
171 string[] v1_0 = {
172 "bug:983",
173 "Sub-bug one",
174 "Sub-bug two estimate \"in title [1d]\"",
175 "Sub-bug two and a half",
176 "Sub-bug three",
177 "Do some stuff",
178 "First",
179 "Second",
180 "Two",
181 "Do \"more stuff\"",
182 "One",
183 "Three",
186 s.dump(log);
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);
215 s.dump(log);
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.
225 "t:5", "t:6",
226 "t:8", "t:7", // done dates come after no done dates
227 "Third",
229 string[] undecided = {
230 "t:4", "t:200", "t:100",
232 string[] v1_0 = {
233 "t:3", // because it was created first
234 "bug:983",
235 "Sub-bug one",
236 "Sub-bug two estimate \"in title [1d]\"",
237 "Sub-bug two and a half",
238 "Sub-bug three",
239 "Do some stuff", // low priority bug
240 "First",
241 "Second",
242 "Two",
243 "Do \"more stuff\"",
244 "One", // child of a lower-priority bug than t3
245 "Three",
247 string[] v2_0 = {
248 "t:2", // because it was created first
249 "Bug without fixfor", // lower priority
250 "Unestimated \"Wv 2.0\" stuff",
251 "Unestimated one",
252 "Unestimated two",
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);
266 s.dump(log);
268 string[] all = {
269 "t:5", "t:6", "t:8", "t:7",
270 "t:4", "t:200", "t:100",
271 "t:3",
273 "child1",
274 "child1a",
275 "child2",
276 "t:1", "t:2",
277 "child1b",
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);
286 s.dump(log);
288 string[] all = {
289 "Top1",
290 "1.1", "1.1.1", "1.1.2",
291 "1.2", "1.2.1", "1.2.2",
292 "Top2",
293 "2.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};" +
303 "uid={2};pwd={3};",
304 "localhost", "fogbugz", "root", "scs");
305 reg.create(s, "bug", "fogbugz:" + odbcstr + ":apenwarr");
306 s.run_until(Schedulator.Phase.Sort2);
307 //s.dump(log);
310 [Test] [Category("mantis")] public void mantis_test()
312 string odbcstr = String.Format
313 ("driver={{MySQL}};" +
314 "server={0};database={1};" +
315 "uid={2};pwd={3};",
316 "localhost", "mantis", "root", "scs");
317 reg.create(s, "bug", "mantis:" + odbcstr + ":wooi");
318 s.run_until(Schedulator.Phase.Sort2);
319 s.dump(log);
322 [Test] [Category("Silly10")] public void schedule_test()
324 reg.create(s, "ts", "file:test10.sched");
325 s.run();
326 s.dump(log);
327 s.dump_schedule(log);
330 [Test] [Category("Silly11")] public void schedule_test2()
332 reg.create(s, "ts", "file:test11.sched");
333 s.run();
334 s.dump(log);
335 s.dump_schedule(log);
337 TaskTimeSlot[] slots = new TaskTimeSlot[s.schedule.Count];
338 int total = 0;
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");
369 s.run();
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");
376 s.run();
377 // s.dump(log);
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()
386 WvTest.DoMain();