Example #1
0
        public void BroadcastWithAckTest(uint size, uint startnode)
        {
            //First, create a hyperweb with 6 nodes in it.
            Node root = new Node(null);
            List<Node> AllNodes = new List<Node>(new Node[] { root });
            for (int i = 0; i < size; i++)
            {
                Node n = new Node(null);
                root.InsertNode(n);
                AllNodes.Add(n);
            }

            //Now create a message visitor and broadcast it.
            MessageVisitor v = new MessageVisitor("First");
            uint Retval = AllNodes[(int)startnode].BroadcastWithAck(v, 0);
            uint Expected = (uint)AllNodes.Count;

            //Now make sure that all nodes have exactly one copy of that message.
            foreach (Node n in AllNodes)
            {
                List<string> Messages = (List<string>)n.Payload["Messages"];
                Assert.AreEqual(1, Messages.Count);
                Assert.AreEqual("First", Messages[0]);
                Assert.AreEqual(Expected, Retval);
            }
        }
Example #2
0
        private void InsertNodeTestCreate(uint size)
        {
            //Refresh the whole hyperweb to size+1 nodes (including root)
            Node root = new Node(null);

            var curStat = root.CurrentState;
            for (uint j = 0; j < size; j++)
                root.InsertNode(new Node(null));

            //And add the node n+2, at insertion point i.
            root.InsertNode(new Node(null));

            string actual = root.DumpAllNodes();

            TextWriter tr = new StreamWriter(File.OpenWrite(@"C:\Users\joel.day3\Documents\Visual Studio 2008\Projects\school\cs340project\cs340project\UnitTesting\TestNodeData\" + (size + 1).ToString() + "Nodes.txt"));
            tr.Write(actual);
            tr.Close();
        }
Example #3
0
        private static void RemoveNodeTest(uint size, uint removeFrom, uint removeAt, string expected)
        {
            //Refresh the whole hyperweb to size+1 nodes (including root)
            Node root = new Node(null);
            List<Node> AllNodes = new List<Node>(new Node[] { root });
            for (uint j = 0; j < size; j++)
            {
                Node n2 = new Node(null);
                root.InsertNode(n2);
                AllNodes.Add(n2);
            }

            //Remove the node they wanted us to.
            var n = AllNodes[(int)removeFrom].RemoveById(removeAt);

            string actual = n.DumpAllNodes();
            if (expected != actual)
                Assert.Fail("Failed on size " + size + ", removeAt " + removeAt);
        }
Example #4
0
        /// <summary>
        /// Insert test.
        /// 
        /// This is the main body of the Insert Test.
        /// </summary>
        /// <param name="size">The size of the web.</param>
        /// <param name="insertAt">The insertAt point.</param>
        /// <param name="expected">The expected output.</param>
        private static void InsertNodeTest(uint size, uint insertAt, string expected)
        {
            //Refresh the whole hyperweb to size+1 nodes (including root)
            Node root = new Node(null);

            var curStat = root.CurrentState;
            List<Node> AllNodes = new List<Node>(new Node[] { root });
            for (uint j = 0; j < size; j++) {
                Node n = new Node(null);
                root.InsertNode(n);
                AllNodes.Add(n);
            }

            //And add the node n+2, at insertion point i.
            Node n2 = new Node(null);
            AllNodes[(int)insertAt].InsertNode(n2);

            string actual = root.DumpAllNodes();
            if (expected != actual)
                Assert.Fail("Failed on size " + size + ", insertAt " + insertAt + ":\n\n" + expected + "\n\n" + actual);
        }
Example #5
0
        /// <summary>
        ///A test for Broadcast
        ///</summary>
        public void VisitTest(uint size, uint startnode)
        {
            //First, create a hyperweb with 6 nodes in it.
            Node root = new Node(null);
            List<Node> AllNodes = new List<Node>(new Node[] { root });
            for (int i = 0; i < size; i++)
            {
                Node n = new Node(null);
                root.InsertNode(n);
                AllNodes.Add(n);
            }

            //Now create a message visitor and broadcast it.
            MessageVisitor v = new MessageVisitor("First");

            uint rand = (uint)(new Random(12123)).Next(0, (int)size - 1);

            AllNodes[(int)startnode].Send(v, rand);

            //Now make sure that all nodes have exactly one copy of that message.
            foreach (Node n in AllNodes)
            {
                if (n.Id == rand)
                {
                    List<string> Messages = (List<string>)n.Payload["Messages"];
                    Assert.AreEqual(1, Messages.Count);
                    Assert.AreEqual("First", Messages[0]);
                }
            }
        }
Example #6
0
        public void RemoveTest()
        {
            TextReader tr = new StreamReader(Assembly.GetExecutingAssembly()
             .GetManifestResourceStream("UnitTesting.TestNodeData.2Nodes.txt"));
            string expected = tr.ReadToEnd();

            Node root = new Node(null);
            List<Node> AllNodes = new List<Node>(new Node[] { root });
            for (uint j = 0; j < 3; j++)
            {
                Node n = new Node(null);
                root.InsertNode(n);
                AllNodes.Add(n);
            }

            //Remove the node they wanted us to.
            AllNodes[3].RemoveById(3);

            string actual = root.DumpAllNodes();
            if (expected != actual)
                Assert.Fail("Failed on size 4");
        }