Exemplo n.º 1
0
        public void TestBarrier()
        {
            var preconditionA = new BaseSender <bool>();
            var preconditionB = new BaseSender <bool>();
            var preconditionC = new BaseSender <bool>();

            var barrier = new Barrier();

            preconditionA.Add(barrier);
            preconditionB.Add(barrier);
            preconditionC.Add(barrier);

            var result = new LastValue <bool>();

            barrier.Add(result);

            Assert.IsFalse(result.lastValue);

            // let two of the preconditions to trigger - this shouldn't change anything
            preconditionA.Send(true, 1f);
            Assert.IsFalse(result.lastValue);
            preconditionC.Send(true, 1f);
            Assert.IsFalse(result.lastValue);

            // let's make sure that sending false doesn't do anything
            preconditionA.Send(false, 1f);
            preconditionB.Send(false, 1f);
            preconditionC.Send(false, 1f);
            Assert.IsFalse(result.lastValue);

            // now the last one sends true, and the barrier becomes true as well
            preconditionB.Send(true, 1f);
            Assert.IsTrue(result.lastValue);
        }