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


C# CalculationEngine.Test方法代码示例

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


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

示例1: Test

        public void Test()
        {
            CalculationEngine engine = new CalculationEngine();

            // adjust culture
            var cultureInfo = engine.CultureInfo;
            engine.CultureInfo = System.Globalization.CultureInfo.InvariantCulture;

            // test internal operators
            engine.Test("0", 0.0);
            engine.Test("+1", 1.0);
            engine.Test("-1", -1.0);
            engine.Test("1+1", 1 + 1.0);
            engine.Test("1*2*3*4*5*6*7*8*9", 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9.0);
            engine.Test("1/(1+1/(1+1/(1+1/(1+1/(1+1/(1+1/(1+1/(1+1/(1+1/(1+1))))))))))", 1 / (1 + 1 / (1 + 1 / (1 + 1 / (1 + 1 / (1 + 1 / (1 + 1 / (1 + 1 / (1 + 1 / (1 + 1 / (1 + 1.0)))))))))));
            engine.Test("((1+2)*(2+3)/(4+5))^0.123", Math.Pow((1 + 2) * (2 + 3) / (4 + 5.0), 0.123));
            engine.Test("10%", 0.1);
            engine.Test("1e+3", 1000.0);

            // test simple variables
            engine.Variables.Add("one", 1);
            engine.Variables.Add("two", 2);
            engine.Test("one + two", 3);
            engine.Test("(two + two)^2", 16);
            engine.Variables.Clear();

            // test DataContext
            var dc = engine.DataContext;
            var p = TestPerson.CreateTestPerson();
            engine.DataContext = p;
            engine.Test("Name", "Test Person");
            engine.Test("Name.Length * 2", p.Name.Length * 2);
            engine.Test("Children.Count", p.Children.Count);
            engine.Test("Children(2).Name", p.Children[2].Name);
            engine.Test("ChildrenDct(\"Test Child 2\").Name", p.ChildrenDct["Test Child 2"].Name);
            engine.Test("ChildrenDct.Count", p.ChildrenDct.Count);
            engine.DataContext = dc;

            // test functions

            // COMPARE TESTS
            engine.Test("5=5"   , true);
            engine.Test("5==5"  , true);
            engine.Test("6==5"  , false);
            engine.Test("6=5"   , false);
            engine.Test("6<5"   , false);
            engine.Test("6>5"   , true);
            engine.Test("5<=10" , true);
            engine.Test("5>=3"  , true);

            // LOGICAL FUNCTION TESTS

            engine.Test("5<=6.0 && 6>=3"  , true);
            engine.Test("true  && true"   , true);
            engine.Test("true  && false"  , false);
            engine.Test("false && true"   , false);
            engine.Test("false && false"  , false);
            engine.Test("true  || true"   , true);
            engine.Test("true  || false"  , true);
            engine.Test("false || true"   , true);
            engine.Test("false || false"  , false);

            engine.Test("AND(true, true)", true);
            engine.Test("AND(true, false)", false);
            engine.Test("AND(false, true)", false);
            engine.Test("AND(false, false)", false);
            engine.Test("OR(true, true)", true);
            engine.Test("OR(true, false)", true);
            engine.Test("OR(false, true)", true);
            engine.Test("OR(false, false)", false);
            engine.Test("NOT(false)", true);
            engine.Test("NOT(true)", false);
            engine.Test("IF(5 > 4, true, false)", true);
            engine.Test("IF(5 > 14, true, false)", false);
            engine.Test("TRUE()", true);
            engine.Test("FALSE()", false);

            // MATH/TRIG FUNCTION TESTS
            engine.Test("ABS(-12)", 12.0);
            engine.Test("ABS(+12)", 12.0);
            engine.Test("ACOS(.23)", Math.Acos(.23));
            engine.Test("ASIN(.23)", Math.Asin(.23));
            engine.Test("ATAN(.23)", Math.Atan(.23));
            engine.Test("ATAN2(1,2)", Math.Atan2(1, 2));
            engine.Test("CEILING(1.8)", Math.Ceiling(1.8));
            engine.Test("COS(1.23)", Math.Cos(1.23));
            engine.Test("COSH(1.23)", Math.Cosh(1.23));
            engine.Test("EXP(1)", Math.Exp(1));
            engine.Test("FLOOR(1.8)", Math.Floor(1.8));
            engine.Test("INT(1.8)", 1);
            engine.Test("LOG(1.8)", Math.Log(1.8, 10)); // default base is 10
            engine.Test("LOG(1.8, 4)", Math.Log(1.8, 4)); // custom base
            engine.Test("LN(1.8)", Math.Log(1.8)); // real log
            engine.Test("LOG10(1.8)", Math.Log10(1.8)); // same as Log(1.8)
            engine.Test("PI()", Math.PI);
            engine.Test("POWER(2,4)", Math.Pow(2, 4));
            //engine.Test("RAND") <= 1.0);
            //engine.Test("RANDBETWEEN(4,5)") <= 5);
            engine.Test("SIGN(-5)", -1);
            engine.Test("SIGN(+5)", +1);
//.........这里部分代码省略.........
开发者ID:AtwooTM,项目名称:ZCalcEngine,代码行数:101,代码来源:CalculationEngineTests.cs


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