コード例 #1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // Environment
            env = new SimulationEnvironment.SimulationEnvironment();

            // TrackModel
            TrackModel.TrackModel trackModel = new TrackModel.TrackModel(env);
            env.TrackModel = trackModel;
            TrackModel.TrackModelGUI trackModelGui = new TrackModelGUI(env, trackModel);

            // CTCOffice
            CTCOffice.CTCOffice ctcOffice = new CTCOffice.CTCOffice(env, env.PrimaryTrackControllerRed, env.PrimaryTrackControllerGreen);
            env.CTCOffice = ctcOffice;
            CTCOffice.CTCOfficeGUI ctcOfficeGui = new CTCOfficeGUI(env, ctcOffice);
            ctcOfficeGui.ShowTrain += new EventHandler<ShowTrainEventArgs>(ctcOfficeGui_ShowTrain);
            ctcOfficeGui.ShowSchedule += new EventHandler<EventArgs>(ctcOfficeGui_ShowSchedule);

            // Scheduler
            SystemScheduler.SystemScheduler scheduler = new SystemScheduler.SystemScheduler(env, ctcOffice);
            env.SystemScheduler = scheduler;
            SystemScheduler.SystemSchedulerGUI schedulerGui = new SystemScheduler.SystemSchedulerGUI(env, scheduler, ctcOffice);

            // train model form
            TrainModel.TrainGUI trainGui = new TrainGUI(env);

            // Track Controllers
            if (env.PrimaryTrackControllerRed != null)
            {
                TrackController.TrackController red = (TrackController.TrackController)env.PrimaryTrackControllerRed;
                TrackControllerUi redTcGui = new TrackControllerUi(env, red);
                trackControllerRedForm = new Form() { Controls = { redTcGui }, TopLevel = true, AutoSize = true, Parent = null, Text = "Terminal Velocity - Track Controller Red" };
            }

            if (env.PrimaryTrackControllerGreen != null)
            {
                TrackController.TrackController green = (TrackController.TrackController)env.PrimaryTrackControllerGreen;
                TrackControllerUi greenTcGui = new TrackControllerUi(env, green);
                trackControllerGreenForm = new Form() { Controls = { greenTcGui }, TopLevel = true, AutoSize = true, Parent = null, Text = "Terminal Velocity - Track Controller Green" };
            }

            ctcForm = new Form() { Controls = { ctcOfficeGui }, AutoSize = true, Text="Terminal Velocity - CTC Office"};
            schedulerForm = new Form() { Controls = { schedulerGui }, TopLevel = true, AutoSize = true, Parent = null, Text="Terminal Velocity - System Scheduler" };
            trackModelForm = new Form() { Controls = { trackModelGui }, TopLevel = true, AutoSize = true, Parent = null, Text="Terminal Velocity - Track Model"};
            trainModelForm = new Form() { Controls = { trainGui }, TopLevel = true, AutoSize = true, Parent = null, Text = "Terminal Velocity - Trains" };

            //TODO
            /*
             * Train Controller Form(s)
             * Train Model Form
            */

            ctcForm.Shown += new EventHandler(ctcForm_Shown);

            Application.Run(ctcForm);
        }
コード例 #2
0
        public void createTrackModel()
        {
            //Create TrackModel
            _trackMod = new TrackModel.TrackModel(_env);
            //Let TrackModel read in the lines before you proceed..shouldnt be done this way, but needed to stop CTC Office from faulting
            bool Proto_res = _trackMod.provideInputFile(@"..\..\Resources\red.csv");

            //Console.WriteLine("Res was "+res);
            Proto_res = _trackMod.provideInputFile(@"..\..\Resources\green.csv");
            //Console.WriteLine("Res was " + res);
            _env.TrackModel = _trackMod;
        }
コード例 #3
0
        //Constructor
        public TrackModelGUI(ISimulationEnvironment env, TrackModel tm)
        {
            //var initialization
            _environment = env;
            _tm          = tm;

            //Subscribe to an environment Tick
            //_environment.Tick += new EventHandler<TickEventArgs>(_environment_Tick);

            //Component initialization
            InitializeComponent();
        }
コード例 #4
0
        //Constructor
        public TrackModelGUI(ISimulationEnvironment env, TrackModel tm)
        {
            //var initialization
            _environment = env;
            _tm = tm;

            //Subscribe to an environment Tick
            //_environment.Tick += new EventHandler<TickEventArgs>(_environment_Tick);

            //Component initialization
            InitializeComponent();
        }
コード例 #5
0
        public bool DoTest(out int pass, out int fail, out List <string> message)
        {
            pass    = 0;
            fail    = 0;
            message = new List <string>();

            ISimulationEnvironment environment = new SimulationEnvironment.SimulationEnvironment();
            var tm = new TrackModel.TrackModel(environment);

            /////////////////////////////////
            //Test 1
            //Check that RedLoaded is initially false
            if (tm.RedLoaded == false)
            {
                pass++;
                message.Add("Pass: RedLoaded is initially false");
            }
            else
            {
                fail++;
                message.Add("Fail: RedLoaded was not initially false, as it should be prior to loading RedLine");
            }
            //End test 1
            /////////////////////////////////


            /////////////////////////////////
            //Test 2
            //Check that GreenLoaded is initially false
            if (tm.GreenLoaded == false)
            {
                pass++;
                message.Add("Pass: GreenLoaded is initially false, as desired");
            }
            else
            {
                fail++;
                message.Add("Fail: GreenLoaded was not initially false, as it should be prior to loading GreenLine");
            }
            /////////////////////////////////


            /////////////////////////////////
            //Test 3
            //provideInputFile returns false when given bad input file
            bool resBool = tm.provideInputFile("asdfawecxwe");/** Gee, Really hope this file doesnt exist*/

            if (resBool == false)
            {
                pass++;
                message.Add("Pass: provideInputFile returns false when given bad file");
            }
            else
            {
                fail++;
                message.Add("Fail: provideInputFile didn't return false when given an invalid filename");
            }
            //End Test 3
            /////////////////////////////////


            /////////////////////////////////
            //Test 4
            //provideInputFile should return false when given a null argument
            resBool = tm.provideInputFile(null);
            if (resBool == false)
            {
                pass++;
                message.Add("Pass: provideInputFile returns false when given a null argument");
            }
            else
            {
                fail++;
                message.Add("Fail: provideInputFile should return false when given a null argument");
            }
            //End Test 4
            /////////////////////////////////


            /////////////////////////////////
            //Test 5
            //provideInputFile should return false when given a non-csv file
            resBool = tm.provideInputFile(@"..\..\red.bad");//An existent but non csv file
            if (resBool == false)
            {
                pass++;
                message.Add("Pass: provideInputFile returns false when given a non-csv file");
            }
            else
            {
                fail++;
                message.Add("Fail: provideInputFile did not return false when given a non-csv file as expected");
            }
            //End Test 5
            /////////////////////////////////


            /////////////////////////////////
            //Test 6
            //provideInputFile should return true when given a valid file
            resBool = tm.provideInputFile(@"..\..\red.csv");
            if (resBool == true)
            {
                pass++;
                message.Add("Pass: provideInputFile returned true when given a valid, existing, and properly formatted file (red.csv)");
            }
            else
            {
                fail++;
                message.Add("Pass: provideInputFile returned false when given a valid and proper file, expected val was true (red.csv)");
            }
            //End Test 6
            /////////////////////////////////


            /////////////////////////////////
            //Test 7
            //provideInputFile should return true when given a valid file
            resBool = tm.provideInputFile(@"..\..\green.csv");
            if (resBool == true)
            {
                pass++;
                message.Add("Pass: provideInputFile returned true when given a valid, existing, and properly formatted file (green.csv)");
            }
            else
            {
                fail++;
                message.Add("Pass: provideInputFile returned false when given a valid and proper file, expected val was true (green.csv)");
            }
            //End Test 7
            /////////////////////////////////


            /////////////////////////////////
            //Test 8
            //Check that RedLoaded property returns true after loading
            if (tm.RedLoaded)
            {
                pass++;
                message.Add("Pass: the RedLoaded Property shows that the red line has now been loaded");
            }
            else
            {
                fail++;
                message.Add("Fail: the RedLoaded Property does not show that the red line has been loaded");
            }
            //End Test 8
            /////////////////////////////////


            /////////////////////////////////
            //Test 9
            if (tm.GreenLoaded)
            {
                pass++;
                message.Add("Pass: The GreenLoaded Property shows that the green line has now been loaded");
            }
            else
            {
                fail++;
                message.Add("Fail: The GreenLoaded Property does not show that the green line has been loaded");
            }
            //End Test 9
            /////////////////////////////////


            /////////////////////////////////
            //Test 10
            //requestBlockInfo should return null when given a negative block number
            IBlock tempIBlock = tm.requestBlockInfo(-1, "Red");

            if (tempIBlock == null)
            {
                pass++;
                message.Add("Pass: requestBlockInfo returned null when given a negative blockID");
            }
            else
            {
                fail++;
                message.Add("Fail: requestBlockInfo returned a valid block when given negative blockID, expected val was null");
            }
            //End Test 10
            /////////////////////////////////


            /////////////////////////////////
            //Test 11
            //requestBlockInfo should return null when given a blockID=0
            tempIBlock = tm.requestBlockInfo(0, "Red");
            if (tempIBlock != null)
            {
                pass++;
                message.Add("Pass: requestBlockInfo was able to retrieve the 0 block of a line");
            }
            else
            {
                fail++;
                message.Add("Fail: requestBlockInfo returned null when given blockID=0, expected val was valid block");
            }
            //End Test 11
            /////////////////////////////////


            /////////////////////////////////
            //Test 12
            //requestBlockInfo should return null when asked to retrieve an out-of-range block id
            tempIBlock = tm.requestBlockInfo(19191, "Red");
            if (tempIBlock == null)
            {
                pass++;
                message.Add("Pass: requestBlockInfo returned null as expected when given an out of range block ID");
            }
            else
            {
                fail++;
                message.Add("Fail: requestBlockInfo did not return null when given an out of range blockID, expected val was null");
            }
            //End Test 12
            /////////////////////////////////


            /////////////////////////////////
            //Test 13
            //requestBlockInfo should return null when given a bad line string
            tempIBlock = tm.requestBlockInfo(0, "asdf");
            if (tempIBlock == null)
            {
                pass++;
                message.Add("Pass: requestBlockInfo returned null when given an invalid line string");
            }
            else
            {
                fail++;
                message.Add("Fail: requestBlockInfo did not return null when given an invalid line string");
            }
            //End Test 13
            /////////////////////////////////


            /////////////////////////////////
            //Test 14
            //requestBlockInfo should return a valid block when asked to retrieve a basic block (without extra infrastructure)
            tempIBlock = tm.requestBlockInfo(1, "Red");
            if (tempIBlock != null)
            {
                pass++;
                message.Add("Pass: requestBlockInfo successfully returned a basic block without extra infrastructure");
            }
            else
            {
                fail++;
                message.Add("Fail: requestBlockInfo returned null when asked to retrieve a basic block without extra infrastructure");
            }
            //End Test 14
            /////////////////////////////////


            /////////////////////////////////
            //Test 15
            //requestBlockInfo should return a valid block when asked to retrieve a more complex block (containing infrastructure such as switch, heater, etc).
            tempIBlock = tm.requestBlockInfo(27, "Red");
            if (tempIBlock != null)
            {
                pass++;
                message.Add("Pass: requestBlockInfo successfully returned a complex block (with additional infra)");
            }
            else
            {
                fail++;
                message.Add("Fail: requestBlockInfo returns null when asked for a more complex block (with additional infra)");
            }
            //End Test 15
            /////////////////////////////////


            /////////////////////////////////
            //Test 16
            //requestUpdateBlock returns false when provided with a null value
            resBool = tm.requestUpdateBlock(null);
            if (resBool == false)
            {
                pass++;
                message.Add("Pass: requestUpdateBlock returns false when given a null value");
            }
            else
            {
                fail++;
                message.Add("Fail: requestUpdateBlock returns true when given a null value, expected value is false");
            }
            //End Test 16
            /////////////////////////////////



            /////////////////////////////////
            //Test 17
            //requestUpdateBlock returns false when provided with a block w/ ID=0 (no updating the yard)
            tempIBlock = tm.requestBlockInfo(0, "Red");
            resBool    = tm.requestUpdateBlock(tempIBlock);
            if (resBool == false)
            {
                pass++;
                message.Add("Pass: requestUpdateBlock returned false when attempting to update 0 block (yard)");
            }
            else
            {
                fail++;
                message.Add("Fail: requestUpdateBlock returned true when attempting to update 0 block (yard), expected value was false");
            }
            //End Test 17
            /////////////////////////////////


            /////////////////////////////////
            //Test 18
            //requestBlockUpdate should allow change of Health State
            tempIBlock = tm.requestBlockInfo(1, "Red");

            //Store old state, and assign new state in a way that ensures oldState and newState are different
            var oldState = tempIBlock.State;

            if (oldState != StateEnum.CircuitFailure)
            {
                tempIBlock.State = StateEnum.CircuitFailure;
            }
            else
            {
                tempIBlock.State = StateEnum.BrokenTrackFailure;
            }

            //Update the block
            resBool = tm.requestUpdateBlock(tempIBlock);
            //Re-request info from database
            tempIBlock = tm.requestBlockInfo(1, "Red");
            if (resBool && tempIBlock.State != oldState)
            {
                pass++;
            }
            else if (!resBool && tempIBlock.State == oldState)
            {
                fail++;
                message.Add("Fail: requestUpdateBlock returnd a false value, when given a changed state, expected val was true");
            }
            else
            {
                fail++;
                message.Add("Fail: requestUpdateBlock returned true, but failed to update the database");
            }
            //End Test 18
            /////////////////////////////////


            /////////////////////////////////
            //Test 19
            //requestUpdateBlock should allow updating of heater state

            //////////////////////////////////
            //THIS NEEDS IMPLEMENTED STILL
            //No blocks in the init file contain heaters by default
            //Should I assume that every block has a heater?
            //I prob want to write a method in the BLOCK object that lets you turn the heater on and off
            //
            //////////////////////////////////
            //End Test 19
            /////////////////////////////////


            /////////////////////////////////
            //Test 20
            //requestUpdateBlock should return true but fail to update swith when asked to update switch information in db
            tempIBlock = tm.requestBlockInfo(1, "Red");
            int oldSD1 = tempIBlock.SwitchDest1;

            tempIBlock.SwitchDest1 = tempIBlock.SwitchDest2;
            tempIBlock.SwitchDest2 = oldSD1;
            resBool    = tm.requestUpdateBlock(tempIBlock);
            tempIBlock = tm.requestBlockInfo(1, "Red");
            if (resBool == true && tempIBlock.SwitchDest1 == oldSD1)
            {
                pass++;
                message.Add("Pass: requestUpdateBlock did not update Switch state in database");
            }
            else
            {
                fail++;
                message.Add("Fail: either the returned boolean was false, or the data was updated in the db.");
            }
            //End Test 20
            /////////////////////////////////


            /////////////////////////////////
            //Test 21
            //requestRouteInfo should return a null value when given a negative route ID
            IRouteInfo tempIRouteInfo = tm.requestRouteInfo(-1);

            if (tempIRouteInfo == null)
            {
                pass++;
                message.Add("Pass: requestRouteInfo returns null when given a negative routeID");
            }
            else
            {
                fail++;
                message.Add("Fail: requestRouteInfo returned a Route when given a negative routeID, expected val was null");
            }
            //End Test 21
            /////////////////////////////////


            /////////////////////////////////
            //Test 22
            //requestRouteInfo should return a null value when given a line other than 0 or 1
            tempIRouteInfo = tm.requestRouteInfo(2);
            if (tempIRouteInfo == null)
            {
                pass++;
                message.Add("Pass: requestRouteInfo returns null when given an out of range routeID");
            }
            else
            {
                fail++;
                message.Add("Fail: requestRouteInfo returned a Route when given an out of range route ID, expected val was null");
            }
            //End Test 22
            /////////////////////////////////


            /////////////////////////////////
            //Test 23
            //requestRouteInfo returns a valid IRouteInfo object when given a line ID of 0 or 1
            tempIRouteInfo = tm.requestRouteInfo(0);
            if (tempIRouteInfo != null)
            {
                pass++;
                message.Add("Pass: requestRouteInfo returns valid IRouteInfo when given valid lineID");
            }
            else
            {
                fail++;
                message.Add("Fail: requestRouteInfo returns null when given valid lineID, expected val was null");
            }
            //End Test 23
            /////////////////////////////////


            /////////////////////////////////
            //Test 24
            //requestTrackGrid should return null when given an invalid line ID
            IBlock[,] tempIBlockArr = tm.requestTrackGrid(-1);
            if (tempIBlockArr == null)
            {
                pass++;
                message.Add("Pass: requestTrackGrid returns null when given invalid line ID");
            }
            else
            {
                fail++;
                message.Add("Fail: requestTrackGrid returns valid IBlock[,] when given invalid line id, expected value was null");
            }
            //End Test 24
            /////////////////////////////////


            /////////////////////////////////
            //Test 25
            //requestTrackGrid should return valid IBlock[,] when given valid line ID
            tempIBlockArr = tm.requestTrackGrid(0);
            if (tempIBlockArr != null)
            {
                pass++;
                message.Add("Pass: requestTrackGrid returns valid IBlock[,] when given valid line id");
            }
            else
            {
                fail++;
                message.Add("Fail: requestTrackGrid returns null when given valid line id, expected val was IBlock[,] object");
            }
            //End Test 25
            /////////////////////////////////


            /////////////////////////////////
            //Test 26
            //requestUpdateSwitch should return false when given a null Block value
            resBool = tm.requestUpdateSwitch(null);
            if (resBool == false)
            {
                pass++;
                message.Add("Pass: requestUpdateSwitch returns false when given a null parameter");
            }
            else
            {
                fail++;
                message.Add("Fail: requestUpdateSwitch returns true when given a null parameter, expected value was false");
            }
            //End Test 26
            /////////////////////////////////


            /////////////////////////////////
            //Test 27
            //requestUpdateSwitch should return false when given a block that doesnt contain a switch
            tempIBlock = tm.requestBlockInfo(1, "Red");
            resBool    = tm.requestUpdateSwitch(tempIBlock);
            if (resBool == false)
            {
                pass++;
                message.Add("Pass: requestUpdateSwitch returns false when given a block without a switch");
            }
            else
            {
                fail++;
                message.Add("Fail: requestUpdateSwitch returns true when given a block without a switch");
            }
            //End Test 27
            /////////////////////////////////


            /////////////////////////////////
            //Test 28
            //requestUpdateSwitch should return true when given a block that contains a switch. Actual DB update checked in next test
            tempIBlock = tm.requestBlockInfo(15, "Red");
            int oldDest1 = tempIBlock.SwitchDest1;

            tempIBlock.SwitchDest1 = tempIBlock.SwitchDest2;
            tempIBlock.SwitchDest2 = oldDest1;
            resBool = tm.requestUpdateSwitch(tempIBlock);

            tempIBlock = tm.requestBlockInfo(15, "Red");
            if (resBool == true)
            {
                if (tempIBlock.SwitchDest1 != oldDest1)
                {
                    pass++;
                    message.Add("Pass: requestUpdateSwitch returned true and updated the database when given valid block");
                }
                else
                {
                    fail++;
                    message.Add("Fail: requestUpdateSwitch returned true but failed to update database when given valid block");
                }
            }
            else
            {
                fail++;
                message.Add("Fail: requestUpdateSwitch returned false when given valid block");
            }

            //End Test 28
            /////////////////////////////////
            return(true);
        }
コード例 #6
0
        private static Form GuiTestFramework(int test)
        {
            ////////////////////////////////////////////////////////////////////////////////////////
            //                              Initializations                                       //
            ////////////////////////////////////////////////////////////////////////////////////////

            // Environment object
            var environment = new SimulationEnvironment.SimulationEnvironment();

            IBlock b0 = new TrackModel.Block(1, StateEnum.Healthy, 0, 0, 0, new[] {0, 0}, 10, DirEnum.East, new[] {""}, 0, 0, 0, "Red",70);
            IBlock b1 = new TrackModel.Block(2, StateEnum.Healthy, 1, 0, 0, new[] {1, 1}, 10, DirEnum.East, new[] {""}, 0, 0, 0, "Red",70);
            IBlock b2 = new TrackModel.Block(3, StateEnum.Healthy, 2, 0, 0, new[] {2, 2}, 10, DirEnum.East, new[] {""}, 0, 0, 0, "Red",70);
            IBlock b3 = new TrackModel.Block(4, StateEnum.BrokenTrackFailure, 3, 0, 0, new[] {3, 3}, 10, DirEnum.East, new[] {""}, 0, 0, 0, "Red",70);

            var sectionA = new List<IBlock> {b0};
            var sectionB = new List<IBlock> {b1, b2};
            var sectionC = new List<IBlock> {b3};

            // Previous track controller's circuit
            var prevCircuit = new TrackCircuit(environment, sectionA);
            // Our track circuit
            var currCircuit = new TrackCircuit(environment, sectionB);
            // Next track controller's circuit
            var nextCircuit = new TrackCircuit(environment, sectionC);

            var prev = new TrackController.TrackController(environment, prevCircuit);
            var curr = new TrackController.TrackController(environment, currCircuit);
            var next = new TrackController.TrackController(environment, nextCircuit);

            //Create TrackModel
            var trackMod = new TrackModel.TrackModel(environment);
            //Let TrackModel read in the lines before you proceed..shouldnt be done this way, but needed to stop CTC Office from faulting
            bool res = trackMod.provideInputFile("red.csv");
            //Console.WriteLine("Res was "+res);
            res = trackMod.provideInputFile("green.csv");
            //Console.WriteLine("Res was " + res);

            environment.TrackModel = trackMod;
            prev.Previous = null;
            prev.Next = curr;

            curr.Previous = prev;
            curr.Next = next;

            next.Previous = curr;
            next.Next = null;

            // Assign the same track controller to both lines
            var office = new CTCOffice.CTCOffice(environment, prev, prev);

            environment.CTCOffice = office;
            environment.PrimaryTrackControllerGreen = prev;
            environment.PrimaryTrackControllerRed = prev;

            ////////////////////////////////////////////////////////////////////////////////////////
            //                            End Initializations                                     //
            ////////////////////////////////////////////////////////////////////////////////////////

            var form = new Form();
            var control = new UserControl();
            switch (test)
            {
                case 0: // SystemScheduler

                    var testSystemScheduler = new SystemScheduler.SystemScheduler(environment, office);
                    control = new SystemSchedulerGUI(environment, testSystemScheduler, office);
                    environment.StartTick();
                    break;
                case 1: // CTCOffice
                    environment = null;

                    b0 = null;
                    b1 = null;
                    b2 = null;
                    b3 = null;

                    sectionA = null;
                    sectionB = null;
                    sectionC = null;

                    prevCircuit = null;
                    currCircuit = null;
                    nextCircuit = null;

                    prev = null;
                    curr = null;
                    next = null;

                    trackMod = null;
                    office = null;

                    new CTCGUITest();
                    break;
                case 2: // TrackModel
                    control = new TrackModelGUI(environment, trackMod);
                    break;
                case 3: // TrackController
                    ITrainModel t = new Train(0, b0, environment);

                    environment.AllTrains.Add(t);

                    prevCircuit.Trains.Add(0, t);

                    control = new TrackControllerUi(environment, environment.PrimaryTrackControllerRed);
                    break;
                case 4: // TrainModel
                    var loc = new int[2];
                    loc[0] = 10;
                    loc[1] = 10;
                    var start = new Block(0, StateEnum.Healthy, 0, 0, -0.02, loc, 100, DirEnum.East, null, 1, 2, 0, "Red",70);
                    environment.AddTrain(new Train(0, start, environment));
                    environment.AddTrain(new Train(1, start, environment));

                    var train0 = (Train)environment.AllTrains[0];
                    train0.ChangeMovement(200);

                    control = new TrainGUI(environment);

                    break;
                case 5: // TrainController
                    var loc2 = new int[2];
                    loc2[0] = 10;
                    loc2[1] = 10;
                    var start2 = new Block(0, StateEnum.Healthy, 0, 0, 0, loc2, 100, DirEnum.East, null, 1, 2, 0, "Red",70);
                    var tc = new TrainController.TrainController(environment, new Train(0, start2, environment));
                    control = new TrainControllerUI(tc, environment);
                    break;
            }

            if (environment != null)
            {
                environment.StartTick();
            }

            if (form != null)
            {
                form.Controls.Add(control);
                form.AutoSize = true;
            }
            else
            {
                return null;
            }

            return form;
        }
コード例 #7
0
        public bool DoTest(out int pass, out int fail, out List<string> message)
        {
            pass = 0;
            fail = 0;
            message = new List<string>();

            ISimulationEnvironment environment = new SimulationEnvironment.SimulationEnvironment();
            var tm = new TrackModel.TrackModel(environment);

            /////////////////////////////////
            //Test 1
            //Check that RedLoaded is initially false
            if (tm.RedLoaded == false)
            {
                pass++;
                message.Add("Pass: RedLoaded is initially false");
            }
            else
            {
                fail++;
                message.Add("Fail: RedLoaded was not initially false, as it should be prior to loading RedLine");
            }
            //End test 1
            /////////////////////////////////

            /////////////////////////////////
            //Test 2
            //Check that GreenLoaded is initially false
            if (tm.GreenLoaded == false)
            {
                pass++;
                message.Add("Pass: GreenLoaded is initially false, as desired");
            }
            else
            {
                fail++;
                message.Add("Fail: GreenLoaded was not initially false, as it should be prior to loading GreenLine");
            }
            /////////////////////////////////

            /////////////////////////////////
            //Test 3
            //provideInputFile returns false when given bad input file
            bool resBool=tm.provideInputFile("asdfawecxwe");/** Gee, Really hope this file doesnt exist*/
            if (resBool == false)
            {
                pass++;
                message.Add("Pass: provideInputFile returns false when given bad file");
            }
            else
            {
                fail++;
                message.Add("Fail: provideInputFile didn't return false when given an invalid filename");
            }
            //End Test 3
            /////////////////////////////////

            /////////////////////////////////
            //Test 4
            //provideInputFile should return false when given a null argument
            resBool = tm.provideInputFile(null);
            if (resBool == false)
            {
                pass++;
                message.Add("Pass: provideInputFile returns false when given a null argument");
            }
            else
            {
                fail++;
                message.Add("Fail: provideInputFile should return false when given a null argument");
            }
            //End Test 4
            /////////////////////////////////

            /////////////////////////////////
            //Test 5
            //provideInputFile should return false when given a non-csv file
            resBool = tm.provideInputFile(@"..\..\red.bad");//An existent but non csv file
            if (resBool == false)
            {
                pass++;
                message.Add("Pass: provideInputFile returns false when given a non-csv file");
            }
            else
            {
                fail++;
                message.Add("Fail: provideInputFile did not return false when given a non-csv file as expected");
            }
            //End Test 5
            /////////////////////////////////

            /////////////////////////////////
            //Test 6
            //provideInputFile should return true when given a valid file
            resBool=tm.provideInputFile(@"..\..\red.csv");
            if (resBool == true)
            {
                pass++;
                message.Add("Pass: provideInputFile returned true when given a valid, existing, and properly formatted file (red.csv)");
            }
            else
            {
                fail++;
                message.Add("Pass: provideInputFile returned false when given a valid and proper file, expected val was true (red.csv)");
            }
            //End Test 6
            /////////////////////////////////

            /////////////////////////////////
            //Test 7
            //provideInputFile should return true when given a valid file
            resBool = tm.provideInputFile(@"..\..\green.csv");
            if (resBool == true)
            {
                pass++;
                message.Add("Pass: provideInputFile returned true when given a valid, existing, and properly formatted file (green.csv)");
            }
            else
            {
                fail++;
                message.Add("Pass: provideInputFile returned false when given a valid and proper file, expected val was true (green.csv)");
            }
            //End Test 7
            /////////////////////////////////

            /////////////////////////////////
            //Test 8
            //Check that RedLoaded property returns true after loading
            if (tm.RedLoaded)
            {
                pass++;
                message.Add("Pass: the RedLoaded Property shows that the red line has now been loaded");
            }
            else
            {
                fail++;
                message.Add("Fail: the RedLoaded Property does not show that the red line has been loaded");
            }
            //End Test 8
            /////////////////////////////////

            /////////////////////////////////
            //Test 9
            if (tm.GreenLoaded)
            {
                pass++;
                message.Add("Pass: The GreenLoaded Property shows that the green line has now been loaded");
            }
            else
            {
                fail++;
                message.Add("Fail: The GreenLoaded Property does not show that the green line has been loaded");
            }
            //End Test 9
            /////////////////////////////////

            /////////////////////////////////
            //Test 10
            //requestBlockInfo should return null when given a negative block number
            IBlock tempIBlock = tm.requestBlockInfo(-1, "Red");
            if (tempIBlock == null)
            {
                pass++;
                message.Add("Pass: requestBlockInfo returned null when given a negative blockID");
            }
            else
            {
                fail++;
                message.Add("Fail: requestBlockInfo returned a valid block when given negative blockID, expected val was null");
            }
            //End Test 10
            /////////////////////////////////

            /////////////////////////////////
            //Test 11
            //requestBlockInfo should return null when given a blockID=0
            tempIBlock = tm.requestBlockInfo(0, "Red");
            if (tempIBlock != null)
            {
                pass++;
                message.Add("Pass: requestBlockInfo was able to retrieve the 0 block of a line");
            }
            else
            {
                fail++;
                message.Add("Fail: requestBlockInfo returned null when given blockID=0, expected val was valid block");
            }
            //End Test 11
            /////////////////////////////////

            /////////////////////////////////
            //Test 12
            //requestBlockInfo should return null when asked to retrieve an out-of-range block id
            tempIBlock = tm.requestBlockInfo(19191, "Red");
            if (tempIBlock == null)
            {
                pass++;
                message.Add("Pass: requestBlockInfo returned null as expected when given an out of range block ID");
            }
            else
            {
                fail++;
                message.Add("Fail: requestBlockInfo did not return null when given an out of range blockID, expected val was null");
            }
            //End Test 12
            /////////////////////////////////

            /////////////////////////////////
            //Test 13
            //requestBlockInfo should return null when given a bad line string
            tempIBlock = tm.requestBlockInfo(0, "asdf");
            if (tempIBlock == null)
            {
                pass++;
                message.Add("Pass: requestBlockInfo returned null when given an invalid line string");
            }
            else
            {
                fail++;
                message.Add("Fail: requestBlockInfo did not return null when given an invalid line string");
            }
            //End Test 13
            /////////////////////////////////

            /////////////////////////////////
            //Test 14
            //requestBlockInfo should return a valid block when asked to retrieve a basic block (without extra infrastructure)
            tempIBlock = tm.requestBlockInfo(1, "Red");
            if (tempIBlock != null)
            {
                pass++;
                message.Add("Pass: requestBlockInfo successfully returned a basic block without extra infrastructure");
            }
            else
            {
                fail++;
                message.Add("Fail: requestBlockInfo returned null when asked to retrieve a basic block without extra infrastructure");
            }
            //End Test 14
            /////////////////////////////////

            /////////////////////////////////
            //Test 15
            //requestBlockInfo should return a valid block when asked to retrieve a more complex block (containing infrastructure such as switch, heater, etc).
            tempIBlock = tm.requestBlockInfo(27, "Red");
            if (tempIBlock != null)
            {
                pass++;
                message.Add("Pass: requestBlockInfo successfully returned a complex block (with additional infra)");
            }
            else
            {
                fail++;
                message.Add("Fail: requestBlockInfo returns null when asked for a more complex block (with additional infra)");
            }
            //End Test 15
            /////////////////////////////////

            /////////////////////////////////
            //Test 16
            //requestUpdateBlock returns false when provided with a null value
            resBool=tm.requestUpdateBlock(null);
            if (resBool == false)
            {
                pass++;
                message.Add("Pass: requestUpdateBlock returns false when given a null value");
            }
            else
            {
                fail++;
                message.Add("Fail: requestUpdateBlock returns true when given a null value, expected value is false");
            }
            //End Test 16
            /////////////////////////////////

            /////////////////////////////////
            //Test 17
            //requestUpdateBlock returns false when provided with a block w/ ID=0 (no updating the yard)
            tempIBlock=tm.requestBlockInfo(0, "Red");
            resBool = tm.requestUpdateBlock(tempIBlock);
            if (resBool == false)
            {
                pass++;
                message.Add("Pass: requestUpdateBlock returned false when attempting to update 0 block (yard)");
            }
            else
            {
                fail++;
                message.Add("Fail: requestUpdateBlock returned true when attempting to update 0 block (yard), expected value was false");
            }
            //End Test 17
            /////////////////////////////////

            /////////////////////////////////
            //Test 18
            //requestBlockUpdate should allow change of Health State
            tempIBlock=tm.requestBlockInfo(1,"Red");

            //Store old state, and assign new state in a way that ensures oldState and newState are different
            var oldState = tempIBlock.State;
            if(oldState!=StateEnum.CircuitFailure)
                tempIBlock.State = StateEnum.CircuitFailure;
            else
                tempIBlock.State=StateEnum.BrokenTrackFailure;

            //Update the block
            resBool=tm.requestUpdateBlock(tempIBlock);
            //Re-request info from database
            tempIBlock=tm.requestBlockInfo(1,"Red");
            if (resBool && tempIBlock.State != oldState)
            {
                pass++;
            }
            else if (!resBool && tempIBlock.State==oldState)
            {
                fail++;
                message.Add("Fail: requestUpdateBlock returnd a false value, when given a changed state, expected val was true");
            }
            else
            {
                fail++;
                message.Add("Fail: requestUpdateBlock returned true, but failed to update the database");
            }
            //End Test 18
            /////////////////////////////////

            /////////////////////////////////
            //Test 19
            //requestUpdateBlock should allow updating of heater state

                    //////////////////////////////////
                            //THIS NEEDS IMPLEMENTED STILL
                            //No blocks in the init file contain heaters by default
                            //Should I assume that every block has a heater?
                            //I prob want to write a method in the BLOCK object that lets you turn the heater on and off
                            //
                    //////////////////////////////////
            //End Test 19
            /////////////////////////////////

            /////////////////////////////////
            //Test 20
            //requestUpdateBlock should return true but fail to update swith when asked to update switch information in db
            tempIBlock=tm.requestBlockInfo(1, "Red");
            int oldSD1 = tempIBlock.SwitchDest1;
            tempIBlock.SwitchDest1 = tempIBlock.SwitchDest2;
            tempIBlock.SwitchDest2 = oldSD1;
            resBool=tm.requestUpdateBlock(tempIBlock);
            tempIBlock=tm.requestBlockInfo(1, "Red");
            if (resBool == true && tempIBlock.SwitchDest1 == oldSD1)
            {
                pass++;
                message.Add("Pass: requestUpdateBlock did not update Switch state in database");
            }
            else
            {
                fail++;
                message.Add("Fail: either the returned boolean was false, or the data was updated in the db.");
            }
            //End Test 20
            /////////////////////////////////

            /////////////////////////////////
            //Test 21
            //requestRouteInfo should return a null value when given a negative route ID
            IRouteInfo tempIRouteInfo=tm.requestRouteInfo(-1);
            if (tempIRouteInfo == null)
            {
                pass++;
                message.Add("Pass: requestRouteInfo returns null when given a negative routeID");
            }
            else
            {
                fail++;
                message.Add("Fail: requestRouteInfo returned a Route when given a negative routeID, expected val was null");
            }
            //End Test 21
            /////////////////////////////////

            /////////////////////////////////
            //Test 22
            //requestRouteInfo should return a null value when given a line other than 0 or 1
            tempIRouteInfo = tm.requestRouteInfo(2);
            if (tempIRouteInfo == null)
            {
                pass++;
                message.Add("Pass: requestRouteInfo returns null when given an out of range routeID");
            }
            else
            {
                fail++;
                message.Add("Fail: requestRouteInfo returned a Route when given an out of range route ID, expected val was null");
            }
            //End Test 22
            /////////////////////////////////

            /////////////////////////////////
            //Test 23
            //requestRouteInfo returns a valid IRouteInfo object when given a line ID of 0 or 1
            tempIRouteInfo = tm.requestRouteInfo(0);
            if (tempIRouteInfo != null)
            {
                pass++;
                message.Add("Pass: requestRouteInfo returns valid IRouteInfo when given valid lineID");
            }
            else
            {
                fail++;
                message.Add("Fail: requestRouteInfo returns null when given valid lineID, expected val was null");
            }
            //End Test 23
            /////////////////////////////////

            /////////////////////////////////
            //Test 24
            //requestTrackGrid should return null when given an invalid line ID
            IBlock[,] tempIBlockArr = tm.requestTrackGrid(-1);
            if (tempIBlockArr == null)
            {
                pass++;
                message.Add("Pass: requestTrackGrid returns null when given invalid line ID");
            }
            else
            {
                fail++;
                message.Add("Fail: requestTrackGrid returns valid IBlock[,] when given invalid line id, expected value was null");
            }
            //End Test 24
            /////////////////////////////////

            /////////////////////////////////
            //Test 25
            //requestTrackGrid should return valid IBlock[,] when given valid line ID
            tempIBlockArr = tm.requestTrackGrid(0);
            if (tempIBlockArr != null)
            {
                pass++;
                message.Add("Pass: requestTrackGrid returns valid IBlock[,] when given valid line id");
            }
            else
            {
                fail++;
                message.Add("Fail: requestTrackGrid returns null when given valid line id, expected val was IBlock[,] object");
            }
            //End Test 25
            /////////////////////////////////

            /////////////////////////////////
            //Test 26
            //requestUpdateSwitch should return false when given a null Block value
            resBool=tm.requestUpdateSwitch(null);
            if (resBool == false)
            {
                pass++;
                message.Add("Pass: requestUpdateSwitch returns false when given a null parameter");
            }
            else
            {
                fail++;
                message.Add("Fail: requestUpdateSwitch returns true when given a null parameter, expected value was false");
            }
            //End Test 26
            /////////////////////////////////

            /////////////////////////////////
            //Test 27
            //requestUpdateSwitch should return false when given a block that doesnt contain a switch
            tempIBlock=tm.requestBlockInfo(1, "Red");
            resBool=tm.requestUpdateSwitch(tempIBlock);
            if (resBool == false)
            {
                pass++;
                message.Add("Pass: requestUpdateSwitch returns false when given a block without a switch");
            }
            else
            {
                fail++;
                message.Add("Fail: requestUpdateSwitch returns true when given a block without a switch");
            }
            //End Test 27
            /////////////////////////////////

            /////////////////////////////////
            //Test 28
            //requestUpdateSwitch should return true when given a block that contains a switch. Actual DB update checked in next test
            tempIBlock = tm.requestBlockInfo(15,"Red");
            int oldDest1 = tempIBlock.SwitchDest1;
            tempIBlock.SwitchDest1 = tempIBlock.SwitchDest2;
            tempIBlock.SwitchDest2 = oldDest1;
            resBool=tm.requestUpdateSwitch(tempIBlock);

            tempIBlock = tm.requestBlockInfo(15, "Red");
            if (resBool == true)
            {
                if (tempIBlock.SwitchDest1 != oldDest1)
                {
                    pass++;
                    message.Add("Pass: requestUpdateSwitch returned true and updated the database when given valid block");
                }
                else
                {
                    fail++;
                    message.Add("Fail: requestUpdateSwitch returned true but failed to update database when given valid block");
                }
            }
            else
            {
                fail++;
                message.Add("Fail: requestUpdateSwitch returned false when given valid block");
            }

            //End Test 28
            /////////////////////////////////
            return true;
        }
コード例 #8
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // Environment
            env = new SimulationEnvironment.SimulationEnvironment();

            // TrackModel
            TrackModel.TrackModel trackModel = new TrackModel.TrackModel(env);
            env.TrackModel = trackModel;
            TrackModel.TrackModelGUI trackModelGui = new TrackModelGUI(env, trackModel);

            // CTCOffice
            CTCOffice.CTCOffice ctcOffice = new CTCOffice.CTCOffice(env, env.PrimaryTrackControllerRed, env.PrimaryTrackControllerGreen);
            env.CTCOffice = ctcOffice;
            CTCOffice.CTCOfficeGUI ctcOfficeGui = new CTCOfficeGUI(env, ctcOffice);
            ctcOfficeGui.ShowTrain    += new EventHandler <ShowTrainEventArgs>(ctcOfficeGui_ShowTrain);
            ctcOfficeGui.ShowSchedule += new EventHandler <EventArgs>(ctcOfficeGui_ShowSchedule);


            // Scheduler
            SystemScheduler.SystemScheduler scheduler = new SystemScheduler.SystemScheduler(env, ctcOffice);
            env.SystemScheduler = scheduler;
            SystemScheduler.SystemSchedulerGUI schedulerGui = new SystemScheduler.SystemSchedulerGUI(env, scheduler, ctcOffice);

            // train model form
            TrainModel.TrainGUI trainGui = new TrainGUI(env);

            // Track Controllers
            if (env.PrimaryTrackControllerRed != null)
            {
                TrackController.TrackController red = (TrackController.TrackController)env.PrimaryTrackControllerRed;
                TrackControllerUi redTcGui          = new TrackControllerUi(env, red);
                trackControllerRedForm = new Form()
                {
                    Controls = { redTcGui }, TopLevel = true, AutoSize = true, Parent = null, Text = "Terminal Velocity - Track Controller Red"
                };
            }

            if (env.PrimaryTrackControllerGreen != null)
            {
                TrackController.TrackController green = (TrackController.TrackController)env.PrimaryTrackControllerGreen;
                TrackControllerUi greenTcGui          = new TrackControllerUi(env, green);
                trackControllerGreenForm = new Form()
                {
                    Controls = { greenTcGui }, TopLevel = true, AutoSize = true, Parent = null, Text = "Terminal Velocity - Track Controller Green"
                };
            }

            ctcForm = new Form()
            {
                Controls = { ctcOfficeGui }, AutoSize = true, Text = "Terminal Velocity - CTC Office"
            };
            schedulerForm = new Form()
            {
                Controls = { schedulerGui }, TopLevel = true, AutoSize = true, Parent = null, Text = "Terminal Velocity - System Scheduler"
            };
            trackModelForm = new Form()
            {
                Controls = { trackModelGui }, TopLevel = true, AutoSize = true, Parent = null, Text = "Terminal Velocity - Track Model"
            };
            trainModelForm = new Form()
            {
                Controls = { trainGui }, TopLevel = true, AutoSize = true, Parent = null, Text = "Terminal Velocity - Trains"
            };


            //TODO

            /*
             * Train Controller Form(s)
             * Train Model Form
             */

            ctcForm.Shown += new EventHandler(ctcForm_Shown);

            Application.Run(ctcForm);
        }
コード例 #9
0
 public void createTrackModel()
 {
     //Create TrackModel
     _trackMod = new TrackModel.TrackModel(_env);
     //Let TrackModel read in the lines before you proceed..shouldnt be done this way, but needed to stop CTC Office from faulting
     bool Proto_res = _trackMod.provideInputFile(@"..\..\Resources\red.csv");
     //Console.WriteLine("Res was "+res);
     Proto_res = _trackMod.provideInputFile(@"..\..\Resources\green.csv");
     //Console.WriteLine("Res was " + res);
     _env.TrackModel = _trackMod;
 }
コード例 #10
0
        private static Form GuiTestFramework(int test)
        {
            ////////////////////////////////////////////////////////////////////////////////////////
            //                              Initializations                                       //
            ////////////////////////////////////////////////////////////////////////////////////////


            // Environment object
            var environment = new SimulationEnvironment.SimulationEnvironment();

            IBlock b0 = new TrackModel.Block(1, StateEnum.Healthy, 0, 0, 0, new[] { 0, 0 }, 10, DirEnum.East, new[] { "" }, 0, 0, 0, "Red", 70);
            IBlock b1 = new TrackModel.Block(2, StateEnum.Healthy, 1, 0, 0, new[] { 1, 1 }, 10, DirEnum.East, new[] { "" }, 0, 0, 0, "Red", 70);
            IBlock b2 = new TrackModel.Block(3, StateEnum.Healthy, 2, 0, 0, new[] { 2, 2 }, 10, DirEnum.East, new[] { "" }, 0, 0, 0, "Red", 70);
            IBlock b3 = new TrackModel.Block(4, StateEnum.BrokenTrackFailure, 3, 0, 0, new[] { 3, 3 }, 10, DirEnum.East, new[] { "" }, 0, 0, 0, "Red", 70);

            var sectionA = new List <IBlock> {
                b0
            };
            var sectionB = new List <IBlock> {
                b1, b2
            };
            var sectionC = new List <IBlock> {
                b3
            };

            // Previous track controller's circuit
            var prevCircuit = new TrackCircuit(environment, sectionA);
            // Our track circuit
            var currCircuit = new TrackCircuit(environment, sectionB);
            // Next track controller's circuit
            var nextCircuit = new TrackCircuit(environment, sectionC);

            var prev = new TrackController.TrackController(environment, prevCircuit);
            var curr = new TrackController.TrackController(environment, currCircuit);
            var next = new TrackController.TrackController(environment, nextCircuit);

            //Create TrackModel
            var trackMod = new TrackModel.TrackModel(environment);
            //Let TrackModel read in the lines before you proceed..shouldnt be done this way, but needed to stop CTC Office from faulting
            bool res = trackMod.provideInputFile("red.csv");

            //Console.WriteLine("Res was "+res);
            res = trackMod.provideInputFile("green.csv");
            //Console.WriteLine("Res was " + res);


            environment.TrackModel = trackMod;
            prev.Previous          = null;
            prev.Next = curr;

            curr.Previous = prev;
            curr.Next     = next;

            next.Previous = curr;
            next.Next     = null;

            // Assign the same track controller to both lines
            var office = new CTCOffice.CTCOffice(environment, prev, prev);

            environment.CTCOffice = office;
            environment.PrimaryTrackControllerGreen = prev;
            environment.PrimaryTrackControllerRed   = prev;


            ////////////////////////////////////////////////////////////////////////////////////////
            //                            End Initializations                                     //
            ////////////////////////////////////////////////////////////////////////////////////////

            var form    = new Form();
            var control = new UserControl();

            switch (test)
            {
            case 0:     // SystemScheduler

                var testSystemScheduler = new SystemScheduler.SystemScheduler(environment, office);
                control = new SystemSchedulerGUI(environment, testSystemScheduler, office);
                environment.StartTick();
                break;

            case 1:     // CTCOffice
                environment = null;

                b0 = null;
                b1 = null;
                b2 = null;
                b3 = null;

                sectionA = null;
                sectionB = null;
                sectionC = null;

                prevCircuit = null;
                currCircuit = null;
                nextCircuit = null;

                prev = null;
                curr = null;
                next = null;

                trackMod = null;
                office   = null;

                new CTCGUITest();
                break;

            case 2:     // TrackModel
                control = new TrackModelGUI(environment, trackMod);
                break;

            case 3:     // TrackController
                ITrainModel t = new Train(0, b0, environment);

                environment.AllTrains.Add(t);

                prevCircuit.Trains.Add(0, t);

                control = new TrackControllerUi(environment, environment.PrimaryTrackControllerRed);
                break;

            case 4:     // TrainModel
                var loc = new int[2];
                loc[0] = 10;
                loc[1] = 10;
                var start = new Block(0, StateEnum.Healthy, 0, 0, -0.02, loc, 100, DirEnum.East, null, 1, 2, 0, "Red", 70);
                environment.AddTrain(new Train(0, start, environment));
                environment.AddTrain(new Train(1, start, environment));

                var train0 = (Train)environment.AllTrains[0];
                train0.ChangeMovement(200);

                control = new TrainGUI(environment);

                break;

            case 5:     // TrainController
                var loc2 = new int[2];
                loc2[0] = 10;
                loc2[1] = 10;
                var start2 = new Block(0, StateEnum.Healthy, 0, 0, 0, loc2, 100, DirEnum.East, null, 1, 2, 0, "Red", 70);
                var tc     = new TrainController.TrainController(environment, new Train(0, start2, environment));
                control = new TrainControllerUI(tc, environment);
                break;
            }

            if (environment != null)
            {
                environment.StartTick();
            }

            if (form != null)
            {
                form.Controls.Add(control);
                form.AutoSize = true;
            }
            else
            {
                return(null);
            }


            return(form);
        }