Esempio n. 1
0
        public void ComplexExpression()
        {
            var first       = new Source();
            var second      = new Source();
            var rx          = new DebugReactiveExpression <string>(() => first.Woop ? "foo" : (second.Woop ? "bar" : "zoo"), "rx");
            var counter     = 0;
            var expectation = 1;

            Assert.AreEqual("zoo", rx.Evaluate());
            rx.Subscribe(s => counter++);
            second.Woop = true;
            Assert.AreEqual(++expectation, counter);
            Assert.AreEqual("bar", rx.Evaluate());
            first.Woop = true;
            Assert.AreEqual("foo", rx.Evaluate());
            Assert.AreEqual(++expectation, counter);
            second.Woop = false;
            Assert.AreEqual("foo", rx.Evaluate());
            Assert.AreEqual(expectation, counter);
            second.Woop = true;
            Assert.AreEqual("foo", rx.Evaluate());
            Assert.AreEqual(expectation, counter);
            first.Woop = false;
            Assert.AreEqual("bar", rx.Evaluate());
            Assert.AreEqual(++expectation, counter);
            second.Woop = false;
            Assert.AreEqual("zoo", rx.Evaluate());
            Assert.AreEqual(++expectation, counter);
        }
Esempio n. 2
0
        public void TestIndirectDiamondSituation2()
        {
            var input     = new ReactiveVariable <int>();
            var timesTwo  = new DebugReactiveExpression <int>(() => input.Value * 2, "timesTwo");
            var plusOne   = new DebugReactiveExpression <int>(() => input.Value + 1, "plusOne");
            var sumOfBoth = new DebugReactiveExpression <int>(() => timesTwo.Evaluate() + plusOne.Evaluate(), "sumOfBoth");
            var counter   = 0;

            sumOfBoth.Subscribe(getValue => Const(getValue, () => counter++));
            Assert.AreEqual(1, counter);
            input.Value = 1;
            Assert.AreEqual(2, counter);
            input.Value = 2;
            Assert.AreEqual(3, counter);
        }
Esempio n. 3
0
        public void TestIndirectDiamondSituation()
        {
            var source = new DebugReactiveVariable <bool>(false, "source");

            source.Value = true;
            var mid1    = new DebugReactiveExpression <bool>(() => source.Value, "mid1");
            var mid2    = new DebugReactiveExpression <bool>(() => source.Value, "mid2");
            var sink    = new DebugReactiveExpression <bool>(() => mid1.Evaluate() && mid2.Evaluate(), "sink");
            var counter = 0;

            sink.Subscribe(getSink => Const(getSink, () => counter++));

            Assert.AreEqual(1, counter);
            source.Value = false;
            Assert.AreEqual(2, counter);
        }
Esempio n. 4
0
        public void TestDebugMethodAndProperties()
        {
            var dependency = new WeakDependency(0, null);

            Assert.AreEqual("empty reference", dependency.ToString());

            var variable = new DebugReactiveVariable <bool>(false, "yo");

            Assert.AreEqual("yo", variable.ToString());

            var expression = new DebugReactiveExpression <bool>(() => variable.Value);

            expression.Evaluate();
            Assert.AreEqual("unnamed", expression.ToString());
            Assert.True(variable.Dependents.Any());
            Assert.False(expression.Dependents.Any());


            var cache = new ReactiveCache <bool>(() => false);

            Assert.False(cache.Dependents.Any());
        }
Esempio n. 5
0
        public void NestedMultipleDependence()
        {
            var source1        = new Source();
            var source2        = new Source();
            var mid            = new DebugReactiveExpression <bool>(() => source1.Woop ^ source2.Woop, "mid");
            var top            = new DebugReactiveExpression <bool>(() => mid.Evaluate() & source1.Woop, "top");
            var topCounter     = 0;
            var midCounter     = 0;
            var topExpectation = 1;
            var midExpectation = 1;

            top.Subscribe(getValue => ReactiveManagerTest.Const(getValue, () => topCounter++));
            mid.Subscribe(getValue => ReactiveManagerTest.Const(getValue, () => midCounter++));
            Assert.AreEqual(topExpectation, topCounter);
            Assert.AreEqual(midExpectation, midCounter);
            source1.FlipWoop();
            Assert.AreEqual(++topExpectation, topCounter);
            Assert.AreEqual(++midExpectation, midCounter);

            source2.FlipWoop();
            Assert.AreEqual(++topExpectation, topCounter);
            Assert.AreEqual(++midExpectation, midCounter);
        }