Пример #1
0
        public void ObservableValue_Events(int expected_changes, int initial_value, params int[] seq)
        {
            int chg_event = 0;

            ObservableValue <int> val = new ObservableValue <int>(initial_value);

            val.ValueChanged += (v1, v0) => chg_event++;

            foreach (int s in seq)
            {
                val.Value = s;
            }

            Assert.That(chg_event, Is.EqualTo(expected_changes));
        }
Пример #2
0
        public void Triggers_FuncCondition_TriggerCount(Func <int, bool> func, int count_until_exclusive, int expected_result)
        {
            ObservableValue <int> x    = new ObservableValue <int>(-1);
            ICondition            cond = new FuncCondition <int>(ref x, func);

            int     triggercount = 0;
            Action  action       = () => { triggercount++; Console.Write(" " + x.Value); };
            Trigger trigger      = new Trigger(cond, action);

            Console.Write("Trigger at: ");
            for (int i = 0; i < count_until_exclusive; i++)
            {
                x.Value = i;
            }

            Assert.That(triggercount, Is.EqualTo(expected_result));
        }
Пример #3
0
        public void Triggers_FuncCondition_TriggerCount_Or(Func <int, bool> func1, Func <int, bool> func2, int count_until_exclusive, int expected_result)
        {
            ObservableValue <int> x     = new ObservableValue <int>(-1);
            ICondition            cond1 = new FuncCondition <int>(ref x, func1);
            ICondition            cond2 = new FuncCondition <int>(ref x, func2);

            int     triggercount = 0;
            Action  action       = () => { triggercount++; Console.Write(" " + x.Value); };
            Trigger trigger      = new Trigger(cond1.Or(cond2), action);

            Console.Write("Trigger at: ");
            for (int i = 0; i < count_until_exclusive; i++)
            {
                x.Value = i;
            }

            Assert.That(triggercount, Is.EqualTo(expected_result * 2)); // because there are two observable links, 2 events is expected per change.
        }
Пример #4
0
        public void Triggers_ValueCondition_TriggerCount_And(MatchType matchType1, int cmp1, MatchType matchType2, int cmp2, int count_until_exclusive, int expected_result)
        {
            ObservableValue <int> x     = new ObservableValue <int>(-1);
            ICondition            cond1 = new ValueCondition <int>(ref x, matchType1, cmp1);
            ICondition            cond2 = new ValueCondition <int>(ref x, matchType2, cmp2);
            int triggercount            = 0;

            Action  action  = () => { triggercount++; Console.Write(" " + x.Value); };
            Trigger trigger = new Trigger(cond1.And(cond2), action);

            Console.Write("Trigger at: ");
            for (int i = 0; i < count_until_exclusive; i++)
            {
                x.Value = i;
            }

            Assert.That(triggercount, Is.EqualTo(expected_result * 2)); // because there are two observable links, 2 events is expected per change.
        }