Beispiel #1
0
        public void TestDefaultCommandInterruptingCommandCanceled()
        {
            ASubsystem subsystem = new ASubsystem();

            MockCommand defaultCommand = new MockCommand();

            defaultCommand.AddRequires(subsystem);

            MockCommand anotherCommand = new MockCommand();

            anotherCommand.AddRequires(subsystem);

            AssertCommandState(defaultCommand, 0, 0, 0, 0, 0);
            subsystem.Init(defaultCommand);
            subsystem.PublicInitDefaultCommand();
            AssertCommandState(defaultCommand, 0, 0, 0, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(defaultCommand, 0, 0, 0, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(defaultCommand, 1, 1, 1, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(defaultCommand, 1, 2, 2, 0, 0);

            anotherCommand.Start();
            AssertCommandState(defaultCommand, 1, 2, 2, 0, 0);
            AssertCommandState(anotherCommand, 0, 0, 0, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(defaultCommand, 1, 3, 3, 0, 1);
            AssertCommandState(anotherCommand, 0, 0, 0, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(defaultCommand, 1, 3, 3, 0, 1);
            AssertCommandState(anotherCommand, 1, 1, 1, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(defaultCommand, 1, 3, 3, 0, 1);
            AssertCommandState(anotherCommand, 1, 2, 2, 0, 0);
            anotherCommand.Cancel();
            AssertCommandState(defaultCommand, 1, 3, 3, 0, 1);
            AssertCommandState(anotherCommand, 1, 2, 2, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(defaultCommand, 1, 3, 3, 0, 1);
            AssertCommandState(anotherCommand, 1, 2, 2, 0, 1);
            Scheduler.Instance.Run();
            AssertCommandState(defaultCommand, 2, 4, 4, 0, 1);
            AssertCommandState(anotherCommand, 1, 2, 2, 0, 1);
            Scheduler.Instance.Run();
            AssertCommandState(defaultCommand, 2, 5, 5, 0, 1);
            AssertCommandState(anotherCommand, 1, 2, 2, 0, 1);
        }
 public void TestRunAndCancel()
 {
     MockCommand command = new MockCommand();
     command.Start();
     AssertCommandState(command, 0, 0, 0, 0, 0);
     Scheduler.Instance.Run();
     AssertCommandState(command, 0, 0, 0, 0, 0);
     Scheduler.Instance.Run();
     AssertCommandState(command, 1, 1, 1, 0, 0);
     Scheduler.Instance.Run();
     AssertCommandState(command, 1, 2, 2, 0, 0);
     Scheduler.Instance.Run();
     AssertCommandState(command, 1, 3, 3, 0, 0);
     command.Cancel();
     AssertCommandState(command, 1, 3, 3, 0, 0);
     Scheduler.Instance.Run();
     AssertCommandState(command, 1, 3, 3, 0, 1);
     Scheduler.Instance.Run();
     AssertCommandState(command, 1, 3, 3, 0, 1);
 }
Beispiel #3
0
        public void TestRunAndCancel()
        {
            MockCommand command = new MockCommand();

            command.Start();
            AssertCommandState(command, 0, 0, 0, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(command, 0, 0, 0, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(command, 1, 1, 1, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(command, 1, 2, 2, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(command, 1, 3, 3, 0, 0);
            command.Cancel();
            AssertCommandState(command, 1, 3, 3, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(command, 1, 3, 3, 0, 1);
            Scheduler.Instance.Run();
            AssertCommandState(command, 1, 3, 3, 0, 1);
        }
        public void TestDefaultCommandInterruptingCommandCanceled()
        {
            ASubsystem subsystem = new ASubsystem();

            MockCommand defaultCommand = new MockCommand();
            defaultCommand.AddRequires(subsystem);

            MockCommand anotherCommand = new MockCommand();
            anotherCommand.AddRequires(subsystem);

            AssertCommandState(defaultCommand, 0, 0, 0, 0, 0);
            subsystem.Init(defaultCommand);
            subsystem.PublicInitDefaultCommand();
            AssertCommandState(defaultCommand, 0, 0, 0, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(defaultCommand, 0, 0, 0, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(defaultCommand, 1, 1, 1, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(defaultCommand, 1, 2, 2, 0, 0);

            anotherCommand.Start();
            AssertCommandState(defaultCommand, 1, 2, 2, 0, 0);
            AssertCommandState(anotherCommand, 0, 0, 0, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(defaultCommand, 1, 3, 3, 0, 1);
            AssertCommandState(anotherCommand, 0, 0, 0, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(defaultCommand, 1, 3, 3, 0, 1);
            AssertCommandState(anotherCommand, 1, 1, 1, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(defaultCommand, 1, 3, 3, 0, 1);
            AssertCommandState(anotherCommand, 1, 2, 2, 0, 0);
            anotherCommand.Cancel();
            AssertCommandState(defaultCommand, 1, 3, 3, 0, 1);
            AssertCommandState(anotherCommand, 1, 2, 2, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(defaultCommand, 1, 3, 3, 0, 1);
            AssertCommandState(anotherCommand, 1, 2, 2, 0, 1);
            Scheduler.Instance.Run();
            AssertCommandState(defaultCommand, 2, 4, 4, 0, 1);
            AssertCommandState(anotherCommand, 1, 2, 2, 0, 1);
            Scheduler.Instance.Run();
            AssertCommandState(defaultCommand, 2, 5, 5, 0, 1);
            AssertCommandState(anotherCommand, 1, 2, 2, 0, 1);
        }
        public void Test()
        {
            MockCommand command1 = new MockCommand();
            MockCommand command2 = new MockCommand();
            MockCommand command3 = new MockCommand();
            MockCommand command4 = new MockCommand();

            button1.WhenPressed(command1);
            button1.WhenReleased(command2);
            button1.WhileHeld(command3);
            button2.WhileHeld(command4);

            AssertCommandState(command1, 0, 0, 0, 0, 0);
            AssertCommandState(command2, 0, 0, 0, 0, 0);
            AssertCommandState(command3, 0, 0, 0, 0, 0);
            AssertCommandState(command4, 0, 0, 0, 0, 0);
            button1.SetPressed(true);
            AssertCommandState(command1, 0, 0, 0, 0, 0);
            AssertCommandState(command2, 0, 0, 0, 0, 0);
            AssertCommandState(command3, 0, 0, 0, 0, 0);
            AssertCommandState(command4, 0, 0, 0, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(command1, 0, 0, 0, 0, 0);
            AssertCommandState(command2, 0, 0, 0, 0, 0);
            AssertCommandState(command3, 0, 0, 0, 0, 0);
            AssertCommandState(command4, 0, 0, 0, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(command1, 1, 1, 1, 0, 0);
            AssertCommandState(command2, 0, 0, 0, 0, 0);
            AssertCommandState(command3, 1, 1, 1, 0, 0);
            AssertCommandState(command4, 0, 0, 0, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(command1, 1, 2, 2, 0, 0);
            AssertCommandState(command2, 0, 0, 0, 0, 0);
            AssertCommandState(command3, 1, 2, 2, 0, 0);
            AssertCommandState(command4, 0, 0, 0, 0, 0);
            button2.SetPressed(true);
            Scheduler.Instance.Run();
            AssertCommandState(command1, 1, 3, 3, 0, 0);
            AssertCommandState(command2, 0, 0, 0, 0, 0);
            AssertCommandState(command3, 1, 3, 3, 0, 0);
            AssertCommandState(command4, 0, 0, 0, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(command1, 1, 4, 4, 0, 0);
            AssertCommandState(command2, 0, 0, 0, 0, 0);
            AssertCommandState(command3, 1, 4, 4, 0, 0);
            AssertCommandState(command4, 1, 1, 1, 0, 0);
            button1.SetPressed(false);
            Scheduler.Instance.Run();
            AssertCommandState(command1, 1, 5, 5, 0, 0);
            AssertCommandState(command2, 0, 0, 0, 0, 0);
            AssertCommandState(command3, 1, 4, 4, 0, 1);
            AssertCommandState(command4, 1, 2, 2, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(command1, 1, 6, 6, 0, 0);
            AssertCommandState(command2, 1, 1, 1, 0, 0);
            AssertCommandState(command3, 1, 4, 4, 0, 1);
            AssertCommandState(command4, 1, 3, 3, 0, 0);
            button2.SetPressed(false);
            Scheduler.Instance.Run();
            AssertCommandState(command1, 1, 7, 7, 0, 0);
            AssertCommandState(command2, 1, 2, 2, 0, 0);
            AssertCommandState(command3, 1, 4, 4, 0, 1);
            AssertCommandState(command4, 1, 3, 3, 0, 1);
            command1.Cancel();
            Scheduler.Instance.Run();
            AssertCommandState(command1, 1, 7, 7, 0, 1);
            AssertCommandState(command2, 1, 3, 3, 0, 0);
            AssertCommandState(command3, 1, 4, 4, 0, 1);
            AssertCommandState(command4, 1, 3, 3, 0, 1);
            command2.SetHasFinished(true);
            Scheduler.Instance.Run();
            AssertCommandState(command1, 1, 7, 7, 0, 1);
            AssertCommandState(command2, 1, 4, 4, 1, 0);
            AssertCommandState(command3, 1, 4, 4, 0, 1);
            AssertCommandState(command4, 1, 3, 3, 0, 1);
            Scheduler.Instance.Run();
            AssertCommandState(command1, 1, 7, 7, 0, 1);
            AssertCommandState(command2, 1, 4, 4, 1, 0);
            AssertCommandState(command3, 1, 4, 4, 0, 1);
            AssertCommandState(command4, 1, 3, 3, 0, 1);
        }
Beispiel #6
0
        public void Test()
        {
            MockCommand command1 = new MockCommand();
            MockCommand command2 = new MockCommand();
            MockCommand command3 = new MockCommand();
            MockCommand command4 = new MockCommand();

            m_button1.WhenPressed(command1);
            m_button1.WhenReleased(command2);
            m_button1.WhileHeld(command3);
            m_button2.WhileHeld(command4);

            AssertCommandState(command1, 0, 0, 0, 0, 0);
            AssertCommandState(command2, 0, 0, 0, 0, 0);
            AssertCommandState(command3, 0, 0, 0, 0, 0);
            AssertCommandState(command4, 0, 0, 0, 0, 0);
            m_button1.SetPressed(true);
            AssertCommandState(command1, 0, 0, 0, 0, 0);
            AssertCommandState(command2, 0, 0, 0, 0, 0);
            AssertCommandState(command3, 0, 0, 0, 0, 0);
            AssertCommandState(command4, 0, 0, 0, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(command1, 0, 0, 0, 0, 0);
            AssertCommandState(command2, 0, 0, 0, 0, 0);
            AssertCommandState(command3, 0, 0, 0, 0, 0);
            AssertCommandState(command4, 0, 0, 0, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(command1, 1, 1, 1, 0, 0);
            AssertCommandState(command2, 0, 0, 0, 0, 0);
            AssertCommandState(command3, 1, 1, 1, 0, 0);
            AssertCommandState(command4, 0, 0, 0, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(command1, 1, 2, 2, 0, 0);
            AssertCommandState(command2, 0, 0, 0, 0, 0);
            AssertCommandState(command3, 1, 2, 2, 0, 0);
            AssertCommandState(command4, 0, 0, 0, 0, 0);
            m_button2.SetPressed(true);
            Scheduler.Instance.Run();
            AssertCommandState(command1, 1, 3, 3, 0, 0);
            AssertCommandState(command2, 0, 0, 0, 0, 0);
            AssertCommandState(command3, 1, 3, 3, 0, 0);
            AssertCommandState(command4, 0, 0, 0, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(command1, 1, 4, 4, 0, 0);
            AssertCommandState(command2, 0, 0, 0, 0, 0);
            AssertCommandState(command3, 1, 4, 4, 0, 0);
            AssertCommandState(command4, 1, 1, 1, 0, 0);
            m_button1.SetPressed(false);
            Scheduler.Instance.Run();
            AssertCommandState(command1, 1, 5, 5, 0, 0);
            AssertCommandState(command2, 0, 0, 0, 0, 0);
            AssertCommandState(command3, 1, 4, 4, 0, 1);
            AssertCommandState(command4, 1, 2, 2, 0, 0);
            Scheduler.Instance.Run();
            AssertCommandState(command1, 1, 6, 6, 0, 0);
            AssertCommandState(command2, 1, 1, 1, 0, 0);
            AssertCommandState(command3, 1, 4, 4, 0, 1);
            AssertCommandState(command4, 1, 3, 3, 0, 0);
            m_button2.SetPressed(false);
            Scheduler.Instance.Run();
            AssertCommandState(command1, 1, 7, 7, 0, 0);
            AssertCommandState(command2, 1, 2, 2, 0, 0);
            AssertCommandState(command3, 1, 4, 4, 0, 1);
            AssertCommandState(command4, 1, 3, 3, 0, 1);
            command1.Cancel();
            Scheduler.Instance.Run();
            AssertCommandState(command1, 1, 7, 7, 0, 1);
            AssertCommandState(command2, 1, 3, 3, 0, 0);
            AssertCommandState(command3, 1, 4, 4, 0, 1);
            AssertCommandState(command4, 1, 3, 3, 0, 1);
            command2.SetHasFinished(true);
            Scheduler.Instance.Run();
            AssertCommandState(command1, 1, 7, 7, 0, 1);
            AssertCommandState(command2, 1, 4, 4, 1, 0);
            AssertCommandState(command3, 1, 4, 4, 0, 1);
            AssertCommandState(command4, 1, 3, 3, 0, 1);
            Scheduler.Instance.Run();
            AssertCommandState(command1, 1, 7, 7, 0, 1);
            AssertCommandState(command2, 1, 4, 4, 1, 0);
            AssertCommandState(command3, 1, 4, 4, 0, 1);
            AssertCommandState(command4, 1, 3, 3, 0, 1);
        }