public void SubGroupOrdering() { IProjectManager<Task, object> manager = new ProjectManager<Task, object>(); // create tasks in random order var a = new Task(); var b = new Task(); var c1 = new Task(); var c2 = new Task(); var d1 = new Task(); var d2 = new Task(); var d3 = new Task(); var e1 = new Task(); var e2 = new Task(); var e3 = new Task(); manager.Add(b); manager.Add(e1); manager.Add(a); manager.Add(e2); manager.Add(c1); manager.Add(d1); manager.Add(d2); manager.Add(e3); manager.Add(d3); manager.Add(c2); // setup: make sub groups manager.Group(a, b); manager.Group(b, c1); manager.Group(b, c2); manager.Group(c1, d1); manager.Group(c1, d2); manager.Group(c2, d3); manager.Group(d1, e1); manager.Group(d2, e2); manager.Group(d2, e3); // setup: make sub groups manager.Group(a, b); manager.Group(b, c1); manager.Group(b, c2); manager.Group(c1, d1); manager.Group(c1, d2); manager.Group(c2, d3); manager.Group(d1, e1); manager.Group(d2, e2); manager.Group(d2, e3); // test: check that order is correct Assert.IsTrue(manager.IndexOf(a) == 0, string.Format("Order a = {0} != {1}", manager.IndexOf(a), 0)); Assert.IsTrue(manager.IndexOf(b) == 1, string.Format("Order a = {0} != {1}", manager.IndexOf(b), 1)); Assert.IsTrue(manager.IndexOf(c1) == 2, string.Format("Order a = {0} != {1}", manager.IndexOf(c1), 2)); Assert.IsTrue(manager.IndexOf(d1) == 3, string.Format("Order a = {0} != {1}", manager.IndexOf(d1), 3)); Assert.IsTrue(manager.IndexOf(e1) == 4, string.Format("Order a = {0} != {1}", manager.IndexOf(d2), 4)); Assert.IsTrue(manager.IndexOf(d2) == 5, string.Format("Order a = {0} != {1}", manager.IndexOf(d3), 5)); Assert.IsTrue(manager.IndexOf(e2) == 6, string.Format("Order a = {0} != {1}", manager.IndexOf(e1), 6)); Assert.IsTrue(manager.IndexOf(e3) == 7, string.Format("Order a = {0} != {1}", manager.IndexOf(e2), 7)); Assert.IsTrue(manager.IndexOf(c2) == 8, string.Format("Order a = {0} != {1}", manager.IndexOf(e3), 8)); Assert.IsTrue(manager.IndexOf(d3) == 9, string.Format("Order a = {0} != {1}", manager.IndexOf(a), 9)); }
public void GroupTaskLevelAndOrdering() { IProjectManager<Task, object> manager = new ProjectManager<Task, object>(); var zero = new Task() { Name = "zero" }; var one = new Task() { Name = "one" }; var two = new Task() { Name = "two" }; var three = new Task() { Name = "three" }; var four = new Task() { Name = "four" }; var five = new Task() { Name = "five" }; manager.Add(zero); manager.Add(one); manager.Add(two); manager.Add(three); manager.Add(four); manager.Add(five); // single level ordering Assert.IsTrue(manager.IndexOf(zero) == 0); Assert.IsTrue(manager.IndexOf(one) == 1); Assert.IsTrue(manager.IndexOf(two) == 2); Assert.IsTrue(manager.IndexOf(three) == 3); Assert.IsTrue(manager.IndexOf(four) == 4); Assert.IsTrue(manager.IndexOf(five) == 5); Assert.IsTrue(manager.Tasks.Count() == 6); // two level ordering manager.Group(zero, two); manager.Group(zero, three); Assert.IsTrue(manager.IndexOf(zero) == 0); Assert.IsTrue(manager.IndexOf(two) == 1); Assert.IsTrue(manager.IndexOf(three) == 2); Assert.IsTrue(manager.IndexOf(one) == 3); Assert.IsTrue(manager.IndexOf(four) == 4); Assert.IsTrue(manager.IndexOf(five) == 5); Assert.IsTrue(manager.Tasks.Count() == 6); // three level ordering manager.Group(five, zero); Assert.IsTrue(manager.IndexOf(one) == 0); Assert.IsTrue(manager.IndexOf(four) == 1); Assert.IsTrue(manager.IndexOf(five) == 2, string.Format("Assert index == {0}; but index == {1}", 0, manager.IndexOf(five))); Assert.IsTrue(manager.IndexOf(zero) == 3); Assert.IsTrue(manager.IndexOf(two) == 4); Assert.IsTrue(manager.IndexOf(three) == 5); Assert.IsTrue(manager.Tasks.Count() == 6); // twin three level ordering manager.Group(four, one); Assert.IsTrue(manager.IndexOf(four) == 0); Assert.IsTrue(manager.IndexOf(one) == 1); Assert.IsTrue(manager.IndexOf(five) == 2, string.Format("Assert index == {0}; but index == {1}", 0, manager.IndexOf(five))); Assert.IsTrue(manager.IndexOf(zero) == 3); Assert.IsTrue(manager.IndexOf(two) == 4); Assert.IsTrue(manager.IndexOf(three) == 5); Assert.IsTrue(manager.Tasks.Count() == 6); // four level ordering manager.Group(two, four); Assert.IsTrue(manager.IndexOf(five) == 0, string.Format("Assert index == {0}; but index == {1}", 0, manager.IndexOf(five))); Assert.IsTrue(manager.IndexOf(zero) == 1); Assert.IsTrue(manager.IndexOf(two) == 2); Assert.IsTrue(manager.IndexOf(four) == 3); Assert.IsTrue(manager.IndexOf(one) == 4); Assert.IsTrue(manager.IndexOf(three) == 5); Assert.IsTrue(manager.Tasks.Count() == 6, string.Format("{0} != {1}", 6, manager.Tasks.Count())); // check parents Assert.IsTrue(manager.ParentOf(zero).Equals(five)); Assert.IsTrue(manager.ParentOf(one).Equals(four)); Assert.IsTrue(manager.ParentOf(two).Equals(zero)); Assert.IsTrue(manager.ParentOf(three).Equals(zero)); Assert.IsTrue(manager.ParentOf(four).Equals(two)); Assert.IsTrue(manager.ParentOf(five) == null); }
public void MoveTasksAroundSingleLevel() { IProjectManager<Task, object> manager = new ProjectManager<Task, object>(); // create tasks var one = new Task() { Name = "one" }; var two = new Task() { Name = "one" }; var three = new Task() { Name = "one" }; manager.Add(one); manager.Add(two); manager.Add(three); // get index of one Assert.IsTrue(manager.IndexOf(one) == 0); Assert.IsTrue(manager.IndexOf(two) == 1); Assert.IsTrue(manager.IndexOf(three) == 2); // move by 1 offset each time manager.Move(one, 1); Assert.IsTrue(manager.IndexOf(two) == 0, string.Format("{0} != {1}", 0, manager.IndexOf(two))); Assert.IsTrue(manager.IndexOf(one) == 1, string.Format("{0} != {1}", 1, manager.IndexOf(one))); Assert.IsTrue(manager.IndexOf(three) == 2, string.Format("{0} != {1}", 2, manager.IndexOf(three))); manager.Move(one, 1); Assert.IsTrue(manager.IndexOf(two) == 0); Assert.IsTrue(manager.IndexOf(three) == 1); Assert.IsTrue(manager.IndexOf(one) == 2); manager.Move(one, 1); Assert.IsTrue(manager.IndexOf(two) == 0); Assert.IsTrue(manager.IndexOf(three) == 1); Assert.IsTrue(manager.IndexOf(one) == 2); // move by 1 offset each time manager.Move(two, 1); Assert.IsTrue(manager.IndexOf(three) == 0); Assert.IsTrue(manager.IndexOf(two) == 1); Assert.IsTrue(manager.IndexOf(one) == 2); manager.Move(two, 1); Assert.IsTrue(manager.IndexOf(three) == 0); Assert.IsTrue(manager.IndexOf(one) == 1); Assert.IsTrue(manager.IndexOf(two) == 2); manager.Move(two, 1); Assert.IsTrue(manager.IndexOf(three) == 0); Assert.IsTrue(manager.IndexOf(one) == 1, string.Format("{0} != {1}", 1, manager.IndexOf(one))); Assert.IsTrue(manager.IndexOf(two) == 2, string.Format("{0} != {1}", 2, manager.IndexOf(two))); // move by -1 offset each time manager.Move(two, -1); Assert.IsTrue(manager.IndexOf(three) == 0); Assert.IsTrue(manager.IndexOf(two) == 1); Assert.IsTrue(manager.IndexOf(one) == 2); manager.Move(two, -1); Assert.IsTrue(manager.IndexOf(two) == 0); Assert.IsTrue(manager.IndexOf(three) == 1); Assert.IsTrue(manager.IndexOf(one) == 2); manager.Move(two, -1); Assert.IsTrue(manager.IndexOf(two) == 0); Assert.IsTrue(manager.IndexOf(three) == 1); Assert.IsTrue(manager.IndexOf(one) == 2); }
public void MoveSingleTaskToCheckForOutOfBoundHandling() { IProjectManager<Task, object> manager = new ProjectManager<Task, object>(); // create a task var first = new Task(); manager.Add(first); Assert.IsTrue(manager.Tasks.Count() == 1); // get task index var index = manager.IndexOf(first); Assert.IsTrue(index == 0, string.Format("Task index should be {0}, but is {1}", 0, index)); // move task by 0 offset manager.Move(first, 0); index = manager.IndexOf(first); Assert.IsTrue(index == 0); // move task by negative offset manager.Move(first, -1); index = manager.IndexOf(first); Assert.IsTrue(index == 0); // move task by count offset manager.Move(first, 1); index = manager.IndexOf(first); Assert.IsTrue(index == 0); // move task by positive offset more than count manager.Move(first, 2); index = manager.IndexOf(first); Assert.IsTrue(index == 0); }
public void MovePartBecomeMoveSplitTask() { IProjectManager<Task, object> manager = new ProjectManager<Task, object>(); var one = new Task(); var two = new Task(); var split = new Task(); var part1 = new Task(); var part2 = new Task(); manager.Add(one); manager.Add(two); manager.Add(split); // setup: create split task manager.Split(split, part1, part2, 1); Assert.IsTrue(manager.IsSplit(split)); Assert.IsTrue(manager.IsPart(part1)); Assert.IsTrue(manager.IsPart(part2)); Assert.IsTrue(manager.IndexOf(one) == 0); Assert.IsTrue(manager.IndexOf(two) == 1); Assert.IsTrue(manager.IndexOf(split) == 2); Assert.IsTrue(manager.IndexOf(part1) == -1); Assert.IsTrue(manager.IndexOf(part2) == -1); // test: move part and expect split task to move instead manager.Move(split, -1); Assert.IsTrue(manager.IndexOf(one) == 0); Assert.IsTrue(manager.IndexOf(split) == 1); Assert.IsTrue(manager.IndexOf(two) == 2); // test: move again manager.Move(split, -1); Assert.IsTrue(manager.IndexOf(split) == 0); Assert.IsTrue(manager.IndexOf(one) == 1); Assert.IsTrue(manager.IndexOf(two) == 2); // test: move again (no effect, reached the top) manager.Move(split, -1); Assert.IsTrue(manager.IndexOf(split) == 0); Assert.IsTrue(manager.IndexOf(one) == 1); Assert.IsTrue(manager.IndexOf(two) == 2); // test: move down manager.Move(split, 1); Assert.IsTrue(manager.IndexOf(one) == 0); Assert.IsTrue(manager.IndexOf(split) == 1); Assert.IsTrue(manager.IndexOf(two) == 2); // test: move out of bounds manager.Move(split, 2); Assert.IsTrue(manager.IndexOf(one) == 0); Assert.IsTrue(manager.IndexOf(two) == 1); Assert.IsTrue(manager.IndexOf(split) == 2); }
public void MoveNonExistingTask() { IProjectManager<Task, object> manager = new ProjectManager<Task, object>(); var task = new Task(); manager.Move(task, 1); Assert.IsTrue(manager.IndexOf(task) == -1); }
public void MoveGroupsAround() { IProjectManager<Task, object> manager = new ProjectManager<Task, object>(); // groups var group1 = new Task() { Name = "group1" }; var group2 = new Task() { Name = "group2" }; var group3 = new Task() { Name = "group3" }; // group 1 tasks var g1t1 = new Task() { Name = "g1t1" }; var g1t2 = new Task() { Name = "g1t2" }; var g1t3 = new Task() { Name = "g1t3" }; // group 2 tasks var g2t1 = new Task() { Name = "g2t1" }; var g2t2 = new Task() { Name = "g2t2" }; var g2t3 = new Task() { Name = "g2t3" }; // group 3 tasks var g3t1 = new Task() { Name = "g3t1" }; var g3t2 = new Task() { Name = "g3t2" }; var g3t3 = new Task() { Name = "g3t3" }; manager.Add(group1); manager.Add(group2); manager.Add(group3); manager.Add(g1t1); manager.Add(g1t2); manager.Add(g1t3); manager.Add(g2t1); manager.Add(g2t2); manager.Add(g2t3); manager.Add(g3t1); manager.Add(g3t2); manager.Add(g3t3); // make groups manager.Group(group1, g1t1); manager.Group(group1, g1t2); manager.Group(group1, g1t3); // make groups manager.Group(group2, g2t1); manager.Group(group2, g2t2); manager.Group(group2, g2t3); // make groups manager.Group(group3, g3t1); manager.Group(group3, g3t2); manager.Group(group3, g3t3); // confirm parents Assert.IsTrue(manager.ParentOf(group1) == null); Assert.IsTrue(manager.ParentOf(group2) == null); Assert.IsTrue(manager.ParentOf(group3) == null); Assert.IsTrue(manager.ParentOf(g1t1) == group1); Assert.IsTrue(manager.ParentOf(g1t2) == group1); Assert.IsTrue(manager.ParentOf(g1t3) == group1); Assert.IsTrue(manager.ParentOf(g2t1) == group2); Assert.IsTrue(manager.ParentOf(g2t2) == group2); Assert.IsTrue(manager.ParentOf(g2t3) == group2); Assert.IsTrue(manager.ParentOf(g3t1) == group3); Assert.IsTrue(manager.ParentOf(g3t2) == group3); Assert.IsTrue(manager.ParentOf(g3t3) == group3); // confirm order Assert.IsTrue(manager.IndexOf(group1) == 0); Assert.IsTrue(manager.IndexOf(g1t1) == 1); Assert.IsTrue(manager.IndexOf(g1t2) == 2); Assert.IsTrue(manager.IndexOf(g1t3) == 3); Assert.IsTrue(manager.IndexOf(group2) == 4); Assert.IsTrue(manager.IndexOf(g2t1) == 5); Assert.IsTrue(manager.IndexOf(g2t2) == 6); Assert.IsTrue(manager.IndexOf(g2t3) == 7); Assert.IsTrue(manager.IndexOf(group3) == 8); Assert.IsTrue(manager.IndexOf(g3t1) == 9); Assert.IsTrue(manager.IndexOf(g3t2) == 10); Assert.IsTrue(manager.IndexOf(g3t3) == 11); // move group under itself 1 (not allowed) manager.Move(group1, 1); Assert.IsTrue(manager.IndexOf(group1) == 0, string.Format("{0} != {1}", 0, manager.IndexOf(group1))); Assert.IsTrue(manager.IndexOf(g1t1) == 1); Assert.IsTrue(manager.IndexOf(g1t2) == 2); Assert.IsTrue(manager.IndexOf(g1t3) == 3); Assert.IsTrue(manager.IndexOf(group2) == 4); Assert.IsTrue(manager.IndexOf(g2t1) == 5); Assert.IsTrue(manager.IndexOf(g2t2) == 6); Assert.IsTrue(manager.IndexOf(g2t3) == 7); Assert.IsTrue(manager.IndexOf(group3) == 8); Assert.IsTrue(manager.IndexOf(g3t1) == 9); Assert.IsTrue(manager.IndexOf(g3t2) == 10); Assert.IsTrue(manager.IndexOf(g3t3) == 11); // move group under itself 2 (not allowed) manager.Move(group1, 2); Assert.IsTrue(manager.IndexOf(group1) == 0); Assert.IsTrue(manager.IndexOf(g1t1) == 1); Assert.IsTrue(manager.IndexOf(g1t2) == 2); Assert.IsTrue(manager.IndexOf(g1t3) == 3); Assert.IsTrue(manager.IndexOf(group2) == 4); Assert.IsTrue(manager.IndexOf(g2t1) == 5); Assert.IsTrue(manager.IndexOf(g2t2) == 6); Assert.IsTrue(manager.IndexOf(g2t3) == 7); Assert.IsTrue(manager.IndexOf(group3) == 8); Assert.IsTrue(manager.IndexOf(g3t1) == 9); Assert.IsTrue(manager.IndexOf(g3t2) == 10); Assert.IsTrue(manager.IndexOf(g3t3) == 11); // move group under itself 3 (not allowed) manager.Move(group1, 3); Assert.IsTrue(manager.IndexOf(group1) == 0); Assert.IsTrue(manager.IndexOf(g1t1) == 1); Assert.IsTrue(manager.IndexOf(g1t2) == 2); Assert.IsTrue(manager.IndexOf(g1t3) == 3); Assert.IsTrue(manager.IndexOf(group2) == 4); Assert.IsTrue(manager.IndexOf(g2t1) == 5); Assert.IsTrue(manager.IndexOf(g2t2) == 6); Assert.IsTrue(manager.IndexOf(g2t3) == 7); Assert.IsTrue(manager.IndexOf(group3) == 8); Assert.IsTrue(manager.IndexOf(g3t1) == 9); Assert.IsTrue(manager.IndexOf(g3t2) == 10); Assert.IsTrue(manager.IndexOf(g3t3) == 11); // move group under itself 4 (not allowed) manager.Move(group1, 4); Assert.IsTrue(manager.IndexOf(group2) == 0); Assert.IsTrue(manager.IndexOf(g2t1) == 1); Assert.IsTrue(manager.IndexOf(g2t2) == 2); Assert.IsTrue(manager.IndexOf(g2t3) == 3); Assert.IsTrue(manager.IndexOf(group1) == 4, string.Format("{0} != {1}", 0, manager.IndexOf(group1))); Assert.IsTrue(manager.IndexOf(g1t1) == 5, string.Format("{0} != {1}", 0, manager.IndexOf(g1t1))); Assert.IsTrue(manager.IndexOf(g1t2) == 6, string.Format("{0} != {1}", 0, manager.IndexOf(g1t2))); Assert.IsTrue(manager.IndexOf(g1t3) == 7, string.Format("{0} != {1}", 0, manager.IndexOf(g1t3))); Assert.IsTrue(manager.IndexOf(group3) == 8); Assert.IsTrue(manager.IndexOf(g3t1) == 9); Assert.IsTrue(manager.IndexOf(g3t2) == 10); Assert.IsTrue(manager.IndexOf(g3t3) == 11); // move group under another group manager.Move(group3, -1); Assert.IsTrue(manager.IndexOf(group2) == 0); Assert.IsTrue(manager.IndexOf(g2t1) == 1); Assert.IsTrue(manager.IndexOf(g2t2) == 2); Assert.IsTrue(manager.IndexOf(g2t3) == 3); Assert.IsTrue(manager.IndexOf(group1) == 4, string.Format("{0} != {1}", 0, manager.IndexOf(group1))); Assert.IsTrue(manager.IndexOf(g1t1) == 5, string.Format("{0} != {1}", 0, manager.IndexOf(g1t1))); Assert.IsTrue(manager.IndexOf(g1t2) == 6, string.Format("{0} != {1}", 0, manager.IndexOf(g1t2))); Assert.IsTrue(manager.IndexOf(group3) == 7); Assert.IsTrue(manager.IndexOf(g3t1) == 8); Assert.IsTrue(manager.IndexOf(g3t2) == 9); Assert.IsTrue(manager.IndexOf(g3t3) == 10); Assert.IsTrue(manager.IndexOf(g1t3) == 11, string.Format("{0} != {1}", 0, manager.IndexOf(g1t3))); // move group within group manager.Move(group3, -1); Assert.IsTrue(manager.IndexOf(group2) == 0); Assert.IsTrue(manager.IndexOf(g2t1) == 1); Assert.IsTrue(manager.IndexOf(g2t2) == 2); Assert.IsTrue(manager.IndexOf(g2t3) == 3); Assert.IsTrue(manager.IndexOf(group1) == 4, string.Format("{0} != {1}", 0, manager.IndexOf(group1))); Assert.IsTrue(manager.IndexOf(g1t1) == 5, string.Format("{0} != {1}", 0, manager.IndexOf(g1t1))); Assert.IsTrue(manager.IndexOf(group3) == 6); Assert.IsTrue(manager.IndexOf(g3t1) == 7); Assert.IsTrue(manager.IndexOf(g3t2) == 8); Assert.IsTrue(manager.IndexOf(g3t3) == 9); Assert.IsTrue(manager.IndexOf(g1t2) == 10, string.Format("{0} != {1}", 0, manager.IndexOf(g1t2))); Assert.IsTrue(manager.IndexOf(g1t3) == 11, string.Format("{0} != {1}", 0, manager.IndexOf(g1t3))); // move group out of another group manager.Move(group3, -2); Assert.IsTrue(manager.IndexOf(group2) == 0); Assert.IsTrue(manager.IndexOf(g2t1) == 1); Assert.IsTrue(manager.IndexOf(g2t2) == 2); Assert.IsTrue(manager.IndexOf(g2t3) == 3); Assert.IsTrue(manager.IndexOf(group3) == 4); Assert.IsTrue(manager.IndexOf(g3t1) == 5); Assert.IsTrue(manager.IndexOf(g3t2) == 6); Assert.IsTrue(manager.IndexOf(g3t3) == 7); Assert.IsTrue(manager.IndexOf(group1) == 8, string.Format("{0} != {1}", 0, manager.IndexOf(group1))); Assert.IsTrue(manager.IndexOf(g1t1) == 9, string.Format("{0} != {1}", 0, manager.IndexOf(g1t1))); Assert.IsTrue(manager.IndexOf(g1t2) == 10, string.Format("{0} != {1}", 0, manager.IndexOf(g1t2))); Assert.IsTrue(manager.IndexOf(g1t3) == 11, string.Format("{0} != {1}", 0, manager.IndexOf(g1t3))); }