Esempio n. 1
0
        public void DepthFirstTraversal(T start, VisitorDelegate <T> whatToDo)
        {
            //Get the starting vertex
            Vertex <T> startVertex = GetVertex(start);

            //Reference to the current vertex
            Vertex <T> currentVertex = null;

            //Dictionary to track the vertices already visited <T,T>
            Dictionary <T, T> visited = new Dictionary <T, T>(NumVertices);

            //Stack to store the current nodes neighbours
            Stack <Vertex <T> > stVertex = new Stack <Vertex <T> >();

            //Push the starting vertex onto the stack
            stVertex.Push(startVertex);

            //while there are vertices on the stack
            while (stVertex.Count > 0)
            {
                currentVertex = stVertex.Pop();                                                     //Current vertex <-- pop top item off of the stack
                if (!visited.ContainsKey(currentVertex.Data))                                       //If the current vertex has NOT been visited
                {
                    whatToDo(currentVertex.Data);                                                   //Process the current vertex
                    visited.Add(currentVertex.Data, currentVertex.Data);                            //Mark as visited
                    IEnumerable <Vertex <T> > neighbours = EnumerateNeighbours(currentVertex.Data); //Get a list of neighbours for current vertex (helper function)

                    foreach (Vertex <T> vt in neighbours)                                           //For each vertex in the list
                    {
                        stVertex.Push(vt);                                                          //Push vertex onto stack
                    }
                }
            }
        }
Esempio n. 2
0
        protected override void Execute(IntPtr bridgeFunc, IProgressMonitor subMonitor)
        {
            using (subMonitor.BeginTask("Exploring " + File.Name, 100))
            {
                BoostTestExploreDelegate bridge =
                    (BoostTestExploreDelegate)Marshal.GetDelegateForFunctionPointer(
                        bridgeFunc,
                        typeof(BoostTestExploreDelegate)
                    );

                VisitorDelegate visitTestCase = new VisitorDelegate(VisitTestCase);
                VisitorDelegate beginVisitTestSuite = new VisitorDelegate(BeginVisitTestSuite);
                VisitorDelegate endVisitTestSuite = new VisitorDelegate(EndVisitTestSuite);

                ErrorReporterDelegate errorReporter =
                    new ErrorReporterDelegate((text) => Logger.Log(LogSeverity.Error, text));

                bridge(
                    File.FullName,

                    visitTestCase,
                    beginVisitTestSuite,
                    endVisitTestSuite,

                    errorReporter
                );

                TestModelSerializer.PublishTestModel(TestModel, MessageSink);
            }
        }
Esempio n. 3
0
        public void BreadthFirstTraversal(T start, VisitorDelegate <T> whatToDo)
        {
            //get the starting vertex
            Vertex <T> vStart = GetVertex(start);
            //referance to the current vertex
            Vertex <T> vCurrent;
            //Dictionary to track the vertices already visited
            Dictionary <T, T> visitedVertices = new Dictionary <T, T>();
            //queue to store unprocessed neughbours
            Queue <Vertex <T> > verticesRemaining = new Queue <Vertex <T> >();

            verticesRemaining.Enqueue(vStart);
            while (verticesRemaining.Count != 0)
            {
                vCurrent = verticesRemaining.Dequeue();
                if (!visitedVertices.ContainsKey(vCurrent.Data))
                {
                    whatToDo(vCurrent.Data);
                    visitedVertices.Add(vCurrent.Data, vCurrent.Data);

                    foreach (Vertex <T> v in EnumerateNeighbors(vCurrent.Data))
                    {
                        verticesRemaining.Enqueue(v);
                    }
                }
            }
        }
Esempio n. 4
0
        private void MakeTree <T>(T fragment, VisitorDelegate <T> visitor) where T : TSqlFragment
        {
            var current = new SqlServerRawTree(typeof(T).Name);

            if (_stack.TryPeek(out var parent))
            {
                parent.AddChild(current);
            }
            else if (Root == null)
            {
                Root = current;
            }
            else
            {
                throw new InvalidOperationException();
            }

            _stack.Push(current);
            visitor(fragment);
            _stack.Pop();

            if (current.ChildrenCount == 0)
            {
                var builder = new StringBuilder();

                for (int i = fragment.FirstTokenIndex; i <= fragment.LastTokenIndex; i++)
                {
                    builder.Append(fragment.ScriptTokenStream[i].Text);
                }

                current.AddChild(new SqlServerRawTreeTerminalNode(builder.ToString()));
            }

            current.Freeze();
        }
Esempio n. 5
0
        public void TestStrategy()
        {
            var flagship        = new Mock <Flagship.Main.Fs>();
            var visitorDelegate = new VisitorDelegate(null, true, new Dictionary <string, object>(), false, configManager.Object);
            var privateVisitor  = new PrivateObject(visitorDelegate);

            privateVisitor.Invoke("GetStrategy");
        }
        private static void TraverseHierarchy(GameObject go, VisitorDelegate visitor, int depth)
        {
            visitor(go, depth);

            foreach (Transform t in go.transform)
            {
                TraverseHierarchy(t.gameObject, visitor, depth + 1);
            }
        }
 public static void TraverseHierarchy(this GameObject go, VisitorDelegate visitor)
 {
     if (go == null)
     {
         throw new ArgumentNullException("go");
     }
     if (visitor == null)
     {
         throw new ArgumentNullException("visitor");
     }
     TraverseHierarchy(go, visitor, 0);
 }
Esempio n. 8
0
    void visit(string[] argv, compilation_unitList asts, TextWriter w)
    {
        compilation ast = new compilation(argv, asts, imports.global);

        ast.link(null);
        for (int i = 0; i < visitors.Count && ast != null; i++)
        {
            VisitorDelegate visitor = visitors[i];
            string[]        args    = (string[])visitorArgs[i];

            ast = visitor(ast, w, args, Msg);
        }
    }
Esempio n. 9
0
        private VisitorDelegate FindVisitor(Type partType)
        {
            VisitorDelegate visitor = null;

            if (!_visitors.TryGetValue(partType, out visitor))
            {
                if (partType != typeof(Part) && partType != typeof(object))
                {
                    visitor = FindVisitor(partType.BaseType);
                    _visitors.Add(partType, visitor);
                }
            }
            return(visitor);
        }
Esempio n. 10
0
        public void VisitorDelegateTest1()
        {
            var context = new Dictionary <string, object>()
            {
                ["key"]  = "value",
                ["key2"] = 4,
                ["key3"] = true
            };

            var visitor = new VisitorDelegate(visitorId, false, context, false, configManager.Object);

            Assert.AreEqual(visitor.AnonymousId, null);
            Assert.AreEqual(visitorId, visitor.VisitorId);
            Assert.IsFalse(visitor.HasConsented);
            Assert.AreEqual(visitor.Context.Count, 5);
            Assert.AreEqual(visitor.Flags.Count, 0);
        }
Esempio n. 11
0
        public NoConsentStrategyTests()
        {
            fsLogManagerMock = new Mock <IFsLogManager>();
            config           = new Flagship.Config.DecisionApiConfig()
            {
                EnvId      = "envID",
                LogManager = fsLogManagerMock.Object,
            };
            trackingManagerMock = new Mock <Flagship.Api.ITrackingManager>();
            decisionManagerMock = new Mock <Flagship.Decision.DecisionManager>(new object[] { null, null });
            var configManager = new Flagship.Config.ConfigManager(config, decisionManagerMock.Object, trackingManagerMock.Object);

            var context = new Dictionary <string, object>()
            {
                ["key0"] = 1,
            };

            visitorDelegate = new Flagship.FsVisitor.VisitorDelegate("visitorId", false, context, false, configManager);
        }
Esempio n. 12
0
        public void VisitorDelegateTest()
        {
            var visitor = new VisitorDelegate(visitorId, false, context, false, configManager.Object);

            Assert.IsNull(visitor.AnonymousId);
            Assert.AreEqual(visitorId, visitor.VisitorId);
            Assert.IsFalse(visitor.HasConsented);
            Assert.AreEqual(visitor.Context.Count, 3);
            Assert.AreEqual(visitor.Flags.Count, 0);

            visitor = new VisitorDelegate(null, false, context, false, configManager.Object);
            Assert.IsNotNull(visitor.VisitorId);
            Assert.AreEqual(visitor.VisitorId.Length, 19);

            visitor = new VisitorDelegate(visitorId, true, context, false, configManager.Object);
            Assert.IsNotNull(visitor.AnonymousId);
            Assert.AreEqual(visitorId, visitor.VisitorId);
            Assert.AreEqual(36, visitor.AnonymousId.Length);
        }
Esempio n. 13
0
    public bool AddVisitor(System.Type type, string[] args)
    {
        checkArg(type, "classname");
        checkArg(args, "args");

        MethodInfo m = type.GetMethod("visit",
                                      new System.Type[] { typeof(compilation),
                                                          typeof(TextWriter),
                                                          typeof(string[]),
                                                          typeof(MessageWriter) });

        if (m != null && m.IsStatic && m.IsPublic && m.ReturnType == typeof(compilation))
        {
            VisitorDelegate visitor
                = (VisitorDelegate)VisitorDelegate.CreateDelegate(typeof(VisitorDelegate), m);
            return(AddVisitor(visitor, args));
        }
        Console.WriteLine("Couldn't find visit method on {0}", type);
        return(false);
    }
Esempio n. 14
0
        public void DepthFirstTraversal(T start, VisitorDelegate <T> whatToDo)
        {
            //get the starting vertex
            Vertex <T> vStart = GetVertex(start);
            //referance to the current vertex
            Vertex <T> vCurrent;
            //Dictionary to track the vertices already visited
            Dictionary <T, T> visitedVertices = new Dictionary <T, T>();
            //stack to store unprocessed neughbours
            Stack <Vertex <T> > verticesRemaining = new Stack <Vertex <T> >();

            /*
             * Push start vertex onto the stack
             * while the stack is not empty
             *  current <-- pop top off the stack
             *  if current has not been visited yet
             *      process the current vertex (call the delegate)
             *      add current to the visited list
             *      for each neighbour of current
             *          push current neighbour onto the stack
             */
            verticesRemaining.Push(vStart);
            while (verticesRemaining.Count != 0)
            {
                vCurrent = verticesRemaining.Pop();
                if (!visitedVertices.ContainsKey(vCurrent.Data))
                {
                    whatToDo(vCurrent.Data);
                    visitedVertices.Add(vCurrent.Data, vCurrent.Data);

                    foreach (Vertex <T> v in EnumerateNeighbors(vCurrent.Data))
                    {
                        verticesRemaining.Push(v);
                    }
                }
            }
        }
Esempio n. 15
0
 public TreeRewriterVisitor(NadirTreePatternMatcher matcher, VisitorDelegate pre, VisitorDelegate post)
     {
     this.matcher = matcher;
     this.pre     = pre;
     this.post    = post;
     }
Esempio n. 16
0
        protected override void Execute(IntPtr bridgeFunc, IProgressMonitor subMonitor)
        {
            subMonitor_ = subMonitor;
            taskStarted_ = false;

            BoostTestRunDelegate bridge =
                (BoostTestRunDelegate)Marshal.GetDelegateForFunctionPointer(
                    bridgeFunc,
                    typeof(BoostTestRunDelegate)
                );

            VisitorDelegate visitTestCase = new VisitorDelegate(VisitTestCase);
            VisitorDelegate beginVisitTestSuite = new VisitorDelegate(BeginVisitTestSuite);
            VisitorDelegate endVisitTestSuite = new VisitorDelegate(EndVisitTestSuite);
            VisitorDelegate shouldSkip = new VisitorDelegate(ShouldSkip);

            TestStartDelegate testStart = new TestStartDelegate(TestStart);
            TestDelegate testFinish = new TestDelegate(TestFinish);
            TestDelegate testAborted = new TestDelegate(TestAborted);
            TestUnitDelegate testUnitStart = new TestUnitDelegate(TestUnitStart);
            TestUnitFinishedDelegate testUnitFinish = new TestUnitFinishedDelegate(TestUnitFinish);
            TestUnitDelegate testUnitSkipped = new TestUnitDelegate(TestUnitSkipped);
            TestUnitDelegate testUnitAborted = new TestUnitDelegate(TestUnitAborted);
            AssertionResultDelegate assertionResult = new AssertionResultDelegate(AssertionResult);
            ExceptionCaughtDelegate exceptionCaught = new ExceptionCaughtDelegate(ExceptionCaught);

            ErrorReporterDelegate errorReporter =
                new ErrorReporterDelegate((text) => Logger.Log(LogSeverity.Error, text));

            bridge(
                File.FullName,

                visitTestCase,
                beginVisitTestSuite,
                endVisitTestSuite,
                shouldSkip,

                testStart,
                testFinish,
                testAborted,
                testUnitStart,
                testUnitFinish,
                testUnitSkipped,
                testUnitAborted,
                assertionResult,
                exceptionCaught,

                errorReporter
            );

            // Cancel all tests that were not completed, if any.
            while (testStepsStack_.Count > 0)
            {
                TestResult result = testResultsStack_.Pop();
                result.Outcome = TestOutcome.Canceled;

                MessageSink.Publish(
                    new TestStepFinishedMessage
                    {
                        StepId = testStepsStack_.Pop().Id,
                        Result = result
                    }
                );
            }

            if (taskStarted_) taskCookie_.Dispose();
        }
Esempio n. 17
0
 public bool AddVisitor(VisitorDelegate visitor, string[] args)
 {
     visitors.Add(visitor);
     visitorArgs.Add(args.Clone());
     return(true);
 }
Esempio n. 18
0
 public bool AddVisitor(VisitorDelegate visitor)
 {
     return(AddVisitor(visitor, new string[0]));
 }