Exemple #1
0
        public void ProcessWaste_SomeWaste_ThrowsException()
        {
            var holder  = new StrategyHolder();
            var garbage = new GarbageProcessor(holder);

            var waste = new StorableWaste("NuclearWaste", 10, 10);

            Assert.That(() => garbage.ProcessWaste(waste), Throws.ArgumentException);
        }
Exemple #2
0
        public void ProcessWaste()
        {
            double expectedRecCapital    = 4000;
            double expectedRecBurnEnergy = -5.7;
            double expectedBurnEnergy    = 97.0012;
            double expectedCapital       = 0;
            double expectedStorCapital   = -2.2961;
            double expectedStorEnergy    = -0.4592;

            BurnableGarbage   burnGarbage = new BurnableGarbage("Burnable", 3.657, 33.156);
            RecyclableGarbage recGarbage  = new RecyclableGarbage("rec", 1.14, 10);
            StorableGarbage   storGarbage = new StorableGarbage("stor", 1.57, 2.25);

            IStrategyHolder strategyHolder = new StrategyHolder();

            strategyHolder.AddStrategy(
                typeof(BurnableDisposableAttribute),
                new BurnableDisposalStrategy());

            strategyHolder.AddStrategy(
                typeof(RecyclableDisposableAttribute),
                new RecyclableDisposalStrategy());

            strategyHolder.AddStrategy(
                typeof(StorableDisposableAttribute),
                new StorableDisposalStrategy());

            IGarbageProcessor processor   = new GarbageProcessor(strategyHolder);
            IProcessingData   processData = processor.ProcessWaste(burnGarbage);

            Assert.AreEqual(expectedBurnEnergy, Math.Round(processData.EnergyBalance, 4));
            Assert.AreEqual(expectedCapital, processData.CapitalBalance);

            processData = processor.ProcessWaste(recGarbage);

            Assert.AreEqual(expectedRecBurnEnergy, Math.Round(processData.EnergyBalance, 1));
            Assert.AreEqual(expectedRecCapital, processData.CapitalBalance);

            processData = processor.ProcessWaste(storGarbage);

            Assert.AreEqual(expectedStorEnergy, Math.Round(processData.EnergyBalance, 4));
            Assert.AreEqual(expectedStorCapital, Math.Round(processData.CapitalBalance, 4));
        }
Exemple #3
0
        public void ProcessWaste_ShouldThrowArgumentException()
        {
            // Arrange
            var garbage          = new StorableWaste("glass", 10.5, 1.2);
            var strategyHolder   = new StrategyHolder();
            var garbageProcessor = new GarbageProcessor(strategyHolder);

            // Act and Assert
            garbageProcessor.ProcessWaste(garbage);
        }
Exemple #4
0
        public void ProcessWaste_ShouldReturnValidCurrentStrategy()
        {
            // Arrange
            var garbage          = new StorableWaste("glass", 10.5, 1.2);
            var strategyHolder   = new StrategyHolder();
            var garbageProcessor = new GarbageProcessor(strategyHolder);

            Type type = garbage.GetType();
            DisposableAttribute      disposalAttribute = (DisposableAttribute)type.GetCustomAttributes(true).FirstOrDefault(x => x.GetType() == typeof(DisposableAttribute));
            IGarbageDisposalStrategy currentStrategy   = new BurnableDisposalStrategy();
            var expectedResult = currentStrategy.ProcessGarbage(garbage);

            // Act
            var actualResult = garbageProcessor.ProcessWaste(garbage);

            // Assert
            Assert.AreEqual(expectedResult, actualResult);
        }
        private static void Main(string[] args)
        {
            double energy  = 0;
            double capital = 0;

            ManagementRequirement managementRequierement = null;

            var input = Console.ReadLine();

            while (input != "TimeToRecycle")
            {
                if (input == "Status")
                {
                    Console.WriteLine("Energy: {0:0.00} Capital: {1:0.00}", energy, capital);
                }
                else
                {
                    var commandArgs = input?.Split(' ', '|');

                    if (commandArgs?[0] == "ProcessGarbage")
                    {
                        var strategyHolder = new StrategyHolder();
                        strategyHolder.AddStrategy(typeof(RecyclableAttribute), new RecyclableGarbageDsiposalStrategy());
                        strategyHolder.AddStrategy(typeof(BurnableAttribute), new BurnableGarbageDisposalStrategy());
                        strategyHolder.AddStrategy(typeof(StorableAttribute), new StorableGarbageDisposalStrategy());

                        var garbageProcessor = new GarbageProcessor(strategyHolder);

                        var name        = commandArgs[1];
                        var weight      = Convert.ToDouble(commandArgs[2]);
                        var volumePerKg = Convert.ToDouble(commandArgs[3]);
                        var type        = commandArgs[4];

                        IWaste garbage = null;
                        switch (type)
                        {
                        case "Recyclable":
                            garbage = new RecyclableGarbage(name, volumePerKg, weight);
                            break;

                        case "Burnable":
                            garbage = new BurnableGarbage(name, volumePerKg, weight);
                            break;

                        case "Storable":
                            garbage = new StorableGarbage(name, volumePerKg, weight);
                            break;

                        default:
                            throw new ArgumentException();
                        }

                        if (managementRequierement != null &&
                            (managementRequierement.CapitalBalance > capital ||
                             managementRequierement.EnergyBalance > energy))
                        {
                            Type attrType = Type.GetType("RecyclingStation.WasteDisposal.Attributes." + managementRequierement.GarbageType + "Attribute");
                            strategyHolder.RemoveStrategy(attrType);
                        }

                        var data = garbageProcessor.ProcessWaste(garbage);
                        if (data != null)
                        {
                            energy  += data.EnergyBalance;
                            capital += data.CapitalBalance;

                            Console.WriteLine("{0:0.00} kg of {1} successfully processed!", weight, name);
                        }
                        else
                        {
                            Console.WriteLine("Processing Denied!");
                        }
                    }
                    else if (commandArgs?[0] == "ChangeManagementRequirement")
                    {
                        var energyBalance  = Convert.ToDouble(commandArgs[1]);
                        var capitalBalance = Convert.ToDouble(commandArgs[2]);
                        var garbageType    = commandArgs[3];

                        managementRequierement = new ManagementRequirement(energyBalance, capitalBalance, garbageType);

                        Console.WriteLine("Management requirement changed!");
                    }
                }

                input = Console.ReadLine();
            }
        }