예제 #1
0
        public void AddTrackBlockTest()
        {
            TrackController target = new TrackController(); // TODO: Initialize to an appropriate value
            TrackBlock block = null; // TODO: Initialize to an appropriate value
            bool actual;
            actual = target.AddTrackBlock(block);
            Assert.IsFalse(actual);

            block = new TrackBlock();
            actual = target.AddTrackBlock(block);
            Assert.IsTrue(actual);
        }
예제 #2
0
        public void AddTrackBlockTest()
        {
            TrackController target = new TrackController(); // TODO: Initialize to an appropriate value
            TrackBlock      block  = null;                  // TODO: Initialize to an appropriate value
            bool            actual;

            actual = target.AddTrackBlock(block);
            Assert.IsFalse(actual);

            block  = new TrackBlock();
            actual = target.AddTrackBlock(block);
            Assert.IsTrue(actual);
        }
예제 #3
0
        public void CloseTrackTest()
        {
            TrackController target  = new TrackController(); // TODO: Initialize to an appropriate value
            string          trackId = string.Empty;          // TODO: Initialize to an appropriate value
            bool            actual;

            actual = target.CloseTrack(trackId);
            Assert.IsFalse(actual);

            // can't close a track that isn't owned
            trackId = "akljkjcbao";
            actual  = target.CloseTrack(trackId);
            Assert.IsFalse(actual);

            // assert true if controller owns track and is able to close it
            TrackBlock block = new TrackBlock();

            block.Name = trackId = "TestName";
            target.AddTrackBlock(block);
            actual = target.CloseTrack(trackId);
            Assert.IsTrue(actual);

            // assert false if track is already closed
            actual = target.CloseTrack(trackId);
            Assert.IsFalse(actual);

            // shouldn't be able to close a track with a train on it
            block.Status.IsOpen       = true;
            block.Status.TrainPresent = true;
            actual = target.CloseTrack(trackId);
            Assert.IsFalse(actual);
        }
예제 #4
0
        public void AddTrackBlockTest()
        {
            TrackController target   = new TrackController(); // TODO: Initialize to an appropriate value
            TrackBlock      block    = null;                  // TODO: Initialize to an appropriate value
            bool            expected = false;                 // TODO: Initialize to an appropriate value
            bool            actual;

            actual = target.AddTrackBlock(block);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
예제 #5
0
        public void CloseTrackTest()
        {
            TrackController target = new TrackController(); // TODO: Initialize to an appropriate value
            string trackId = string.Empty; // TODO: Initialize to an appropriate value
            bool actual;
            actual = target.CloseTrack(trackId);
            Assert.IsFalse(actual);

            // can't close a track that isn't owned
            trackId = "akljkjcbao";
            actual = target.CloseTrack(trackId);
            Assert.IsFalse(actual);

            // assert true if controller owns track and is able to close it
            TrackBlock block = new TrackBlock();
            block.Name = trackId = "TestName";
            target.AddTrackBlock(block);
            actual = target.CloseTrack(trackId);
            Assert.IsTrue(actual);

            // assert false if track is already closed
            actual = target.CloseTrack(trackId);
            Assert.IsFalse(actual);

            // shouldn't be able to close a track with a train on it
            block.Status.IsOpen = true;
            block.Status.TrainPresent = true;
            actual = target.CloseTrack(trackId);
            Assert.IsFalse(actual);
        }
예제 #6
0
        /// <summary>
        /// Creates track controllers and assigns track blocks to them
        /// </summary>
        ///
        /// <param name="blocks">List of track blocks in the layout</param>
        ///
        /// <returns>bool Sucess</returns>
        private bool BuildLayout(List <TrackBlock> blocks, List <TrackSwitch> switches)
        {
            if (blocks == null)
            {
                return(false);
            }

            //Collection of track controllers
            Dictionary <string, ITrackController> trackControllers = new Dictionary <string, ITrackController>();

            //Variables for calculating the size of the layout
            double minX = Double.PositiveInfinity;
            double maxX = 0;
            double minY = Double.PositiveInfinity;
            double maxY = 0;

            //Reset
            m_controllerList.Clear();
            m_trainList.Clear();
            m_trackTable.Clear();
            m_blockTable.Clear();

            foreach (TrackBlock b in blocks)
            {
                if (!string.IsNullOrEmpty(b.ControllerId))
                {
                    m_blockTable[b.Name] = b;
                    if (!trackControllers.ContainsKey(b.ControllerId))
                    {
                        //Create a new track controller
                        ITrackController controller = new TrackController();
                        controller.AddTrackBlock(b);
                        m_trackTable[b] = controller;
                        m_controllerList.Add(controller);
                        trackControllers[b.ControllerId] = controller;
                    }
                    else
                    {
                        //Add it to the existing track controller
                        ITrackController controller = trackControllers[b.ControllerId];
                        controller.AddTrackBlock(b);
                        m_trackTable[b] = controller;
                    }
                }
                else
                {
                    m_log.LogError("Block primary controller ID was null or empty. Skipping block");
                    continue;
                }

                if (!string.IsNullOrEmpty(b.SecondaryControllerId))
                {
                    if (!trackControllers.ContainsKey(b.SecondaryControllerId))
                    {
                        //Create a new track controller
                        ITrackController controller = new TrackController();
                        controller.AddTrackBlock(b);
                        m_controllerList.Add(controller);
                        trackControllers[b.SecondaryControllerId] = controller;

                        //No need to add the controller to the track table.
                    }
                    else
                    {
                        //Add it to the existing track controller
                        ITrackController controller = trackControllers[b.SecondaryControllerId];
                        controller.AddTrackBlock(b);

                        //No need to add the controller to the track table.
                    }
                }

                //Calculate the min and max coordinates of the layout
                if (b.StartPoint.X < minX)
                {
                    //Only need to check the start point since it is always smaller
                    minX = b.StartPoint.X;
                }
                if (b.EndPoint.X > maxX)
                {
                    //Only need to check the end point since it is always larger
                    maxX = b.EndPoint.X;
                }

                //Need to check both the start and end point for Y
                if (b.StartPoint.Y < minY)
                {
                    minY = b.StartPoint.Y;
                }
                if (b.EndPoint.Y < minY)
                {
                    minY = b.EndPoint.Y;
                }

                if (b.StartPoint.Y > maxY)
                {
                    maxY = b.StartPoint.Y;
                }
                if (b.EndPoint.Y > maxY)
                {
                    maxY = b.EndPoint.Y;
                }
            }

            //Now go back and assign previous/next blocks
            foreach (TrackBlock b in blocks)
            {
                if (!string.IsNullOrEmpty(b.PreviousBlockId))
                {
                    if (m_blockTable.ContainsKey(b.PreviousBlockId))
                    {
                        b.PreviousBlock = m_blockTable[b.PreviousBlockId];
                    }
                }
                if (!string.IsNullOrEmpty(b.NextBlockId))
                {
                    if (m_blockTable.ContainsKey(b.NextBlockId))
                    {
                        b.NextBlock = m_blockTable[b.NextBlockId];
                    }
                }
            }

            //Now create the switches and assign them to track controllers
            if (switches != null)
            {
                foreach (TrackSwitch s in switches)
                {
                    if (m_blockTable.ContainsKey(s.BranchClosedId) && m_blockTable.ContainsKey(s.BranchOpenId) && m_blockTable.ContainsKey(s.TrunkId))
                    {
                        if (trackControllers.ContainsKey(s.ControllerId))
                        {
                            //Assign the blocks to the switch
                            s.Trunk        = m_blockTable[s.TrunkId];
                            s.BranchClosed = m_blockTable[s.BranchClosedId];
                            s.BranchOpen   = m_blockTable[s.BranchOpenId];
                            s.State        = TrackSwitchState.Closed;
                            trackControllers[s.ControllerId].SetSwitch(s);
                        }
                        else
                        {
                            m_log.LogError("Switch Track Controller Id was invalid. Skipping.");
                        }
                    }
                    else
                    {
                        m_log.LogError("Block Id not found. Skipping.");
                    }
                }
            }

            //Calculate the start point and total size
            m_layoutStartPoint = new Point(System.Convert.ToInt32(minX), System.Convert.ToInt32(minY));

            if (maxX < Double.PositiveInfinity && maxY < Double.PositiveInfinity)
            {
                m_layoutSize = new Size(System.Convert.ToInt32(maxX - minX), System.Convert.ToInt32(maxY - minY));
            }

            return(true);
        }