Esempio n. 1
0
    void TestEventUsurp3()
    {
        // The agent should begin ticking. The Event 1 should start and pre-empt the agent.
        // Event 2 should pre-empt Event 1. Event 3 should pre-empt Event 2 before Event 2
        // can start. Event 1 should terminate properly, then Event 3 should execute fully.

        Debug.Log("TestEventUsurp");
        this.ticks = 0;

        TestSmartEvent event1 = new TestSmartEvent(obj1, agent);
        event1.Name = "Event1";

        TestSmartEvent event2 = new TestSmartEvent(obj1, obj2);
        event2.Name = "Event2";

        TestSmartEvent event3 = new TestSmartEvent(obj1, obj2);
        event3.Name = "Event3";

        Readout("Beginning", new IHasBehaviorEvent[] { event1, event2, event3 }, this.obj1, this.obj2, this.agent);

        this.agent.StartBehavior();
        Readout("Agent.StartBehavior() Results", new IHasBehaviorEvent[] { event1, event2, event3 }, this.obj1, this.obj2, this.agent);

        this.Tick(2, new IHasBehaviorEvent[] { event1, event2, event3 }, this.obj1, this.obj2, this.agent);

        event1.StartEvent(0.1f);
        Readout("event1.StartEvent() Results", new IHasBehaviorEvent[] { event1, event2, event3 }, this.obj1, this.obj2, this.agent);

        this.Tick(7, new IHasBehaviorEvent[] { event1, event2, event3 }, this.obj1, this.obj2, this.agent);

        // Same as the other two Usurp tests

        event2.StartEvent(0.2f);
        Readout("event2.StartEvent() Results", new IHasBehaviorEvent[] { event1, event2, event3 }, this.obj1, this.obj2, this.agent);
        DebugUtil.Assert(this.obj1.Behavior.Status == BehaviorStatus.InEvent);
        DebugUtil.Assert(this.obj2.Behavior.Status == BehaviorStatus.Idle);
        DebugUtil.Assert(this.agent.Behavior.Status == BehaviorStatus.InEvent);
        DebugUtil.Assert(event1.Behavior.Status == EventStatus.Running);
        DebugUtil.Assert(event2.Behavior.Status == EventStatus.Initializing);
        DebugUtil.Assert(event3.Behavior.Status == EventStatus.Instantiated);
        DebugUtil.Assert(this.obj1.Behavior.PendingEvent == null);
        DebugUtil.Assert(this.obj2.Behavior.PendingEvent == null);
        DebugUtil.Assert(this.agent.Behavior.PendingEvent == null);
        DebugUtil.Assert(this.obj1.Behavior.CurrentEvent == event1.Behavior);
        DebugUtil.Assert(this.obj2.Behavior.CurrentEvent == null);
        DebugUtil.Assert(this.agent.Behavior.CurrentEvent == event1.Behavior);

        event3.StartEvent(0.3f);
        Readout("event3.StartEvent() Results", new IHasBehaviorEvent[] { event1, event2, event3 }, this.obj1, this.obj2, this.agent);
        DebugUtil.Assert(this.obj1.Behavior.Status == BehaviorStatus.InEvent);
        DebugUtil.Assert(this.obj2.Behavior.Status == BehaviorStatus.Idle);
        DebugUtil.Assert(this.agent.Behavior.Status == BehaviorStatus.InEvent);
        DebugUtil.Assert(event1.Behavior.Status == EventStatus.Running);
        DebugUtil.Assert(event2.Behavior.Status == EventStatus.Initializing);
        DebugUtil.Assert(event3.Behavior.Status == EventStatus.Initializing);
        DebugUtil.Assert(this.obj1.Behavior.PendingEvent == null);
        DebugUtil.Assert(this.obj2.Behavior.PendingEvent == null);
        DebugUtil.Assert(this.agent.Behavior.PendingEvent == null);
        DebugUtil.Assert(this.obj1.Behavior.CurrentEvent == event1.Behavior);
        DebugUtil.Assert(this.obj2.Behavior.CurrentEvent == null);
        DebugUtil.Assert(this.agent.Behavior.CurrentEvent == event1.Behavior);

        this.Tick(1, new IHasBehaviorEvent[] { event1, event2, event3 }, this.obj1, this.obj2, this.agent);
        DebugUtil.Assert(this.obj1.Behavior.Status == BehaviorStatus.InEvent);
        DebugUtil.Assert(this.obj2.Behavior.Status == BehaviorStatus.Idle);
        DebugUtil.Assert(this.agent.Behavior.Status == BehaviorStatus.InEvent);
        DebugUtil.Assert(event1.Behavior.Status == EventStatus.Running);
        DebugUtil.Assert(event2.Behavior.Status == EventStatus.Terminating);
        DebugUtil.Assert(event3.Behavior.Status == EventStatus.Pending);
        DebugUtil.Assert(this.obj1.Behavior.PendingEvent == event3.Behavior);
        DebugUtil.Assert(this.obj2.Behavior.PendingEvent == event3.Behavior);
        DebugUtil.Assert(this.agent.Behavior.PendingEvent == null);
        DebugUtil.Assert(this.obj1.Behavior.CurrentEvent == event1.Behavior);
        DebugUtil.Assert(this.obj2.Behavior.CurrentEvent == null);
        DebugUtil.Assert(this.agent.Behavior.CurrentEvent == event1.Behavior);

        // Tick 10
        this.Tick(1, new IHasBehaviorEvent[] { event1, event2, event3 }, this.obj1, this.obj2, this.agent);
        DebugUtil.Assert(this.obj1.Behavior.Status == BehaviorStatus.InEvent);
        DebugUtil.Assert(this.obj2.Behavior.Status == BehaviorStatus.Idle);
        DebugUtil.Assert(this.agent.Behavior.Status == BehaviorStatus.InEvent);
        DebugUtil.Assert(event1.Behavior.Status == EventStatus.Terminating);
        DebugUtil.Assert(event2.Behavior.Status == EventStatus.Detaching);
        DebugUtil.Assert(event3.Behavior.Status == EventStatus.Pending);
        DebugUtil.Assert(this.obj1.Behavior.PendingEvent == event3.Behavior);
        DebugUtil.Assert(this.obj2.Behavior.PendingEvent == event3.Behavior);
        DebugUtil.Assert(this.agent.Behavior.PendingEvent == null);
        DebugUtil.Assert(this.obj1.Behavior.CurrentEvent == event1.Behavior);
        DebugUtil.Assert(this.obj2.Behavior.CurrentEvent == null);
        DebugUtil.Assert(this.agent.Behavior.CurrentEvent == event1.Behavior);

        this.Tick(1, new IHasBehaviorEvent[] { event1, event2, event3 }, this.obj1, this.obj2, this.agent);
        DebugUtil.Assert(this.obj1.Behavior.Status == BehaviorStatus.InEvent);
        DebugUtil.Assert(this.obj2.Behavior.Status == BehaviorStatus.Idle);
        DebugUtil.Assert(this.agent.Behavior.Status == BehaviorStatus.InEvent);
        DebugUtil.Assert(event1.Behavior.Status == EventStatus.Terminating);
        DebugUtil.Assert(event2.Behavior.Status == EventStatus.Finished);
        DebugUtil.Assert(event3.Behavior.Status == EventStatus.Pending);
        DebugUtil.Assert(this.obj1.Behavior.PendingEvent == event3.Behavior);
        DebugUtil.Assert(this.obj2.Behavior.PendingEvent == event3.Behavior);
        DebugUtil.Assert(this.agent.Behavior.PendingEvent == null);
        DebugUtil.Assert(this.obj1.Behavior.CurrentEvent == event1.Behavior);
        DebugUtil.Assert(this.obj2.Behavior.CurrentEvent == null);
        DebugUtil.Assert(this.agent.Behavior.CurrentEvent == event1.Behavior);

        this.Tick(1, new IHasBehaviorEvent[] { event1, event2, event3 }, this.obj1, this.obj2, this.agent);
        DebugUtil.Assert(this.obj1.Behavior.Status == BehaviorStatus.InEvent);
        DebugUtil.Assert(this.obj2.Behavior.Status == BehaviorStatus.Idle);
        DebugUtil.Assert(this.agent.Behavior.Status == BehaviorStatus.InEvent);
        DebugUtil.Assert(event1.Behavior.Status == EventStatus.Detaching);
        DebugUtil.Assert(event2.Behavior.Status == EventStatus.Finished);
        DebugUtil.Assert(event3.Behavior.Status == EventStatus.Pending);
        DebugUtil.Assert(this.obj1.Behavior.PendingEvent == event3.Behavior);
        DebugUtil.Assert(this.obj2.Behavior.PendingEvent == event3.Behavior);
        DebugUtil.Assert(this.agent.Behavior.PendingEvent == null);
        DebugUtil.Assert(this.obj1.Behavior.CurrentEvent == event1.Behavior);
        DebugUtil.Assert(this.obj2.Behavior.CurrentEvent == null);
        DebugUtil.Assert(this.agent.Behavior.CurrentEvent == event1.Behavior);

        this.Tick(1, new IHasBehaviorEvent[] { event1, event2, event3 }, this.obj1, this.obj2, this.agent);
        DebugUtil.Assert(this.obj1.Behavior.Status == BehaviorStatus.Idle);
        DebugUtil.Assert(this.obj2.Behavior.Status == BehaviorStatus.Idle);
        DebugUtil.Assert(this.agent.Behavior.Status == BehaviorStatus.Running);
        DebugUtil.Assert(event1.Behavior.Status == EventStatus.Finished);
        DebugUtil.Assert(event2.Behavior.Status == EventStatus.Finished);
        DebugUtil.Assert(event3.Behavior.Status == EventStatus.Pending);
        DebugUtil.Assert(this.obj1.Behavior.PendingEvent == event3.Behavior);
        DebugUtil.Assert(this.obj2.Behavior.PendingEvent == event3.Behavior);
        DebugUtil.Assert(this.agent.Behavior.PendingEvent == null);
        DebugUtil.Assert(this.obj1.Behavior.CurrentEvent == null);
        DebugUtil.Assert(this.obj2.Behavior.CurrentEvent == null);
        DebugUtil.Assert(this.agent.Behavior.CurrentEvent == null);


        this.Tick(1, new IHasBehaviorEvent[] { event1, event2, event3 }, this.obj1, this.obj2, this.agent);
        DebugUtil.Assert(this.obj1.Behavior.Status == BehaviorStatus.InEvent);
        DebugUtil.Assert(this.obj2.Behavior.Status == BehaviorStatus.InEvent);
        DebugUtil.Assert(this.agent.Behavior.Status == BehaviorStatus.Running);
        DebugUtil.Assert(event1.Behavior.Status == EventStatus.Finished);
        DebugUtil.Assert(event2.Behavior.Status == EventStatus.Finished);
        DebugUtil.Assert(event3.Behavior.Status == EventStatus.Running);
        DebugUtil.Assert(this.obj1.Behavior.PendingEvent == null);
        DebugUtil.Assert(this.obj2.Behavior.PendingEvent == null);
        DebugUtil.Assert(this.agent.Behavior.PendingEvent == null);
        DebugUtil.Assert(this.obj1.Behavior.CurrentEvent == event3.Behavior);
        DebugUtil.Assert(this.obj2.Behavior.CurrentEvent == event3.Behavior);
        DebugUtil.Assert(this.agent.Behavior.CurrentEvent == null);

        // Tick 15
        this.Tick(1, new IHasBehaviorEvent[] { event1, event2, event3 }, this.obj1, this.obj2, this.agent);
        DebugUtil.Assert(this.obj1.Behavior.Status == BehaviorStatus.InEvent);
        DebugUtil.Assert(this.obj2.Behavior.Status == BehaviorStatus.InEvent);
        DebugUtil.Assert(this.agent.Behavior.Status == BehaviorStatus.Running);
        DebugUtil.Assert(event1.Behavior.Status == EventStatus.Finished);
        DebugUtil.Assert(event2.Behavior.Status == EventStatus.Finished);
        DebugUtil.Assert(event3.Behavior.Status == EventStatus.Running);
        DebugUtil.Assert(this.obj1.Behavior.PendingEvent == null);
        DebugUtil.Assert(this.obj2.Behavior.PendingEvent == null);
        DebugUtil.Assert(this.agent.Behavior.PendingEvent == null);
        DebugUtil.Assert(this.obj1.Behavior.CurrentEvent == event3.Behavior);
        DebugUtil.Assert(this.obj2.Behavior.CurrentEvent == event3.Behavior);
        DebugUtil.Assert(this.agent.Behavior.CurrentEvent == null);

        this.Tick(6, new IHasBehaviorEvent[] { event1, event2, event3 }, this.obj1, this.obj2, this.agent);
        DebugUtil.Assert(this.obj1.Behavior.Status == BehaviorStatus.InEvent);
        DebugUtil.Assert(this.obj2.Behavior.Status == BehaviorStatus.InEvent);
        DebugUtil.Assert(this.agent.Behavior.Status == BehaviorStatus.Running);
        DebugUtil.Assert(event1.Behavior.Status == EventStatus.Finished);
        DebugUtil.Assert(event2.Behavior.Status == EventStatus.Finished);
        DebugUtil.Assert(event3.Behavior.Status == EventStatus.Running);
        DebugUtil.Assert(this.obj1.Behavior.PendingEvent == null);
        DebugUtil.Assert(this.obj2.Behavior.PendingEvent == null);
        DebugUtil.Assert(this.agent.Behavior.PendingEvent == null);
        DebugUtil.Assert(this.obj1.Behavior.CurrentEvent == event3.Behavior);
        DebugUtil.Assert(this.obj2.Behavior.CurrentEvent == event3.Behavior);
        DebugUtil.Assert(this.agent.Behavior.CurrentEvent == null);

        this.Tick(1, new IHasBehaviorEvent[] { event1, event2, event3 }, this.obj1, this.obj2, this.agent);
        DebugUtil.Assert(this.obj1.Behavior.Status == BehaviorStatus.InEvent);
        DebugUtil.Assert(this.obj2.Behavior.Status == BehaviorStatus.InEvent);
        DebugUtil.Assert(this.agent.Behavior.Status == BehaviorStatus.Running);
        DebugUtil.Assert(event1.Behavior.Status == EventStatus.Finished);
        DebugUtil.Assert(event2.Behavior.Status == EventStatus.Finished);
        DebugUtil.Assert(event3.Behavior.Status == EventStatus.Detaching);
        DebugUtil.Assert(this.obj1.Behavior.PendingEvent == null);
        DebugUtil.Assert(this.obj2.Behavior.PendingEvent == null);
        DebugUtil.Assert(this.agent.Behavior.PendingEvent == null);
        DebugUtil.Assert(this.obj1.Behavior.CurrentEvent == event3.Behavior);
        DebugUtil.Assert(this.obj2.Behavior.CurrentEvent == event3.Behavior);
        DebugUtil.Assert(this.agent.Behavior.CurrentEvent == null);

        this.Tick(1, new IHasBehaviorEvent[] { event1, event2, event3 }, this.obj1, this.obj2, this.agent);
        DebugUtil.Assert(this.obj1.Behavior.Status == BehaviorStatus.Idle);
        DebugUtil.Assert(this.obj2.Behavior.Status == BehaviorStatus.Idle);
        DebugUtil.Assert(this.agent.Behavior.Status == BehaviorStatus.Running);
        DebugUtil.Assert(event1.Behavior.Status == EventStatus.Finished);
        DebugUtil.Assert(event2.Behavior.Status == EventStatus.Finished);
        DebugUtil.Assert(event3.Behavior.Status == EventStatus.Finished);
        DebugUtil.Assert(this.obj1.Behavior.PendingEvent == null);
        DebugUtil.Assert(this.obj2.Behavior.PendingEvent == null);
        DebugUtil.Assert(this.agent.Behavior.PendingEvent == null);
        DebugUtil.Assert(this.obj1.Behavior.CurrentEvent == null);
        DebugUtil.Assert(this.obj2.Behavior.CurrentEvent == null);
        DebugUtil.Assert(this.agent.Behavior.CurrentEvent == null);

        this.Tick(2, new IHasBehaviorEvent[] { event1, event2, event3 }, this.obj1, this.obj2, this.agent);
        DebugUtil.Assert(this.obj1.Behavior.Status == BehaviorStatus.Idle);
        DebugUtil.Assert(this.obj2.Behavior.Status == BehaviorStatus.Idle);
        DebugUtil.Assert(this.agent.Behavior.Status == BehaviorStatus.Running);
        DebugUtil.Assert(event1.Behavior.Status == EventStatus.Finished);
        DebugUtil.Assert(event2.Behavior.Status == EventStatus.Finished);
        DebugUtil.Assert(event3.Behavior.Status == EventStatus.Finished);
        DebugUtil.Assert(this.obj1.Behavior.PendingEvent == null);
        DebugUtil.Assert(this.obj2.Behavior.PendingEvent == null);
        DebugUtil.Assert(this.agent.Behavior.PendingEvent == null);
        DebugUtil.Assert(this.obj1.Behavior.CurrentEvent == null);
        DebugUtil.Assert(this.obj2.Behavior.CurrentEvent == null);
        DebugUtil.Assert(this.agent.Behavior.CurrentEvent == null);

        this.Tick(2, new IHasBehaviorEvent[] { event1, event2, event3 }, this.obj1, this.obj2, this.agent);

        Debug.LogWarning("TestEventUsurp3 Passed!");
    }
Esempio n. 2
0
    void TestSingleEvent()
    {
        // The agent should begin ticking. Then the event should start and pre-empt the agent.
        // Then the event should end and the agent should resume ticking.

        Debug.Log("TestSingleEvent");

        TestSmartEvent event1 = new TestSmartEvent(obj1, agent);
        event1.Name = "Event1";

        Readout("Beginning", new IHasBehaviorEvent[] { event1 }, this.obj1, this.agent);
        DebugUtil.Assert(this.obj1.Behavior.Status == BehaviorStatus.Idle);
        DebugUtil.Assert(this.agent.Behavior.Status == BehaviorStatus.Running || this.agent.Behavior.Status == BehaviorStatus.Idle);
        DebugUtil.Assert(event1.Behavior.Status == EventStatus.Instantiated);

        this.agent.StartBehavior();
        Readout("Agent.StartBehavior() Results", new IHasBehaviorEvent[] { event1 }, this.obj1, this.agent);
        DebugUtil.Assert(this.obj1.Behavior.Status == BehaviorStatus.Idle);
        DebugUtil.Assert(this.agent.Behavior.Status == BehaviorStatus.Running);
        DebugUtil.Assert(event1.Behavior.Status == EventStatus.Instantiated);

        this.Tick(2, new IHasBehaviorEvent[] { event1 }, this.obj1, this.agent);
        DebugUtil.Assert(this.obj1.Behavior.Status == BehaviorStatus.Idle);
        DebugUtil.Assert(this.agent.Behavior.Status == BehaviorStatus.Running);
        DebugUtil.Assert(event1.Behavior.Status == EventStatus.Instantiated);

        event1.StartEvent(0.1f);
        Readout("event1.StartEvent() Results", new IHasBehaviorEvent[] { event1 }, this.obj1, this.agent);
        DebugUtil.Assert(this.obj1.Behavior.Status == BehaviorStatus.Idle);
        DebugUtil.Assert(this.agent.Behavior.Status == BehaviorStatus.Running);
        DebugUtil.Assert(event1.Behavior.Status == EventStatus.Initializing);

        this.Tick(1, new IHasBehaviorEvent[] { event1 }, this.obj1, this.agent);
        DebugUtil.Assert(this.obj1.Behavior.Status == BehaviorStatus.Idle);
        DebugUtil.Assert(this.agent.Behavior.Status == BehaviorStatus.Running);
        DebugUtil.Assert(event1.Behavior.Status == EventStatus.Pending);

        this.Tick(1, new IHasBehaviorEvent[] { event1 }, this.obj1, this.agent);
        DebugUtil.Assert(this.obj1.Behavior.Status == BehaviorStatus.Idle);
        DebugUtil.Assert(this.agent.Behavior.Status == BehaviorStatus.Terminating);
        DebugUtil.Assert(event1.Behavior.Status == EventStatus.Pending);

        this.Tick(1, new IHasBehaviorEvent[] { event1 }, this.obj1, this.agent);
        DebugUtil.Assert(this.obj1.Behavior.Status == BehaviorStatus.Idle);
        DebugUtil.Assert(this.agent.Behavior.Status == BehaviorStatus.Terminating);
        DebugUtil.Assert(event1.Behavior.Status == EventStatus.Pending);

        this.Tick(1, new IHasBehaviorEvent[] { event1 }, this.obj1, this.agent);
        DebugUtil.Assert(this.obj1.Behavior.Status == BehaviorStatus.Idle);
        DebugUtil.Assert(this.agent.Behavior.Status == BehaviorStatus.Idle);
        DebugUtil.Assert(event1.Behavior.Status == EventStatus.Pending);

        this.Tick(1, new IHasBehaviorEvent[] { event1 }, this.obj1, this.agent);
        DebugUtil.Assert(this.obj1.Behavior.Status == BehaviorStatus.InEvent);
        DebugUtil.Assert(this.agent.Behavior.Status == BehaviorStatus.InEvent);
        DebugUtil.Assert(event1.Behavior.Status == EventStatus.Running);

        this.Tick(7, new IHasBehaviorEvent[] { event1 }, this.obj1, this.agent);
        DebugUtil.Assert(this.obj1.Behavior.Status == BehaviorStatus.InEvent);
        DebugUtil.Assert(this.agent.Behavior.Status == BehaviorStatus.InEvent);
        DebugUtil.Assert(event1.Behavior.Status == EventStatus.Running);

        this.Tick(1, new IHasBehaviorEvent[] { event1 }, this.obj1, this.agent);
        DebugUtil.Assert(this.obj1.Behavior.Status == BehaviorStatus.InEvent);
        DebugUtil.Assert(this.agent.Behavior.Status == BehaviorStatus.InEvent);
        DebugUtil.Assert(event1.Behavior.Status == EventStatus.Detaching);

        this.Tick(1, new IHasBehaviorEvent[] { event1 }, this.obj1, this.agent);
        DebugUtil.Assert(this.obj1.Behavior.Status == BehaviorStatus.Idle);
        DebugUtil.Assert(this.agent.Behavior.Status == BehaviorStatus.Running);
        DebugUtil.Assert(event1.Behavior.Status == EventStatus.Finished);

        this.Tick(2, new IHasBehaviorEvent[] { event1 }, this.obj1, this.agent);
        DebugUtil.Assert(this.obj1.Behavior.Status == BehaviorStatus.Idle);
        DebugUtil.Assert(this.agent.Behavior.Status == BehaviorStatus.Running);
        DebugUtil.Assert(event1.Behavior.Status == EventStatus.Finished);

        this.Tick(2, new IHasBehaviorEvent[] { event1 }, this.obj1, this.agent);

        Debug.LogWarning("TestSingleEvent Passed!");
    }