Esempio n. 1
0
        /// <summary>
        /// A test for Broadcast With Acknowledgement
        /// </summary>
        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);
            }
        }
Esempio n. 2
0
        public override void Deserialize( GenericReader reader )
        {
            base.Deserialize( reader );

            int version = reader.ReadEncodedInt();

            m_SideLength = reader.ReadEncodedInt();

            m_Path = new Node[reader.ReadEncodedInt()];
            for ( int i = 0; i < m_Path.Length; i++ )
            {
                m_Path[i] = new Node( reader.ReadEncodedInt(), reader.ReadEncodedInt() );
            }
        }
Esempio n. 3
0
        public void InitPath()
        {
            // Depth-First Search algorithm

            int totalNodes = SideLength * SideLength;

            Node[] stack = new Node[totalNodes];
            Node current = stack[0] = new Node( 0, 0 );
            int stackSize = 1;

            bool[,] visited = new bool[SideLength, SideLength];
            visited[0, 0] = true;

            while ( true )
            {
                PathDirection[] choices = new PathDirection[4];
                int count = 0;

                if ( current.X > 0 && !visited[current.X - 1, current.Y] )
                    choices[count++] = PathDirection.Left;

                if ( current.Y > 0 && !visited[current.X, current.Y - 1] )
                    choices[count++] = PathDirection.Up;

                if ( current.X < SideLength - 1 && !visited[current.X + 1, current.Y] )
                    choices[count++] = PathDirection.Right;

                if ( current.Y < SideLength - 1 && !visited[current.X, current.Y + 1] )
                    choices[count++] = PathDirection.Down;

                if ( count > 0 )
                {
                    PathDirection dir = choices[Utility.Random( count )];

                    switch ( dir )
                    {
                        case PathDirection.Left:
                            current = new Node( current.X - 1, current.Y );
                            break;
                        case PathDirection.Up:
                            current = new Node( current.X, current.Y - 1 );
                            break;
                        case PathDirection.Right:
                            current = new Node( current.X + 1, current.Y );
                            break;
                        default:
                            current = new Node( current.X, current.Y + 1 );
                            break;
                    }

                    stack[stackSize++] = current;

                    if ( current.X == SideLength - 1 && current.Y == SideLength - 1 )
                        break;

                    visited[current.X, current.Y] = true;
                }
                else
                {
                    current = stack[--stackSize - 1];
                }
            }

            m_Path = new Node[stackSize];

            for ( int i = 0; i < stackSize; i++ )
            {
                m_Path[i] = stack[i];
            }

            if ( m_User != null )
            {
                m_User.CloseGump( typeof( GameGump ) );
                m_User = null;
            }
        }
Esempio n. 4
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();
        }
Esempio n. 5
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);
        }
Esempio n. 6
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);
        }
Esempio n. 7
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]);
                }
            }
        }
Esempio n. 8
0
        public void SurrogateIdTest()
        {
            // Target 1
            Node target = new Node(1406, null); // TODO: Initialize to an appropriate value
            uint actual;
            actual = target.SurrogateId(2450);
            Assert.AreEqual<uint>(actual, 3454);

            // Target 2
            Node target2 = new Node(1, null); // TODO: Initialize to an appropriate value
            uint actual2;
            actual2 = target2.SurrogateId(2);
            Assert.AreEqual<uint>(actual2, 3);

            // Target 3
            Node target3 = new Node(1, null); // TODO: Initialize to an appropriate value
            uint actual3;
            actual3 = target3.SurrogateId(1406);
            Assert.AreEqual<uint>(actual3, 1025);
        }
Esempio n. 9
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");
        }
Esempio n. 10
0
        public void ParentIdTest()
        {
            // Target 1
            Node target = new Node(3454, null); // TODO: Initialize to an appropriate value
            uint actual;
            actual = target.ParentId;
            Assert.AreEqual<uint>(actual, 1406);

            // Target 2
            Node target2 = new Node(1, null); // TODO: Initialize to an appropriate value
            uint actual2;
            actual2 = target2.ParentId;
            Assert.AreEqual<uint>(actual2, 0);

            // Target 3
            Node target3 = new Node(2048, null); // TODO: Initialize to an appropriate value
            uint actual3;
            actual3 = target3.ParentId;
            Assert.AreEqual<uint>(actual3, 0);

            // Target 4
            Node target4 = new Node(2, null); // TODO: Initialize to an appropriate value
            uint actual4;
            actual4 = target4.ParentId;
            Assert.AreEqual<uint>(actual4, 0);
        }
Esempio n. 11
0
        public void ChildIdTest()
        {
            // Target 1
            Node target = new Node(1406, null); // TODO: Initialize to an appropriate value
            uint actual;
            actual = target.ChildId(1406);
            Assert.AreEqual<uint>(actual, 3454);

            // Target 2
            Node target2 = new Node(0, null); // TODO: Initialize to an appropriate value
            uint actual2;
            actual2 = target2.ChildId(0);
            Assert.AreEqual<uint>(actual2, 1);

            // Target 3
            Node target3 = new Node(0, null); // TODO: Initialize to an appropriate value
            uint actual3;
            actual3 = target3.ChildId(1406);
            Assert.AreEqual<uint>(actual3, 2048);

            // Target 4
            Node target4 = new Node(0, null); // TODO: Initialize to an appropriate value
            uint actual4;
            actual4 = target4.ChildId(1);
            Assert.AreEqual<uint>(actual4, 2);
        }