public void RunningAfterHaltAfterRunningDoesNotHaltPreviouslyChildren()
        {
            // four children: flip_flop, success, running, and other
            // the sequence is ticked, halted, and ticked
            // flip_flop will return success on the first tick, running on the second tick
            // normally, after flip_flop returns running, success and running should be halted
            // since the sequence is halted between the first and second tick, they should not be halted
            var flip_flop = new ReturnStatusFromCollectionNode(NodeStatus.SUCCESS, NodeStatus.RUNNING);
            var success   = new ReturnXNode(NodeStatus.SUCCESS);
            var running   = new ReturnXNode(NodeStatus.RUNNING);
            var other     = new ReturnXNode(NodeStatus.SUCCESS);
            var node      = new SequenceNode(new List <INode>
            {
                flip_flop,
                success,
                running,
                other,
            });

            var status = node.Tick();

            Assert.That(status, Is.EqualTo(NodeStatus.RUNNING));
            Assert.That(flip_flop.Ticks, Is.EqualTo(1));
            Assert.That(success.Ticks, Is.EqualTo(1));
            Assert.That(running.Ticks, Is.EqualTo(1));
            Assert.That(other.Ticks, Is.EqualTo(0));
            Assert.That(flip_flop.Halts, Is.EqualTo(0));
            Assert.That(success.Halts, Is.EqualTo(0));
            Assert.That(running.Halts, Is.EqualTo(0));
            Assert.That(other.Halts, Is.EqualTo(0));

            node.Halt();
            Assert.That(flip_flop.Halts, Is.EqualTo(1));
            Assert.That(success.Halts, Is.EqualTo(1));
            Assert.That(running.Halts, Is.EqualTo(1));
            Assert.That(other.Halts, Is.EqualTo(1));

            // prime flip_flop so that it's next tick, the one from sequence, is running
            flip_flop.Tick();

            status = node.Tick();
            Assert.That(status, Is.EqualTo(NodeStatus.RUNNING));
            Assert.That(flip_flop.Ticks, Is.EqualTo(3)); // two from sequence, one from primer
            Assert.That(success.Ticks, Is.EqualTo(1));
            Assert.That(running.Ticks, Is.EqualTo(1));
            Assert.That(flip_flop.Halts, Is.EqualTo(1));
            Assert.That(success.Halts, Is.EqualTo(1));
            Assert.That(running.Halts, Is.EqualTo(1));
            Assert.That(other.Halts, Is.EqualTo(1));
        }
        public void RestartsAfterHalt()
        {
            // sequence should restart from beginning when halted while still running
            var success = new ReturnXNode(NodeStatus.SUCCESS);
            var running = new ReturnXNode(NodeStatus.RUNNING);
            var other   = new ReturnXNode(NodeStatus.SUCCESS);
            var node    = new SequenceNode(new List <INode>
            {
                success,
                running,
                other,
            });

            // starts at the beginning
            var status = node.Tick();

            Assert.That(status, Is.EqualTo(NodeStatus.RUNNING));
            Assert.That(success.Ticks, Is.EqualTo(1));
            Assert.That(running.Ticks, Is.EqualTo(1));
            Assert.That(other.Ticks, Is.EqualTo(0));

            // restarts, up to running child
            node.Tick();
            Assert.That(success.Ticks, Is.EqualTo(2));
            Assert.That(running.Ticks, Is.EqualTo(2));
            Assert.That(other.Ticks, Is.EqualTo(0));

            node.Halt();
            Assert.That(success.Halts, Is.EqualTo(1));
            Assert.That(running.Halts, Is.EqualTo(1));
            Assert.That(other.Halts, Is.EqualTo(1));

            // restarts at the beginning
            node.Tick();
            Assert.That(success.Ticks, Is.EqualTo(3));
            Assert.That(running.Ticks, Is.EqualTo(3));
            Assert.That(other.Ticks, Is.EqualTo(0));
        }