Beispiel #1
0
        public void ComplexOtherTest()
        {
            var names = new List <string>();
            var set   = new GraphSet <string>();
            var three = set.Add("3");

            three.AddChild("4");
            var two2 = three.AddParent("2");
            var two  = three.AddParent("Two");

            two.AddChild("Three");
            two.AddParent("One");
            var un = two.AddParent("Un");

            un.AddChild(two2);

            var gtf = set.Add("greatfather");
            var gtm = set.Add("greatmother");
            var gf  = gtf.AddChild("grandfather");

            gtm.AddChild(gf);
            var f = gf.AddChild("father");

            f.AddChild("me");
            var taskGraph = set.ToTaskGraph(x => { OnNames(names, x); });
            var tasks     = taskGraph.GetNodes().Select(x => x.Value.Task).ToArray();

            Assert.Equal(12, tasks.Length);
            var task = Task.Factory.ContinueWhenAll(tasks, x => { });

            task.Wait();
            lock (_synchro)
            {
                Assert.False(_error, "Names contains " + names.FirstOrDefault());
                if (names.Count != 12)
                {
                    var message = "Names: " + string.Join(", ", names);
                    Assert.False(true, message);
                }
                Assert.True(names.IndexOf("3") < names.IndexOf("4"));
                Assert.True(names.IndexOf("Two") < names.IndexOf("3"));
                Assert.True(names.IndexOf("One") < names.IndexOf("Two"),
                            "One: " + names.IndexOf("One") + " Two: " + names.IndexOf("Two"));
                Assert.True(names.IndexOf("Un") < names.IndexOf("Two"));
                Check.That(names).Contains("One");
                Check.That(names).Contains("Two");
                Check.That(names).Contains("Three");
                Check.That(names).Contains("4");
                Check.That(names).Contains("Un");
                Check.That(names).Contains("father");
                Check.That(names).Contains("me");
                Check.That(names).Contains("grandfather");
                Check.That(names).Contains("greatfather");
                Check.That(names).Contains("greatmother");
            }
        }
Beispiel #2
0
        public void ContinueOnLeavesThenContinueWithTest()
        {
            var names = new List <string>();
            var set   = new GraphSet <string>();
            var three = set.Add("3");

            three.AddChild("4");
            var two2 = three.AddParent("2");
            var two  = three.AddParent("Two");

            two.AddChild("Three");
            two.AddParent("One");
            var un = two.AddParent("Un");

            un.AddChild(two2);

            var gtf = set.Add("greatfather");
            var gtm = set.Add("greatmother");
            var gf  = gtf.AddChild("grandfather");

            gtm.AddChild(gf);
            var f = gf.AddChild("father");

            f.AddChild("me");
            var taskGraph  = set.ToTaskGraph(x => { OnNames(names, x); });
            var taskLeaves = taskGraph.ContinueOnLeavesWith(OnLeaves);

            taskLeaves.GetWhenAllTask().Wait();
            var taskCombined = taskGraph.ContinueWith(x => { OnRemoveNames(names, x); });
            var task         = taskCombined.GetWhenAllTask();

            task.Wait();
            //Thread.Sleep(1000);
            lock (_synchro)
            {
                Assert.False(_error, "Names contains " + names.FirstOrDefault());
                Assert.Equal(0, names.Count);
                Assert.True(_removeNames.IndexOf("3") < _removeNames.IndexOf("4"));
                Assert.True(_removeNames.IndexOf("Two") < _removeNames.IndexOf("3"));
                Assert.True(_removeNames.IndexOf("One") < _removeNames.IndexOf("Two"));
                Assert.True(_removeNames.IndexOf("Un") < _removeNames.IndexOf("Two"));
            }
        }
Beispiel #3
0
        public void ContinueWithTest()
        {
            var names = new List <string>();
            var set   = new GraphSet <string>();
            var three = set.Add("3");

            three.AddChild("4");
            var two2 = three.AddParent("2");
            var two  = three.AddParent("Two");

            two.AddParent("One");
            var un = two.AddParent("Un");

            un.AddChild(two2);
            var taskGraph    = set.ToTaskGraph(x => { OnNames(names, x); });
            var taskCombined = taskGraph.ContinueWith(x => { OnRemoveNames(names, x); });
            var task         = taskCombined.GetWhenAllTask();

            task.Wait();
            Assert.Equal(0, names.Count);
            Assert.False(_error);
        }