Esempio n. 1
0
        public void Run(string destinationString, int expectedTime)
        {
            var cargoes = new List <Cargo>();

            var destinations = destinationString.Split(",", StringSplitOptions.RemoveEmptyEntries);

            foreach (var destinationName in destinations)
            {
                var destination = Destination.FromString(destinationName);

                var cargoId = SequentialIdGenerator.GenerateIdFor(SequentialIdGenerator.Entity.Cargo);

                var cargo = new Cargo(cargoId, destination);

                cargoes.Add(cargo);

                _deliveryManager.PlanDelivery(cargo);
            }

            int time = 0;

            while (!cargoes.All(cargo => cargo.IsDelivered))
            {
                _deliveryManager.Tick(time);

                time++;
            }

            Assert.Equal(expectedTime, time - 1);
        }
        public TransportManager()
        {
            var truck1Id = SequentialIdGenerator.GenerateIdFor(SequentialIdGenerator.Entity.Truck);
            var truck1   = new Truck(truck1Id);

            var truck2Id = SequentialIdGenerator.GenerateIdFor(SequentialIdGenerator.Entity.Truck);
            var truck2   = new Truck(truck2Id);

            var ship1Id = SequentialIdGenerator.GenerateIdFor(SequentialIdGenerator.Entity.Ship);
            var ship1   = new Ship(ship1Id);

            _availableTransport = new List <ITransport> {
                truck1, truck2, ship1
            };
        }
Esempio n. 3
0
        public void Init()
        {
            var lines = new List <char[]>
            {
                "00ABC".ToCharArray(),
                "0BCAD".ToCharArray()
            };

            Configuration = new Mock <IConfiguration>();
            Configuration.SetupGet(conf => conf.EmptySlotCharacter).Returns('0');
            Configuration.SetupGet(conf => conf.SortingLineMaximumCapacity).Returns(5);
            Configuration.SetupGet(conf => conf.YardLocomotiveMaximumCapacity).Returns(1);

            Destination = 'A';
            IdGenerator = new SequentialIdGenerator();

            Yard       = new Yard(IdGenerator, Configuration.Object, lines);
            Yardmaster = Yard.Yardmaster;
        }
Esempio n. 4
0
        public static void Main(string[] args)
        {
            var configuration = new Configuration();
            var idGenerator   = new SequentialIdGenerator();

            var fileReader = new FileReader();
            var ui         = new ConsoleUtil(configuration, fileReader);

            do
            {
                ui.ShowMessage("Welcome to the Marshalling Yard!");

                // Load sorting lines from file or prompt the user for file location
                ui.BeginSection();
                var   lines = ui.GetSortingLines();
                IYard yard  = null;
                try
                {
                    yard = new Yard(idGenerator, configuration, lines);
                }
                catch (InvalidOperationException)
                {
                    var message = "Cannot create marshalling yard! Check the application's parameters.";
                    ui.ShowErrorMessage(message);
                    break;
                }

                var yardmaster = yard.Yardmaster;

                // Show initial sorting lines
                ui.ShowMessage("Initial sorting lines:");
                var sortingLines = yard.GetSortingLines().Select(line => line.ToString());
                ui.ShowList(sortingLines);

                // Prompt user for destination
                ui.BeginSection();
                var destination = ui.GetDestination();

                // Create navigational map and move cars
                var linesMap = yard.GetLinesMap(destination);
                var steps    = yardmaster.AssembleTrain(linesMap);

                // Show list of steps
                ui.BeginSection();
                ui.ShowMessage($"Selected destination: {destination}");
                ui.ShowMessage("Movements:");
                ui.ShowList(steps.Select(step => step.ToString()));

                // Show total of movements
                steps.Select(step => step.ToString());
                ui.ShowMessage($"Total of movements: {steps.Count()}.");

                // Show final sorting lines
                ui.BeginSection();
                ui.ShowMessage("Final sorting lines:");
                sortingLines = yard.GetSortingLines().Select(line => line.ToString());
                ui.ShowList(sortingLines);

                // Show train line
                ui.BeginSection();
                ui.ShowMessage("Train line:");
                var trainLine = yard.TrainLine.ToString();
                ui.ShowList(new[] { trainLine });
                ui.ShowMessage($"Total of cars in train line: {trainLine.Count()}.");
            } while (!ui.HasUserChosenToExit());
        }