当前位置: 首页>>代码示例>>C#>>正文


C# Processor.Solve方法代码示例

本文整理汇总了C#中Processor.Solve方法的典型用法代码示例。如果您正苦于以下问题:C# Processor.Solve方法的具体用法?C# Processor.Solve怎么用?C# Processor.Solve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Processor的用法示例。


在下文中一共展示了Processor.Solve方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SolveStringTest

        public void SolveStringTest()
        {
            var lexer = new Mock<ILexer>();
            var parser = new Mock<IParser>();
            var simplifier = new Mock<ISimplifier>();

            var strExp = "x := 1";
            var exp = new Define(new Variable("x"), new Number(1));

            var tokens = new List<IToken>
            {
                new FunctionToken(Functions.Define, 2),
                new SymbolToken(Symbols.OpenBracket),
                new VariableToken("x"),
                new SymbolToken(Symbols.Comma),
                new NumberToken(1),
                new SymbolToken(Symbols.CloseBracket)
            };
            lexer.Setup(l => l.Tokenize(strExp)).Returns(() => tokens);
            parser.Setup(p => p.Parse(tokens)).Returns(() => exp);

            simplifier.Setup(s => s.Analyze(It.IsAny<Define>())).Returns<Define>(e => e);

            var processor = new Processor(lexer.Object, parser.Object, simplifier.Object, null);
            var result = processor.Solve<StringResult>(strExp);

            lexer.Verify(l => l.Tokenize(It.IsAny<string>()), Times.Once());
            parser.Verify(p => p.Parse(It.IsAny<IEnumerable<IToken>>()), Times.Once());

            Assert.Equal("The value '1' was assigned to the variable 'x'.", result.Result);
        }
开发者ID:sys27,项目名称:xFunc,代码行数:31,代码来源:ProcessorTest.cs

示例2: SolveExpTest

        public void SolveExpTest()
        {
            var lexer = new Mock<ILexer>();
            var parser = new Mock<IParser>();
            var simplifier = new Mock<ISimplifier>();
            var differentiator = new Mock<IDifferentiator>();

            var strExp = "deriv(x)";
            var exp = new Derivative(new Variable("x"), new Variable("x"));
            var diff = new Number(1);

            var tokens = new List<IToken>
            {
                new FunctionToken(Functions.Derivative, 1),
                new SymbolToken(Symbols.OpenBracket),
                new VariableToken("x"),
                new SymbolToken(Symbols.CloseBracket)
            };
            lexer.Setup(l => l.Tokenize(strExp)).Returns(() => tokens);
            parser.Setup(p => p.Parse(tokens)).Returns(() => exp);

            simplifier.Setup(s => s.Analyze(It.IsAny<Number>())).Returns<Number>(e => e);
            simplifier.Setup(s => s.Analyze(It.IsAny<Derivative>())).Returns<Derivative>(e => e);

            differentiator.Setup(d => d.Analyze(It.IsAny<Derivative>())).Returns(() => diff);
            differentiator.SetupProperty(d => d.Variable);
            differentiator.SetupProperty(d => d.Parameters);

            exp.Differentiator = differentiator.Object;
            exp.Simplifier = simplifier.Object;
            var processor = new Processor(lexer.Object, parser.Object, simplifier.Object, differentiator.Object);
            var result = processor.Solve<ExpressionResult>(strExp);

            lexer.Verify(l => l.Tokenize(It.IsAny<string>()), Times.Once());
            parser.Verify(p => p.Parse(It.IsAny<IEnumerable<IToken>>()), Times.Once());

            Assert.Equal(new Number(1), result.Result);
        }
开发者ID:sys27,项目名称:xFunc,代码行数:38,代码来源:ProcessorTest.cs

示例3: SolveComplexTest

        public void SolveComplexTest()
        {
            var lexer = new Mock<ILexer>();
            var parser = new Mock<IParser>();
            var simplifier = new Mock<ISimplifier>();

            var strExp = "conjugate(2.3 + 1.4i)";
            var complex = new Complex(2.3, 1.4);
            var exp = new Conjugate(new ComplexNumber(complex));

            var tokens = new List<IToken>
            {
                new FunctionToken(Functions.Conjugate, 1),
                new SymbolToken(Symbols.OpenBracket),
                new NumberToken(2.3),
                new OperationToken(Operations.Addition),
                new NumberToken(1.4),
                new OperationToken(Operations.Multiplication),
                new ComplexNumberToken(Complex.ImaginaryOne),
                new SymbolToken(Symbols.CloseBracket)
            };
            lexer.Setup(l => l.Tokenize(strExp)).Returns(() => tokens);
            parser.Setup(p => p.Parse(tokens)).Returns(() => exp);

            simplifier.Setup(s => s.Analyze(It.IsAny<Conjugate>())).Returns<Conjugate>(e => e);

            var processor = new Processor(lexer.Object, parser.Object, simplifier.Object, null);
            var result = processor.Solve<ComplexNumberResult>(strExp);

            lexer.Verify(l => l.Tokenize(It.IsAny<string>()), Times.Once());
            parser.Verify(p => p.Parse(It.IsAny<IEnumerable<IToken>>()), Times.Once());

            Assert.Equal(Complex.Conjugate(complex), result.Result);
        }
开发者ID:sys27,项目名称:xFunc,代码行数:34,代码来源:ProcessorTest.cs

示例4: SolveDoubleTest

        public void SolveDoubleTest()
        {
            var lexer = new Mock<ILexer>();
            var parser = new Mock<IParser>();
            var simplifier = new Mock<ISimplifier>();

            var strExp = "1 + 1.1";
            var exp = new Add(new Number(1), new Number(1.1));

            var tokens = new List<IToken>
            {
                new NumberToken(2),
                new OperationToken(Operations.Addition),
                new NumberToken(1.1)
            };
            lexer.Setup(l => l.Tokenize(strExp)).Returns(() => tokens);
            parser.Setup(p => p.Parse(tokens)).Returns(() => exp);

            simplifier.Setup(s => s.Analyze(It.IsAny<Add>())).Returns<Add>(e => e);

            var processor = new Processor(lexer.Object, parser.Object, simplifier.Object, null);
            var result = processor.Solve<NumberResult>(strExp);

            lexer.Verify(l => l.Tokenize(It.IsAny<string>()), Times.Once());
            parser.Verify(p => p.Parse(It.IsAny<IEnumerable<IToken>>()), Times.Once());

            Assert.Equal(2.1, result.Result);
        }
开发者ID:sys27,项目名称:xFunc,代码行数:28,代码来源:ProcessorTest.cs

示例5: SolveBoolTest

        public void SolveBoolTest()
        {
            var lexer = new Mock<ILexer>();
            var parser = new Mock<IParser>();
            var simplifier = new Mock<ISimplifier>();

            var strExp = "true & false";
            var exp = new And(new Bool(true), new Bool(false));

            var tokens = new List<IToken>
            {
                new BooleanToken(true),
                new OperationToken(Operations.And),
                new BooleanToken(false)
            };
            lexer.Setup(l => l.Tokenize(strExp)).Returns(() => tokens);
            parser.Setup(p => p.Parse(tokens)).Returns(() => exp);

            simplifier.Setup(s => s.Analyze(It.IsAny<And>())).Returns<And>(e => e);

            var processor = new Processor(lexer.Object, parser.Object, simplifier.Object, null);
            var result = processor.Solve<BooleanResult>(strExp);

            lexer.Verify(l => l.Tokenize(It.IsAny<string>()), Times.Once());
            parser.Verify(p => p.Parse(It.IsAny<IEnumerable<IToken>>()), Times.Once());

            Assert.Equal(false, result.Result);
        }
开发者ID:sys27,项目名称:xFunc,代码行数:28,代码来源:ProcessorTest.cs


注:本文中的Processor.Solve方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。