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 PersonnelTest1()
        {
            List<IRole> roles = new List<IRole>();
            roles.Add(new XRayRole());
            Personnel p1 = new Personnel(1,roles);
            bool pass1 = roles == p1.get_roles();

            IRole loaderrole = new LoaderRole();
            roles.Add(loaderrole);
            p1.add_role(loaderrole);
            bool pass2 = roles == p1.get_roles();

            roles.Remove(loaderrole);
            p1.remove_role(new LoaderRole());
            p1.add_role(loaderrole);
            bool pass3 = roles == p1.get_roles();

            bool fail1 = false;
            try
            {
                p1.add_role(new LoaderRole());
            }
            catch (Exception e)
            {
                if (e.GetType().FullName == "System.Diagnostics.Contracts.__ContractsRuntime+ContractException")
                    fail1 = true;

            }

            Assert.IsTrue(pass1);
            Assert.IsTrue(pass2);
            Assert.IsTrue(pass3);
            Assert.IsTrue(fail1);
        }
        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");
        }
Ejemplo n.º 5
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 void PersonnelTest2()
        {
            List<IRole> roles = new List<IRole>();

            Console.WriteLine("Add LoaderRole");
            roles.Add(new LoaderRole());

            Console.WriteLine("Add StuckLuggageRole");
            roles.Add(new StuckLuggageRole());

            Personnel p = new Personnel(1, roles);

            Console.WriteLine("Roles:");
            foreach (IRole role in p.get_roles())
            {
                Console.WriteLine(role);
            }

            p.remove_role(new StuckLuggageRole());
            Console.WriteLine("Removed StuckLuggageRole");

            Console.WriteLine("Roles:");
            foreach (IRole role in p.get_roles())
            {
                Console.WriteLine(role);
            }

            Console.WriteLine("Add XRayRole");
            p.add_role(new XRayRole());

            Console.WriteLine("Roles:");
            foreach (IRole role in p.get_roles())
            {
                Console.WriteLine(role);
            }
        }
 public void returnPerson(Personnel person)
 {
     this.personnel.Add(person);
 }