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


C# CSharpLogic.Var类代码示例

本文整理汇总了C#中CSharpLogic.Var的典型用法代码示例。如果您正苦于以下问题:C# Var类的具体用法?C# Var怎么用?C# Var使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Var类属于CSharpLogic命名空间,在下文中一共展示了Var类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Test_IsVar_2

        public void Test_IsVar_2()
        {
            //var itself
            object ob2 = new Var('1');
            Assert.True(Var.ContainsVar(ob2));

            //Tuple
            object ob1 = new Tuple<object, object>(new Var('x'), 1);
            object ob0 = new Tuple<object>(1);
            Assert.True(Var.ContainsVar(ob1));
            Assert.False(Var.ContainsVar(ob0));

            //IEnumerable
            object ob3 = new List<object>() {1, 1, 1};
            object ob4 = new List<object>() { new Var('x'), 1 };
            Assert.False(Var.ContainsVar(ob3));
            Assert.True(Var.ContainsVar(ob4));

            //Dictionary
            var ob5 = new Dictionary<object, object>();
            ob5.Add(new Var('y'), 1);
            var ob6 = new Dictionary<object, object>();
            ob6.Add(2,3);
            Assert.True(Var.ContainsVar(ob5));
            Assert.False(Var.ContainsVar(ob6));
        }
开发者ID:buptkang,项目名称:CSharp.Logic,代码行数:26,代码来源:Variable.cs

示例2: Equation_EqGoal_Satisfy

        public void Equation_EqGoal_Satisfy()
        {
            //2=2
            var eq = new Equation(2, 2);
            object obj;
            bool result = eq.IsEqGoal(out obj);
            Assert.False(result);

            //3=4
            eq = new Equation(3, 4);
            result = eq.IsEqGoal(out obj);
            Assert.False(result);

            //3=5-2
            var term = new Term(Expression.Add, new List<object>() { 5, -2 });
            eq = new Equation(3, term);
            result = eq.IsEqGoal(out obj);
            Assert.False(result);

            //x = x
            //TODO
            var variable = new Var('x');
            eq = new Equation(variable, variable);
            /*            result = eq.IsEqGoal(out obj);
                        Assert.True(result);*/

            //x = 2x-x
            //TODO
            term = new Term(Expression.Multiply, new List<object>() { 2, variable });
            var term0 = new Term(Expression.Multiply, new List<object>() { -1, variable });
            var term1 = new Term(Expression.Add, new List<object>() { term, term0 });
            eq = new Equation(variable, term1);
            /*            result = eq.IsEqGoal(out obj);
                        Assert.True(result);*/
        }
开发者ID:buptkang,项目名称:CSharp.Logic,代码行数:35,代码来源:0.Equation.Basic.Test.cs

示例3: Test_print

        public void Test_print()
        {
            var variable = new Var('x');
            var term = new Term(Expression.Multiply, new Tuple<object, object>(1, variable));

            Assert.True(term.ToString().Equals("(1*x)"));
        }
开发者ID:buptkang,项目名称:CSharp.Logic,代码行数:7,代码来源:0.Term.Test.cs

示例4: TestReify_Dict

        public void TestReify_Dict()
        {
            var x = new Var();
            var y = new Var();
            /*           
             *          s = {x: 2, y: 4}
                        e = {1: x, 3: {5: y}}
                        assert reify(e, s) == {1: 2, 3: {5: 4}}
             */
            var dict = new Dictionary<object, object>();
            dict.Add(x, 2);
            dict.Add(y, 4);

            var testDict = new Dictionary<object, object>();
            testDict.Add(1, x);
            var embedDict = new Dictionary<object, object>();
            embedDict.Add(5, y);
            testDict.Add(3, embedDict);

            var mockDict = new Dictionary<object, object>();
            mockDict.Add(1, 2);
            var mockEmbedDict = new Dictionary<object, object>();
            mockEmbedDict.Add(5, 4);
            mockDict.Add(3, mockEmbedDict);

            var obj = LogicSharp.Reify(testDict, dict) as Dictionary<object, object>;
            var test1 = obj[1];

            Assert.True(test1.Equals(mockDict[1]));

            var test2 = obj[3] as Dictionary<object, object>;
            var mocktest2 = mockDict[3] as Dictionary<object, object>;
            Assert.True(test2[5].Equals(mocktest2[5]));

        }
开发者ID:buptkang,项目名称:CSharp.Logic,代码行数:35,代码来源:Reification.cs

示例5: test_reify_object_dynamic

        public void test_reify_object_dynamic()
        {
            //dynamic approach
            /*            obj = reify_object(Foo(1, var(3)), {var(3): 4})
                        assert obj.a == 1
                        assert obj.b == 4

                        f = Foo(1, 2)
                        assert reify_object(f, {}) is f
             */

            dynamic foo = new DyLogicObject();
            foo.a = 1;
            var variable = new Var(3);
            foo.b = variable;

            var dict = new Dictionary<object, object>();
            dict.Add(variable, 4);

            dynamic obj = LogicSharp.Reify_Object(foo, dict);
            Assert.NotNull(obj);
            Assert.True(1.Equals(obj.a));
            Assert.True(4.Equals(obj.b));

            dynamic f = new DyLogicObject();
            f.a = 1;
            f.b = 2;

            dict = new Dictionary<object, object>();
            obj = LogicSharp.Reify_Object(f, dict);
            Assert.True(obj == f);
        }
开发者ID:buptkang,项目名称:CSharp.Logic,代码行数:32,代码来源:DyLogicObject.cs

示例6: TestLine_Unify_Reify_0

        public void TestLine_Unify_Reify_0()
        {
            var graph = new RelationGraph();
            var a = new Var("a");
		    var line = new Line(a, 1, 1.0);
		    var ls = new LineSymbol(line);
		    graph.AddNode(ls);

            List<ShapeSymbol> lines = graph.RetrieveShapeSymbols(ShapeType.Line);
            Assert.True(lines.Count == 1);
            var lineSymbol = lines[0] as LineSymbol;
            Assert.NotNull(lineSymbol);
            Assert.True(lineSymbol.CachedSymbols.Count == 0);

            var eqGoal = new EqGoal(a, 1); // a=1
            graph.AddNode(eqGoal);

            lines = graph.RetrieveShapeSymbols(ShapeType.Line);
            Assert.True(lines.Count == 1);
            var currLine = lines[0] as LineSymbol;
            Assert.NotNull(currLine);
            Assert.True(currLine.CachedSymbols.Count == 1);
            var cachedLineSymbol = currLine.CachedSymbols.ToList()[0] as LineSymbol;
            Assert.NotNull(cachedLineSymbol);
            var cachedLine = cachedLineSymbol.Shape as Line;
            Assert.NotNull(cachedLine);
            Assert.True(cachedLine.A.Equals(1.0));
            Assert.True(cachedLine.B.Equals(1.0));
            Assert.True(cachedLine.C.Equals(1.0));

            graph.DeleteNode(eqGoal);
            lines = graph.RetrieveShapeSymbols(ShapeType.Line);
            Assert.True(lines.Count == 1);
            currLine = lines[0] as LineSymbol;
            Assert.NotNull(currLine);
            Assert.True(currLine.CachedSymbols.Count == 0);
            Assert.True(currLine.CachedGoals.Count == 0);

		    var eqGoal2 = new EqGoal(a, 3);
            graph.AddNode(eqGoal2);

            lines = graph.RetrieveShapeSymbols(ShapeType.Line);
            Assert.True(lines.Count == 1);
            currLine = lines[0] as LineSymbol;
            Assert.NotNull(currLine);
            Assert.True(currLine.CachedSymbols.Count == 1);
		    Assert.True(currLine.CachedGoals.Count == 1);

            graph.DeleteNode(eqGoal2);

            lines = graph.RetrieveShapeSymbols(ShapeType.Line);
            Assert.True(lines.Count == 1);
            currLine = lines[0] as LineSymbol;
            Assert.NotNull(currLine);
            Assert.True(currLine.CachedSymbols.Count == 0);
            Assert.True(currLine.CachedGoals.Count == 0);

          
        }
开发者ID:buptkang,项目名称:Relation.Logic,代码行数:59,代码来源:1.Test.Line.cs

示例7: Test_Clone1

 public void Test_Clone1()
 {
     var variable = new Var('a'); 
     var variable1 = variable.Clone();
     variable1.Token = "b";
     Assert.True(variable.Token.Equals('a'));
     Assert.True(variable.ToString().Equals("a"));
 }
开发者ID:buptkang,项目名称:CSharp.Logic,代码行数:8,代码来源:Variable.cs

示例8: Test_print3

 public void Test_print3()
 {
     var x = new Var('x');
     var term0 = new Term(Expression.Multiply, new List<object>() {3, x});
     var y = new Var('y');
     var term1 = new Term(Expression.Multiply, new List<object>() {-1, y});
     var term = new Term(Expression.Add, new List<object>() {term0, term1});
     Assert.True(term.ToString().Equals("3x-y"));
 }
开发者ID:buptkang,项目名称:CSharp.Logic,代码行数:9,代码来源:0.Term.Test.cs

示例9: Test_Commutative_2_NonLinear

 public void Test_Commutative_2_NonLinear()
 {
     //x^2*3 -> 3*x^2
     var x = new Var('x');
     var x_square = new Term(Expression.Power, new List<object>() { x, 2 });
     var a = new Term(Expression.Multiply, new List<object>() { x_square, 3 });
     object result = a.EvalAlgebra();
     Assert.True(result.ToString().Equals("3(x^2)"));
 }
开发者ID:buptkang,项目名称:CSharp.Logic,代码行数:9,代码来源:2.Algebra.Test.cs

示例10: Test_Commutative_2

 public void Test_Commutative_2()
 {
     //x*3 -> 3*x
     var x = new Var('x');
     var a = new Term(Expression.Multiply, new List<object>() { x, 3 });
     object result = a.EvalAlgebra();
     Assert.NotNull(result);
     Assert.True(result.ToString().Equals("3x"));
     Assert.True(a.Traces.Count == 1);
 }
开发者ID:buptkang,项目名称:CSharp.Logic,代码行数:10,代码来源:2.Algebra.Test.cs

示例11: UnifyTest

        public void UnifyTest()
        {
            var term1 = new Term(Expression.Add, new List<object>() { 1, 1 });
            var x = new Var('x');
            var term2 = new Term(Expression.Add, new List<object>() { 1, x });

            var dict = new Dictionary<object, object>();
            bool result = LogicSharp.Unify(term1, term2, dict);

            Assert.True(result);
            Assert.True(dict.Count == 1);
        }
开发者ID:buptkang,项目名称:CSharp.Logic,代码行数:12,代码来源:0.Term.Test.cs

示例12: Term_Algebra_Arith_4

 public void Term_Algebra_Arith_4()
 {
     // //a^2+ 4^2 - 25; 
     //a^2+25+-1*16
     var a = new Var('a');
     var term1 = new Term(Expression.Power, new List<object>() {a, 2});
     var term2 = new Term(Expression.Power, new List<object>() {4, 2});
     var term3 = new Term(Expression.Multiply, new List<object>() {-1, 25});
     var term = new Term(Expression.Add, new List<object>() {term1, term2, term3});
     object obj = term.Eval();
     Assert.NotNull(obj);
 }
开发者ID:buptkang,项目名称:CSharp.Logic,代码行数:12,代码来源:3.Integrate.Test.cs

示例13: Test_Commutative_1_NonLinear_2

 public void Test_Commutative_1_NonLinear_2()
 {
     // x+x^2 -> x^2+x
     var x = new Var('x');
     var x_square = new Term(Expression.Power, new List<object>() { x, 2 });
     var term = new Term(Expression.Add, new List<object>() { x, x_square });
     object result = term.EvalAlgebra();
     var gTerm = result as Term;
     Assert.NotNull(gTerm);
     Assert.NotNull(result);
     Assert.True(result.ToString().Equals("x^2+x"));
 }
开发者ID:buptkang,项目名称:CSharp.Logic,代码行数:12,代码来源:2.Algebra.Test.cs

示例14: Test_Commutative_1

 public void Test_Commutative_1()
 {
     //3+x -> x+3             
     var x = new Var('x');
     var a = new Term(Expression.Add, new List<object>() { 3, x });
     object result = a.EvalAlgebra();
     var gTerm = result as Term;
     Assert.NotNull(gTerm);
     Assert.NotNull(result);
     Assert.True(result.ToString().Equals("x+3"));
     Assert.True(a.Traces.Count == 1);
 }
开发者ID:buptkang,项目名称:CSharp.Logic,代码行数:12,代码来源:2.Algebra.Test.cs

示例15: Test_Check1

        public void Test_Check1()
        {
            var line = new Line(1, 2, 3);
            Assert.True(line.Concrete);

            Assert.True(line.A.Equals(1.0));
            Assert.True(line.B.Equals(2.0));
            Assert.True(line.C.Equals(3.0));

            var variable = new Var('x');
            var line2 = new Line(2, variable, 3);
            Assert.False(line2.Concrete);
        }
开发者ID:buptkang,项目名称:Relation.Logic,代码行数:13,代码来源:Test.Line.cs


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