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); }
public void Test_UnReify_1_1() { //a = 1, a*b = -1; //true positive var graph = new RelationGraph(); var a = new Var("a"); var b = new Var("b"); var eqGoal = new EqGoal(a, 1); var lhsTerm = new Term(Expression.Multiply, new List <object>() { a, b }); var equation = new Equation(lhsTerm, -1); graph.AddNode(eqGoal); var en = graph.AddNode(equation) as EquationNode; Assert.NotNull(en); Assert.True(en.Equation.CachedEntities.Count == 1); Assert.True(graph.Nodes.Count == 3); graph.DeleteNode(eqGoal); Assert.True(graph.Nodes.Count == 1); var eqNode = graph.Nodes[0] as EquationNode; Assert.NotNull(eqNode); Assert.True(eqNode.Equation.CachedEntities.Count == 0); }
public void Test_UnReify_1_0() { //a = 1, a*b = -1; //true positive var graph = new RelationGraph(); var a = new Var("a"); var b = new Var("b"); var eqGoal = new EqGoal(a, 1); var lhsTerm = new Term(Expression.Multiply, new List<object>() { a, b }); var equation = new Equation(lhsTerm, -1); graph.AddNode(eqGoal); var en = graph.AddNode(equation) as EquationNode; Assert.NotNull(en); Assert.True(en.Equation.CachedEntities.Count == 1); Assert.True(graph.Nodes.Count == 3); graph.DeleteNode(equation); Assert.True(graph.Nodes.Count == 1); }
public void TestScenario_02_WorkedExample_1() { //add three nodes in sequence //delete d=5 var graph = new RelationGraph(); var pt1 = new Point("A", 2, 4); var pt1Symbol = new PointSymbol(pt1); var v = new Var("v"); var pt2 = new Point("B", 5, v); var pt2Symbol = new PointSymbol(pt2); graph.AddNode(pt1Symbol); graph.AddNode(pt2Symbol); var d = new Var("d"); var eqGoal = new EqGoal(d, 5); graph.AddNode(eqGoal); Assert.True(graph.Nodes.Count == 5); //Form a Cycle Directed Graph Assert.True(graph.FoundCycleInGraph()); var ptNode = graph.RetrieveShapeNode(pt2Symbol); Assert.True(ptNode.InEdges.Count == 2); graph.DeleteNode(eqGoal); Assert.True(graph.Nodes.Count == 2); var pt1Node = graph.RetrieveShapeNode(pt1Symbol); Assert.NotNull(pt1Node); Assert.True(pt1Node.InEdges.Count == 0); Assert.True(pt1Node.OutEdges.Count == 0); var pt2Node = graph.RetrieveShapeNode(pt2Symbol); Assert.NotNull(pt2Node); Assert.True(pt2Node.InEdges.Count == 0); Assert.True(pt2Node.OutEdges.Count == 0); }
public void Test_UnReify_2_0() { // a=2, b=a //true positive var graph = new RelationGraph(); var a = new Var("a"); var b = new Var("b"); var eqGoal = new EqGoal(a, 2); var equation = new Equation(b, a); graph.AddNode(eqGoal); var en = graph.AddNode(equation) as EquationNode; Assert.NotNull(en); Assert.True(en.Equation.CachedEntities.Count == 1); Assert.True(graph.Nodes.Count == 3); graph.DeleteNode(equation); Assert.True(graph.Nodes.Count == 1); }
public void TestScenario_02_WorkedExample_2() { //add three nodes in sequence //delete point A var graph = new RelationGraph(); var pt1 = new Point("A", 2, 4); var pt1Symbol = new PointSymbol(pt1); var v = new Var("v"); var pt2 = new Point("B", 5, v); var pt2Symbol = new PointSymbol(pt2); graph.AddNode(pt1Symbol); graph.AddNode(pt2Symbol); var d = new Var("d"); var eqGoal = new EqGoal(d, 5); graph.AddNode(eqGoal); Assert.True(graph.Nodes.Count == 5); //Form a Cycle Directed Graph Assert.True(graph.FoundCycleInGraph()); var ptNode = graph.RetrieveShapeNode(pt2Symbol); Assert.True(ptNode.InEdges.Count == 2); graph.DeleteNode(pt1Symbol); Assert.True(graph.Nodes.Count == 2); var pt2Node = graph.RetrieveShapeNode(pt2Symbol); Assert.NotNull(pt2Node); Assert.True(pt2Node.InEdges.Count == 0); Assert.True(pt2Node.OutEdges.Count == 0); }
public void Test_UnReify_2_0() { // a=2, b=a //true positive var graph = new RelationGraph(); var a = new Var("a"); var b = new Var("b"); var eqGoal = new EqGoal(a, 2); var equation = new Equation(b, a); graph.AddNode(eqGoal); var en = graph.AddNode(equation) as EquationNode; Assert.NotNull(en); Assert.True(en.Equation.CachedEntities.Count == 1); Assert.True(graph.Nodes.Count == 3); graph.DeleteNode(equation); Assert.True(graph.Nodes.Count == 1); }
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); shapes = graph.RetrieveShapeSymbols(); Assert.True(shapes.Count == 1); ps = shapes[0] as PointSymbol; Assert.NotNull(ps); Assert.False(ps.Shape.Concrete); Assert.True(ps.CachedGoals.Count == 4); Assert.True(ps.CachedSymbols.Count == 4); foreach (var css in ps.CachedSymbols) { Assert.True(css.Shape.Concrete); } #endregion /* * current status: * (1,1), (2,1), (1,2), (2,2) * * next input: * delete y = 2 * */ #region Block 5 graph.DeleteNode(eqGoal3); shapes = graph.RetrieveShapeSymbols(); Assert.True(shapes.Count == 1); pt = shapes[0] as PointSymbol; Assert.NotNull(pt); Assert.False(pt.Shape.Concrete); Assert.True(pt.CachedGoals.Count == 3); Assert.True(pt.CachedSymbols.Count == 2); foreach (var ss in pt.CachedSymbols) { Assert.True(ss.Shape.Concrete); } goals = graph.RetrieveGoals(); Assert.True(goals.Count == 3); #endregion /* * current status: * (1,1), (2,1) * * next input: * delete y = 1 * */ #region Block 6 graph.DeleteNode(eqGoal2); shapes = graph.RetrieveShapeSymbols(); Assert.True(shapes.Count == 1); pt = shapes[0] as PointSymbol; Assert.NotNull(pt); Assert.False(pt.Shape.Concrete); Assert.True(pt.CachedGoals.Count == 3); Assert.True(pt.CachedSymbols.Count == 2); #endregion /* foreach (var shape in pt.CachedSymbols) * { * Assert.False(shape.Shape.Concrete); * } * goals = graph.RetrieveGoals(); * Assert.True(goals.Count == 2); * * * ///////////////////////////////////////////// * * graph.DeleteNode(ps); * shapes = graph.RetrieveShapeSymbols(); * Assert.True(shapes.Count == 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); }
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); shapes = graph.RetrieveShapeSymbols(); Assert.True(shapes.Count == 1); ps = shapes[0] as PointSymbol; Assert.NotNull(ps); Assert.False(ps.Shape.Concrete); Assert.True(ps.CachedGoals.Count == 4); Assert.True(ps.CachedSymbols.Count == 4); foreach (var css in ps.CachedSymbols) { Assert.True(css.Shape.Concrete); } #endregion /* * current status: * (1,1), (2,1), (1,2), (2,2) * * next input: * delete y = 2 * */ #region Block 5 graph.DeleteNode(eqGoal3); shapes = graph.RetrieveShapeSymbols(); Assert.True(shapes.Count == 1); pt = shapes[0] as PointSymbol; Assert.NotNull(pt); Assert.False(pt.Shape.Concrete); Assert.True(pt.CachedGoals.Count == 3); Assert.True(pt.CachedSymbols.Count == 2); foreach (var ss in pt.CachedSymbols) { Assert.True(ss.Shape.Concrete); } goals = graph.RetrieveGoals(); Assert.True(goals.Count == 3); #endregion /* * current status: * (1,1), (2,1) * * next input: * delete y = 1 * */ #region Block 6 graph.DeleteNode(eqGoal2); shapes = graph.RetrieveShapeSymbols(); Assert.True(shapes.Count == 1); pt = shapes[0] as PointSymbol; Assert.NotNull(pt); Assert.False(pt.Shape.Concrete); Assert.True(pt.CachedGoals.Count == 3); Assert.True(pt.CachedSymbols.Count == 2); #endregion /* foreach (var shape in pt.CachedSymbols) { Assert.False(shape.Shape.Concrete); } goals = graph.RetrieveGoals(); Assert.True(goals.Count == 2); ///////////////////////////////////////////// graph.DeleteNode(ps); shapes = graph.RetrieveShapeSymbols(); Assert.True(shapes.Count == 0);*/ }