コード例 #1
0
        public void CheckAddAfterReachingCappacity()
        {
            int           cappacityOfContainer      = 2;
            int           moduleId                  = 1;
            int           moduleAdditionalParameter = 10;
            IContainer    container                 = new ModuleContainer(cappacityOfContainer);
            IEnergyModule module0 = new CryogenRod(moduleId, moduleAdditionalParameter);

            container.AddEnergyModule(module0);
            IAbsorbingModule module1 = new HeatProcessor(moduleId, moduleAdditionalParameter);

            container.AddAbsorbingModule(module1);
            int expectedModuleCount = 2;
            int actuallModuleCount  = container.ModulesByInput.Count;

            Assert.AreEqual(expectedModuleCount, actuallModuleCount, "Module is not added count not increased");
            moduleId++;
            container.AddAbsorbingModule(new HeatProcessor(moduleId, moduleAdditionalParameter));
            actuallModuleCount = container.ModulesByInput.Count;
            Assert.AreEqual(expectedModuleCount, actuallModuleCount, "Module is not added count not increased");
            Assert.That(container.ModulesByInput.Where(x => x is IEnergyModule).Count() == 0, "Container does not remove uppon overflow the first to enter");

            container.AddEnergyModule(new CryogenRod(moduleId++, moduleAdditionalParameter));
            container.AddEnergyModule(new CryogenRod(moduleId, moduleAdditionalParameter));
            Assert.That(container.ModulesByInput.Where(x => x is IAbsorbingModule).Count() == 0, "Container does not remove uppon overflow the first to enter");
        }
コード例 #2
0
        public void Test1()
        {
            var moduleContainer       = new ModuleContainer(3);
            var absorbingModule       = new CooldownSystem(2, 0);
            var secondabsorbingModule = new CooldownSystem(5, 100);
            var energyModule          = new CryogenRod(3, 200);
            var secondEnergyModule    = new CryogenRod(4, 100);

            moduleContainer.AddAbsorbingModule(absorbingModule);
            moduleContainer.AddAbsorbingModule(secondabsorbingModule);
            moduleContainer.AddEnergyModule(energyModule);

            moduleContainer.AddEnergyModule(secondEnergyModule);

            var actualTotalHeatAbsorbingResult = moduleContainer.TotalHeatAbsorbing;
            var actualTotalEnergyOutput        = moduleContainer.TotalEnergyOutput;

            var expectedTotalHeatAbsorbingResult = 100;
            var expectedTotalEnergyOutput        = 300;


            var actualModulesByInputCount   = moduleContainer.ModulesByInput.Count;
            var expectedModulesByInputCount = 3;

            Assert.AreEqual(expectedTotalHeatAbsorbingResult, actualTotalHeatAbsorbingResult);
            Assert.AreEqual(expectedTotalEnergyOutput, actualTotalEnergyOutput);
            Assert.AreEqual(expectedModulesByInputCount, actualModulesByInputCount);

            //Assert.AreEqual(actualModulesByInputCount, expectedModulesByInputCount);
            //Assert.Throws<ArgumentException>(() => moduleContainer.AddAbsorbingModule(null));
        }
コード例 #3
0
        public void AddModuleValidation()
        {
            moduleContainer.AddAbsorbingModule(new HeatProcessor(1, 100));
            moduleContainer.AddAbsorbingModule(new CooldownSystem(2, 200));
            moduleContainer.AddEnergyModule(new CryogenRod(3, 300));
            moduleContainer.AddEnergyModule(new CryogenRod(4, 400));

            Assert.That(moduleContainer.ModulesByInput.Count, Is.EqualTo(4));
            Assert.That(moduleContainer.TotalEnergyOutput, Is.EqualTo(700));
            Assert.AreEqual(moduleContainer.TotalHeatAbsorbing, 300);
        }
コード例 #4
0
        public void TestToRemoveOldestModule()
        {
            var moduleContainer = new ModuleContainer(1);

            var module1 = new HeatProcessor(1, 200);
            var module2 = new HeatProcessor(2, 300);

            moduleContainer.AddAbsorbingModule(module1);
            moduleContainer.AddAbsorbingModule(module2);

            System.Console.WriteLine(moduleContainer.TotalHeatAbsorbing);
            Assert.That(moduleContainer.ModulesByInput.Count, Is.EqualTo(1));
        }
コード例 #5
0
        public void TestingHeat()
        {
            var moduleContainer = new ModuleContainer(2);

            var cooldown = new CooldownSystem(13, 41);
            var heatProc = new HeatProcessor(3, 14);

            moduleContainer.AddEnergyModule(new CryogenRod(31, 41));
            moduleContainer.AddAbsorbingModule(heatProc);
            moduleContainer.AddAbsorbingModule(cooldown);

            var expectedAbsorbing = 55;

            Assert.That(expectedAbsorbing, Is.EqualTo(moduleContainer.TotalHeatAbsorbing));
        }
コード例 #6
0
        public void CheckNullModuleAddThrowsArgumentException()
        {
            IContainer container = new ModuleContainer(10);

            Assert.That(() => container.AddEnergyModule(null), Throws.ArgumentException);
            Assert.That(() => container.AddAbsorbingModule(null), Throws.ArgumentException);
        }
コード例 #7
0
        public void WhenModuleIsFullRemovesFirst()
        {
            var moduleContainer = new ModuleContainer(3);
            var energy          = new CryogenRod(3, 13);
            var heatProc        = new HeatProcessor(4, 14);
            var prces           = new HeatProcessor(7, 14);
            var cooldown        = new CooldownSystem(1, 2);

            moduleContainer.AddAbsorbingModule(heatProc);
            moduleContainer.AddEnergyModule(energy);
            moduleContainer.AddAbsorbingModule(prces);
            moduleContainer.AddAbsorbingModule(cooldown);


            Assert.That(3, Is.EqualTo(moduleContainer.ModulesByInput.Count));
        }
コード例 #8
0
        public void TestAddAbsorbingModulesWithNull()
        {
            var             capacity        = 10;
            ModuleContainer moduleContainer = new ModuleContainer(capacity);

            Assert.That(() => moduleContainer.AddAbsorbingModule(null), Throws.ArgumentException);
        }
コード例 #9
0
        public void TestWhenCapacityIsEqualToInputModule()
        {
            var             capacity        = 1;
            ModuleContainer moduleContainer = new ModuleContainer(capacity);

            var modele1 = new CryogenRod(1, 100);

            moduleContainer.AddEnergyModule(modele1);

            var module2 = new HeatProcessor(2, 200);

            moduleContainer.AddAbsorbingModule(module2);

            var actualEnergy       = moduleContainer.TotalEnergyOutput;
            var expectedEnergy     = 0;
            var actualAbsorbsion   = moduleContainer.TotalHeatAbsorbing;
            var expectedAbsorbtion = 200;

            var actualModuleIntut   = moduleContainer.ModulesByInput.Count;
            var expectedModuleInput = 1;

            Assert.That(actualEnergy, Is.EqualTo(expectedEnergy));
            Assert.That(actualAbsorbsion, Is.EqualTo(expectedAbsorbtion));
            Assert.That(actualModuleIntut, Is.EqualTo(expectedModuleInput));
        }
コード例 #10
0
        public void AddAbsorbingModuleShouldThrowError()
        {
            var container = new ModuleContainer(10);
            IAbsorbingModule absorbingModule = null;

            Assert.Throws <ArgumentException>(() => container.AddAbsorbingModule(absorbingModule));
        }
コード例 #11
0
        public void AddAbsorbingModuleShouldRemoveOldestModule()
        {
            var container        = new ModuleContainer(3);
            var absorbingModule1 = new HeatProcessor(1, 100);
            var absorbingModule2 = new HeatProcessor(2, 100);
            var absorbingModule3 = new HeatProcessor(3, 100);
            var absorbingModule4 = new HeatProcessor(4, 100);

            container.AddAbsorbingModule(absorbingModule1);
            container.AddAbsorbingModule(absorbingModule2);
            container.AddAbsorbingModule(absorbingModule3);
            container.AddAbsorbingModule(absorbingModule4);

            Assert.AreEqual(300, container.TotalHeatAbsorbing);
            Assert.AreEqual(3, container.ModulesByInput.Count);
            Assert.AreEqual(2, container.ModulesByInput.First().Id);
        }
コード例 #12
0
        public void TotalHeatAbsorbingProperty()
        {
            var moduleContainer = new ModuleContainer(10);

            var absorbingModule  = new HeatProcessor(1, 100);
            var absorbingModule2 = new HeatProcessor(2, 100);

            moduleContainer.AddAbsorbingModule(absorbingModule);
            moduleContainer.AddAbsorbingModule(absorbingModule2);

            var actualHeatAbsorbing = moduleContainer.GetType()
                                      .GetProperty("TotalHeatAbsorbing", BindingFlags.Public | BindingFlags.Instance)
                                      .GetValue(moduleContainer);

            var expectedOutput = 200;

            Assert.AreEqual(expectedOutput, actualHeatAbsorbing);
        }
コード例 #13
0
        public void AddAbsorbingModuleTest()
        {
            var moduleContainer = new ModuleContainer(10);

            var absorbingModule = new HeatProcessor(1, 100);

            moduleContainer.AddAbsorbingModule(absorbingModule);

            FieldInfo fieldAbsorbingModules = moduleContainer.GetType()
                                              .GetField("absorbingModules", BindingFlags.NonPublic | BindingFlags.Instance);

            var actualCount   = (IDictionary)fieldAbsorbingModules.GetValue(moduleContainer);
            var expectedCount = 1;

            Assert.AreEqual(expectedCount, actualCount.Count);

            Assert.That(() => moduleContainer.AddAbsorbingModule(null), Throws.ArgumentException);
        }
コード例 #14
0
        public void AddingNullModulesThrowsException()
        {
            var moduleContainer = new ModuleContainer(5);

            Assert.That(() => { moduleContainer.AddEnergyModule(null); },
                        Throws.ArgumentException);

            Assert.That(() => { moduleContainer.AddAbsorbingModule(null); },
                        Throws.ArgumentException);
        }
コード例 #15
0
        public void TestToCreateAbsorbingModule()
        {
            var moduleContainer = new ModuleContainer(4);

            var module = new HeatProcessor(1, 200);

            moduleContainer.AddAbsorbingModule(module);

            System.Console.WriteLine(moduleContainer.TotalHeatAbsorbing);
            Assert.That(moduleContainer.TotalHeatAbsorbing, Is.EqualTo(200));
        }
コード例 #16
0
        public void TestProperties()
        {
            var             capacity        = 10;
            ModuleContainer moduleContainer = new ModuleContainer(capacity);

            var modele1 = new CryogenRod(1, 100);
            var module2 = new HeatProcessor(2, 200);
            var module3 = new CooldownSystem(3, 300);

            moduleContainer.AddEnergyModule(modele1);
            moduleContainer.AddAbsorbingModule(module2);
            moduleContainer.AddAbsorbingModule(module3);


            var actual   = moduleContainer.ModulesByInput.Count;
            var expected = 3;

            Assert.That(actual, Is.EqualTo(expected));
            Assert.That(moduleContainer.TotalEnergyOutput, Is.EqualTo(100));
            Assert.That(moduleContainer.TotalHeatAbsorbing, Is.EqualTo(500));
        }
コード例 #17
0
        public void TestIfModulesAreBeingAdded()
        {
            var moduleContainer = new ModuleContainer(5);
            var energy          = new CryogenRod(3, 13);
            var heatProc        = new HeatProcessor(3, 14);

            moduleContainer.AddAbsorbingModule(heatProc);
            moduleContainer.AddEnergyModule(energy);


            Assert.That(2, Is.EqualTo(moduleContainer.ModulesByInput.Count));
        }
コード例 #18
0
        public void TestHeatModule()
        {
            int moduleCapacity = 1;
            var cdSystem       = new CooldownSystem(1, 1000);

            ModuleContainer testContainer = new ModuleContainer(moduleCapacity);

            testContainer.AddAbsorbingModule(cdSystem);

            Assert.AreEqual(testContainer.ModulesByInput.Count, 1);
            Assert.AreEqual(testContainer.TotalEnergyOutput, 0);
            Assert.AreEqual(testContainer.TotalHeatAbsorbing, 1000);
        }
コード例 #19
0
        public void TestAddAbsorbingModules()
        {
            var             capacity        = 10;
            ModuleContainer moduleContainer = new ModuleContainer(capacity);

            IAbsorbingModule module1 = new HeatProcessor(1, 100);

            moduleContainer.AddAbsorbingModule(module1);

            var actual   = moduleContainer.TotalHeatAbsorbing;
            var expected = 100;

            Assert.That(actual, Is.EqualTo(expected));
        }
コード例 #20
0
        public void CheckAddAbsorbingModule()
        {
            int              cappacityOfContainer      = 1;
            int              moduleId                  = 1;
            int              moduleAdditionalParameter = 10;
            IContainer       container                 = new ModuleContainer(cappacityOfContainer);
            IAbsorbingModule module0 = new HeatProcessor(moduleId, moduleAdditionalParameter);

            container.AddAbsorbingModule(module0);
            int expectedModuleCount = 1;
            int actuallModuleCount  = container.ModulesByInput.Count;

            Assert.AreEqual(expectedModuleCount, actuallModuleCount, "Module is not added count not increased");
        }
コード例 #21
0
        public void TestingToString()
        {
            var moduleContainer = new ModuleContainer(5);


            var energy   = new CryogenRod(3, 13);
            var heatProc = new HeatProcessor(3, 14);

            moduleContainer.AddAbsorbingModule(heatProc);
            moduleContainer.AddEnergyModule(energy);

            var expectedEnergy = moduleContainer.TotalEnergyOutput;

            Assert.That(expectedEnergy, Is.EqualTo(moduleContainer.TotalEnergyOutput));
        }
コード例 #22
0
        public void CheckTotalEnergyAndAbsorbingOutput()
        {
            int        cappacityOfContainer      = 3;
            int        moduleId                  = 1;
            int        moduleAdditionalParameter = 15;
            IContainer container                 = new ModuleContainer(cappacityOfContainer);

            container.AddEnergyModule(new CryogenRod(moduleId++, moduleAdditionalParameter));
            container.AddEnergyModule(new CryogenRod(moduleId++, moduleAdditionalParameter));
            container.AddAbsorbingModule(new HeatProcessor(moduleId++, moduleAdditionalParameter));
            int expectedTotalEnergy = 30;

            Assert.AreEqual(expectedTotalEnergy, container.TotalEnergyOutput);

            int expectedTotalAbsorbing = 15;

            Assert.AreEqual(expectedTotalAbsorbing, container.TotalHeatAbsorbing);
        }
コード例 #23
0
        public void TestModuleContainer()
        {
            var moduleContainer = new ModuleContainer(5);

            List <IModule> modules = new List <IModule>()
            {
                new CooldownSystem(1, 10000), new CryogenRod(2, 140), new CryogenRod(3, 140),
                new CryogenRod(4, 140), new CryogenRod(5, 140), new HeatProcessor(6, 20000)
            };

            foreach (var module in modules)
            {
                if (module.GetType().Name == "CooldownSystem" || module.GetType().Name == "HeatProcessor")
                {
                    moduleContainer.AddAbsorbingModule((IAbsorbingModule)module);
                }
                else
                {
                    moduleContainer.AddEnergyModule((IEnergyModule)module);
                }
            }


            modules.RemoveAt(0);

            int index = 0;

            foreach (var module in moduleContainer.ModulesByInput)
            {
                Assert.AreEqual(module, modules[index]);
                index++;
            }

            long expectedEnergy = 560;
            long actualEnergy   = moduleContainer.TotalEnergyOutput;

            long expectedHeat = 20000;
            long actualHeat   = moduleContainer.TotalHeatAbsorbing;


            Assert.AreEqual(5, moduleContainer.ModulesByInput.Count);
            Assert.AreEqual(expectedEnergy, actualEnergy, "Invalid energy");
            Assert.AreEqual(expectedHeat, actualHeat, "Invalid heat");
        }
コード例 #24
0
        public void RemoveOldestModuleTest()
        {
            var moduleContainer = new ModuleContainer(10);

            var absorbingModule = new HeatProcessor(1, 100);
            var energyModule    = new CryogenRod(2, 100);

            moduleContainer.AddAbsorbingModule(absorbingModule);
            moduleContainer.AddEnergyModule(energyModule);

            MethodInfo removeOldestModule = moduleContainer.GetType()
                                            .GetMethod("RemoveOldestModule", BindingFlags.NonPublic | BindingFlags.Instance);

            FieldInfo fieldAbsorbingModules = moduleContainer.GetType()
                                              .GetField("absorbingModules", BindingFlags.NonPublic | BindingFlags.Instance);

            FieldInfo fieldEnergyModules = moduleContainer.GetType()
                                           .GetField("energyModules", BindingFlags.NonPublic | BindingFlags.Instance);

            var energyModuleField             = (IDictionary)fieldEnergyModules.GetValue(moduleContainer);
            var expectedResultForEnergyModule = 1;

            var absorbingModules            = (IDictionary)fieldAbsorbingModules.GetValue(moduleContainer);
            var expectedForAbsorbingModules = 0;

            removeOldestModule.Invoke(moduleContainer, null);

            FieldInfo fieldModulesByInput = moduleContainer.GetType()
                                            .GetField("modulesByInput", BindingFlags.NonPublic | BindingFlags.Instance);

            var actualValue = (IList)fieldModulesByInput.GetValue(moduleContainer);
            var expected    = 1;

            Assert.AreEqual(expectedResultForEnergyModule, energyModuleField.Count);
            Assert.AreEqual(expectedForAbsorbingModules, absorbingModules.Count);
            Assert.AreEqual(expected, actualValue.Count);
        }
コード例 #25
0
 public void WhenAddAbsorbingModuleCall_ShouldThrowExceptionIfGivenModuleIsNull()
 {
     Assert.Throws <ArgumentException>(() => moduleContainer.AddAbsorbingModule(null));
 }