本文整理汇总了C#中CSharpLogic.Var.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# Var.Equals方法的具体用法?C# Var.Equals怎么用?C# Var.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CSharpLogic.Var
的用法示例。
在下文中一共展示了Var.Equals方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestReify
public void TestReify()
{
var x = new Var();
var y = new Var();
var z = new Var();
var dict = new Dictionary<object, object>();
dict.Add(x, 1);
dict.Add(y, 2);
dict.Add(z, new Tuple<object, object>(x, y));
object result = LogicSharp.Reify(x, dict);
Assert.True(result.Equals(1));
Assert.True(LogicSharp.Reify(10, dict).Equals(10));
var t = new Var('t');
result = LogicSharp.Reify(t, dict);
Assert.True(t.Equals(result));
var tuple = new Tuple<object, object>(1, y);
Assert.True(LogicSharp.Reify(tuple, dict)
.Equals(new Tuple<object, object>(1, 2)));
// assert reify((1, (x, (y, 2))), s) == (1, (1, (2, 2)))
var tuple1 = new Tuple<object, object>(y, 2);
var tuple2 = new Tuple<object, object>(x, tuple1);
var tuple3 = new Tuple<object, object>(1, tuple2);
var obj = LogicSharp.Reify(tuple3, dict);
var tuple10 = new Tuple<object, object>(2, 2);
var tuple20 = new Tuple<object, object>(1, tuple10);
var tuple30 = new Tuple<object, object>(1, tuple20);
Assert.True(obj.Equals(tuple30));
// assert reify(z, s) == (1, 2)
Assert.True(LogicSharp.Reify(z, dict).Equals(new Tuple<object, object>(1, 2)));
}
示例2: ContainsVar
public bool ContainsVar(Var variable)
{
var tuple1 = Args as Tuple<object>;
if (tuple1 != null)
{
var term1 = tuple1.Item1 as Term;
if (term1 != null) return term1.ContainsVar(variable);
var variable1 = tuple1.Item1 as Var;
if (variable1 != null) return variable1.Equals(variable);
return false; //constant
}
var lst = Args as List<object>;
if (lst != null)
{
foreach (var obj in lst)
{
var term1 = obj as Term;
if (term1 != null) return term1.ContainsVar(variable);
var variable1 = obj as Var;
if (variable1 != null)
{
bool tempresult = variable1.Equals(variable);
if (tempresult) return true;
}
}
return false;
}
var tuple2 = Args as Tuple<object, object>;
if (tuple2 != null)
{
bool result;
var term1 = tuple2.Item1 as Term;
if (term1 != null)
{
result = term1.ContainsVar(variable);
if (result) return true;
}
var variable1 = tuple2.Item1 as Var;
if (variable1 != null)
{
result = variable1.Equals(variable);
if (result) return true;
}
var term2 = tuple2.Item2 as Term;
if (term2 != null)
{
result = term2.ContainsVar(variable);
if (result) return true;
}
var variable2 = tuple2.Item2 as Var;
if (variable2 != null)
{
result = variable.Equals(variable2);
if (result) return true;
}
return false;
}
throw new Exception("Term.cs: Cannot reach here");
}
示例3: Run
public static object Run(Var variable, EqGoal goal)
{
if (variable.Equals(goal.Lhs)) return goal.Rhs;
if (variable.Equals(goal.Rhs)) return goal.Lhs;
return null;
}
示例4: TestPoint_Unify_Reify_0
public void TestPoint_Unify_Reify_0()
{
var graph = new RelationGraph();
//true positive
var x = new Var('x');
var y = new Var('y');
var point = new Point(x, y);
var ps = new PointSymbol(point);
graph.AddNode(ps);
Assert.True(graph.Nodes.Count == 1);
/*
*
* Current Status:
*
* (x,y)
*
* next input:
*
* x=1
*/
var eqGoal = new EqGoal(x, 1); // x=1
graph.AddNode(eqGoal);
Assert.True(graph.Nodes.Count == 2);
List<ShapeSymbol> shapes = graph.RetrieveShapeSymbols();
Assert.True(shapes.Count == 1);
var pt = shapes[0] as PointSymbol;
Assert.NotNull(pt);
Assert.True(pt.Equals(ps));
Assert.True(pt.CachedGoals.Count == 1);
Assert.True(pt.CachedSymbols.Count == 1);
var gPointSymbol = pt.CachedSymbols.ToList()[0] as PointSymbol;
Assert.NotNull(gPointSymbol);
var gPoint = gPointSymbol.Shape as Point;
Assert.NotNull(gPoint);
Assert.False(gPoint.Concrete);
Assert.True(1.0.Equals(gPoint.XCoordinate));
Assert.True(y.Equals(gPoint.YCoordinate));
/******
* current status:
* (1,y)
*
* next input:
* x = 2
****/
#region Block 2
var eqGoal1 = new EqGoal(x, 2); // x=2
graph.AddNode(eqGoal1);
shapes = graph.RetrieveShapeSymbols();
Assert.True(shapes.Count == 1);
pt = shapes[0] as PointSymbol;
Assert.NotNull(pt);
Assert.True(pt.Equals(ps));
Assert.True(pt.CachedGoals.Count == 2);
Assert.True(pt.CachedSymbols.Count == 2);
Assert.False(point.Concrete);
#endregion
/******
* current status:
* (1,y)
* (2,y)
*
* next input:
* y = 1
****/
#region Block 3
var eqGoal2 = new EqGoal(y, 1); // y = 1
graph.AddNode(eqGoal2);
shapes = graph.RetrieveShapeSymbols();
Assert.True(shapes.Count == 1);
pt = shapes[0] as PointSymbol;
Assert.False(point.Concrete);
Assert.True(ps.CachedGoals.Count == 3);
Assert.True(ps.CachedSymbols.Count == 2);
foreach (var ss in ps.CachedSymbols)
{
Assert.True(ss.Shape.Concrete);
}
var goals = graph.RetrieveGoals();
Assert.True(goals.Count == 3);
#endregion
/******
* current status:
* (1,1)
* (2,1)
*
* next input:
* y = 2
****/
#region Block 4
var eqGoal3 = new EqGoal(y, 2); // y = 2
graph.AddNode(eqGoal3);
//.........这里部分代码省略.........