public void AddAbsorbingModule_ValidModule_ShouldAddCorrectly() { IAbsorbingModule module = new HeatProcessor(1, 2); this.moduleContainer.AddAbsorbingModule(module); var expected = 1; var actual = this.moduleContainer.ModulesByInput.Count; Assert.AreEqual(expected, actual); }
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)); }
public void TestAddAbsorbingModulesWithOverCapacity() { var capacity = 1; ModuleContainer moduleContainer = new ModuleContainer(capacity); var module1 = new HeatProcessor(1, 100); var modele2 = new CooldownSystem(2, 200); var actual = moduleContainer.TotalHeatAbsorbing; var expected = 0; Assert.That(actual, Is.EqualTo(expected)); }
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)); }
public void TotalHeatAbsorbing_ShouldReturnCorrectValue() { IAbsorbingModule firstModule = new HeatProcessor(1, 2); IAbsorbingModule secondModule = new HeatProcessor(2, 3); this.moduleContainer.AddAbsorbingModule(firstModule); this.moduleContainer.AddAbsorbingModule(secondModule); var expected = 5; var actual = this.moduleContainer.TotalHeatAbsorbing; Assert.AreEqual(expected, actual); }
public void AddAbsorbingModule_RemovesOldestModule() { IAbsorbingModule firstModule = new HeatProcessor(1, 2); IAbsorbingModule secondModule = new HeatProcessor(2, 3); IAbsorbingModule thirdModule = new HeatProcessor(3, 4); IAbsorbingModule fourthModule = new HeatProcessor(4, 5); this.moduleContainer.AddAbsorbingModule(firstModule); this.moduleContainer.AddAbsorbingModule(secondModule); this.moduleContainer.AddAbsorbingModule(thirdModule); this.moduleContainer.AddAbsorbingModule(fourthModule); Assert.AreEqual(3, this.moduleContainer.ModulesByInput.Count); }
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)); }
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"); }
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)); }
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)); }
public void AddAbsorbingModuleMethod() { IAbsorbingModule absorbongyModule = new HeatProcessor(2, 20); this.moduleContainer.AddAbsorbingModule(absorbongyModule); //Method should add energyModule long expectedResult = 20; long actualResult = this.moduleContainer.TotalHeatAbsorbing; Assert.That(actualResult, Is.EqualTo(expectedResult), "Total energy output should be 20"); //Method should throws exceptio if no parameter is provided Assert.Throws <ArgumentException>(() => this.moduleContainer.AddAbsorbingModule(null), "Method should throws ArgumentException"); }
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)); }
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); }
// Parameters – reactorId(int), type(string), additionalParameter(int). public string ModuleCommand(IList <string> arguments) { int reactorId = int.Parse(arguments[0]); string moduleType = arguments[1]; int additionalParameter = int.Parse(arguments[2]); // Creates a Module of the given type with the next id and adds // it to the ModuleContainer of the Reactor with the given reactorId. // The type will either be “CryogenRod”, “HeatProcessor” or “CoolingSystem int currentId = this.currentId; // System.Console.WriteLine("CNT (BEFORE): " + this.modules.Count); switch (moduleType) { case "CryogenRod": IEnergyModule cryogenRod = new CryogenRod(this.currentId, additionalParameter); // this.currentId++; this.reactors[reactorId].AddEnergyModule(cryogenRod); this.identifiableObjects.Add(cryogenRod.Id, cryogenRod); this.modules.Add(cryogenRod.Id, cryogenRod); break; case "HeatProcessor": IAbsorbingModule heatProcessor = new HeatProcessor(this.currentId, additionalParameter); // this.currentId++; this.reactors[reactorId].AddAbsorbingModule(heatProcessor); this.identifiableObjects.Add(heatProcessor.Id, heatProcessor); this.modules.Add(heatProcessor.Id, heatProcessor); break; case "CooldownSystem": IAbsorbingModule cooldownSystem = new CooldownSystem(this.currentId, additionalParameter); // this.currentId++; this.reactors[reactorId].AddAbsorbingModule(cooldownSystem); this.identifiableObjects.Add(cooldownSystem.Id, cooldownSystem); this.modules.Add(cooldownSystem.Id, cooldownSystem); break; } //System.Console.WriteLine("CNT (AFTER): " + this.modules.Count); string result = string.Format(Constants.ModuleCreateMessage, moduleType, this.currentId++, reactorId); return(result); }
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); }
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); }
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)); }
public string ModuleCommand(IList <string> arguments) { int reactorId = int.Parse(arguments[0]); string moduleType = arguments[1]; int additionalParameter = int.Parse(arguments[2]); string moduleName = string.Empty; switch (moduleType) { case "CryogenRod": IEnergyModule cryogenRod = new CryogenRod(this.currentId, additionalParameter); moduleName = cryogenRod.GetType().Name; this.reactors[reactorId].AddEnergyModule(cryogenRod); this.identifiableObjects.Add(cryogenRod.Id, cryogenRod); this.modules.Add(cryogenRod.Id, cryogenRod); break; case "HeatProcessor": IAbsorbingModule heatProcessor = new HeatProcessor(this.currentId, additionalParameter); moduleName = heatProcessor.GetType().Name; this.reactors[reactorId].AddAbsorbingModule(heatProcessor); this.identifiableObjects.Add(heatProcessor.Id, heatProcessor); this.modules.Add(heatProcessor.Id, heatProcessor); break; case "CooldownSystem": IAbsorbingModule cooldownSystem = new CooldownSystem(this.currentId, additionalParameter); moduleName = cooldownSystem.GetType().Name; this.reactors[reactorId].AddAbsorbingModule(cooldownSystem); this.identifiableObjects.Add(cooldownSystem.Id, cooldownSystem); this.modules.Add(cooldownSystem.Id, cooldownSystem); break; } string result = string.Format(Constants.ModuleCreateMessage, moduleName, this.currentId++, reactorId); return(result); }
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); }