public void SortingForwarderTest1() { List<IRole> roles = new List<IRole>(); roles.Add(new LoaderRole()); Personnel p1 = new Personnel(2, roles); List<Personnel> pl = new List<Personnel>(); PersonnelController pc = new PersonnelController(pl); List<IProblem> problems = new List<IProblem>(); problems.Add(new Stuck(0, pc)); Airplane ap = new Airplane(problems, 2); ILuggageQueue queue = new FIFOQueue(); bool pass1 = queue.Count() == 0; queue.enqueueLuggage(1, new LuggageBag(ap)); bool pass2 = queue.Count() == 1; List<IComponent> nextComponents = new List<IComponent>(); nextComponents.Add(ap); SortingForwarder s = new SortingForwarder(queue,nextComponents); Thread.Sleep(1000); s.processLuggage(new LuggageBag(ap)); bool pass3 = queue.Count() == 0; Assert.IsTrue(pass1); Assert.IsTrue(pass2); Assert.IsTrue(pass3); }
public void testConveyorBeltSplitterConstructor() { int dequeueDeltaMiliSeconds = 1000; int id = 0; List<IProblem> problems = new List<IProblem>(); ConveyorBeltSplitter cbs = new ConveyorBeltSplitter(dequeueDeltaMiliSeconds, problems, id); Assert.AreEqual(cbs.name, "Splitter number: " + id.ToString()); Assert.AreEqual(cbs.stuck, false); IComponent destination = cbs; LuggageBag lb = new LuggageBag(destination); Assert.AreEqual(cbs.getSinks().Count, 0); // Check count() and enqueluggage with problem and without problem List<Personnel> plist = new List<Personnel>(); List<IRole> roles = new List<IRole>(); roles.Add(new StuckLuggageRole()); Personnel p1 = new Personnel(1, roles); plist.Add(p1); PersonnelController pc = new PersonnelController(plist); Stuck s = new Stuck(0, pc); problems.Add(s); cbs.EnqueueLuggage(lb); bool fail1 = true; try { cbs.getSinks(); } catch (Exception e) { if (e.GetType().FullName == "System.Diagnostics.Contracts.__ContractsRuntime+ContractException") fail1 = false; } Assert.IsTrue(fail1); /** Assert.AreEqual(1,cbs.Count()); s = new Stuck(100, pc); problems.Add(s); cbs.EnqueueLuggage(lb); Assert.AreEqual(2,cbs.Count()); try { cbs.addNextComponent(cbs); } catch (NotImplementedException) { Assert.IsTrue(true); } Assert.AreEqual(cbs.getSinks().Count, 1);**/ }
public void testAirplaneConstructor() { List<IProblem> problems = new List<IProblem>(); int id= 0; Airplane ap = new Airplane(problems, id); // Constructor() Assert.AreEqual(ap.name, "Airplane number: "+id.ToString()); Assert.AreEqual(ap.initialized, true); Assert.AreEqual(ap.stuck, false); IComponent destination = ap; LuggageBag lb = new LuggageBag(destination); // Check count() and enqueluggage with problem and without problem List<Personnel> plist = new List<Personnel>(); List<IRole> roles = new List<IRole>(); roles.Add(new StuckLuggageRole()); Personnel p1 = new Personnel(1, roles); plist.Add(p1); PersonnelController pc = new PersonnelController(plist); Stuck s = new Stuck(0, pc); problems.Add(s); ap.EnqueueLuggage(lb); Thread.Sleep(1000); Assert.AreEqual(0, ap.Count()); s = new Stuck(100, pc); problems.Add(s); ap.EnqueueLuggage(lb); Assert.AreEqual(1, ap.Count()); //DequeLuggage() //ap.DequeueLuggage(); //Assert.AreEqual(ap.Count(), 0); //AddNextComponent() try { ap.addNextComponent(ap); } catch (NotImplementedException) { Assert.IsTrue(true); } //InAndOutCounters() Assert.AreEqual(ap.InAndOutCounters().Item1, 2); //GetSinks() //Assert.AreEqual(ap.getSinks(), ); Assert.AreEqual(ap.getSinks().Count, 1); //Assert.AreEqual(ap.getSinks().ToString(), "Airplane number: 0"); }
public void StuckTest1() { List<Personnel> plist = new List<Personnel>(); List<IRole> roles = new List<IRole>(); roles.Add(new StuckLuggageRole()); Personnel p1 = new Personnel(1, roles); plist.Add(p1); PersonnelController pc = new PersonnelController(plist); Stuck s = new Stuck(0,pc); bool fail1 = s.Fail(); s = new Stuck(100, pc); bool fail2 = s.Fail(); bool fail3 = false; try { s = new Stuck(-1, pc); s.Fail(); } catch (Exception e) { if (e.GetType().FullName == "System.Diagnostics.Contracts.__ContractsRuntime+ContractException") fail3 = true; } bool fail4 = false; try { s = new Stuck(101, pc); s.Fail(); } catch (Exception e) { if (e.GetType().FullName == "System.Diagnostics.Contracts.__ContractsRuntime+ContractException") fail4 = true; } //s.HandleProblem(); Assert.IsFalse(fail1); Assert.IsTrue(fail2); Assert.IsTrue(fail3); Assert.IsTrue(fail4); }
public void PersonnelControllerTest1() { List<IRole> roles1 = new List<IRole>(); roles1.Add(new LoaderRole()); Personnel p1 = new Personnel(1, roles1); List<Personnel> personnel = new List<Personnel>(); personnel.Add(p1); PersonnelController pc = new PersonnelController(personnel); List<IRole> roles2 = new List<IRole>(); roles2.Add(new StuckLuggageRole()); Personnel p2 = new Personnel(2, roles2); pc.returnPerson(p2); Personnel p3 = pc.acquirePersonWithRole(new StuckLuggageRole()); bool pass1 = p2 == p3; Assert.IsNotNull(p3); Assert.IsTrue(pass1); }
public Stuck(double stuck_constant, PersonnelController pc) { Contract.Requires(stuck_constant >= 0 && stuck_constant <= 100, "Wrong value for stuck constant"); this.stuck_constant = stuck_constant; this.pc = pc; }