Example #1
0
        public void Case13()
        {
            var random = new Random();

            foreach (var _ in Enumerable.Range(0, 100))
            {
                int a = random.Next(-100, 100);
                int b = random.Next(-100, 100);
                TestContext.WriteLine($"a={a}, b={b}");

                var sideEffect = new SideEffetHolder();

                Expression <Func <int, bool> > expr1 = x => x % 2 == 0;
                Expression <Func <int, bool> > expr2 = y => y % (sideEffect.Update(3)) == 0;

                var expr4 = (Expression <Func <int, int, bool> >)ExpressionOperators.OrElse(expr1, expr2);

                Assert.AreEqual(a % 2 == 0 || b % 3 == 0, expr4.Compile().Invoke(a, b));
                if (a % 2 != 0)
                {
                    Assert.AreEqual(3, sideEffect.Value);
                }
                else
                {
                    Assert.AreEqual(0, sideEffect.Value);
                }
            }
        }
Example #2
0
        public void Case11()
        {
            var random = new Random();

            foreach (var _ in Enumerable.Range(0, 100))
            {
                int a = random.Next(-100, 100);
                int b = random.Next(-100, 100);
                TestContext.WriteLine($"a={a}, b={b}");

                Expression <Func <int, bool> > expr1 = x => x % 2 == 0;
                Expression <Func <int, bool> > expr2 = y => y % 3 == 0;

                var expr4 = (Expression <Func <int, int, bool> >)ExpressionOperators.OrElse(expr1, expr2);

                Assert.AreEqual(a % 2 == 0 || b % 3 == 0, expr4.Compile().Invoke(a, b));
            }
        }