Beispiel #1
0
        public void MaybeNothing()
        {
            var exprFactory = new MaybeExpressionFactory(MaybeMonad.Instance);
            var parser      = new ExpressionParser <Maybe <object> >(exprFactory);
            var expr        = parser.Parse("A + 0.5 + 0.5").Expression;
            var result      = expr.Evaluate(new { });

            Assert.That(result.HasValue, Is.False);
        }
Beispiel #2
0
        public void DivideByZero()
        {
            var exprFactory = new MaybeExpressionFactory(MaybeMonad.Instance);
            var parser      = new ExpressionParser <Maybe <object> >(exprFactory);
            var expr        = parser.Parse("1/0").Expression;
            var result      = expr.Evaluate(new { });

            Assert.That(result, Is.EqualTo(Maybe <object> .None));
        }
Beispiel #3
0
        public void MaybeSome()
        {
            var exprFactory = new MaybeExpressionFactory(MaybeMonad.Instance);
            var parser      = new ExpressionParser <Maybe <object> >(exprFactory);
            var expr        = parser.Parse("A + 0.5 + 0.5").Expression;
            var result      = expr.Evaluate(new { A = 0.5d });

            Assert.That(result.HasValue);
            Assert.That((double)result.Value, Is.EqualTo(1.5).Within(0.00000001));
        }