CategoryPartitionAddEdgeSingleGraphIt1.java
package org.graphstream.graph.implementations;
import static org.junit.Assert.assertEquals;
import org.databene.benerator.anno.Source;
import org.databene.feed4junit.Feeder;
import org.graphstream.graph.Edge;
import org.graphstream.graph.IdAlreadyInUseException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
@RunWith(Feeder.class)
public class CategoryPartitionAddEdgeSingleGraphIt1 {
//idExistance, idValue, graphNrNodes, graphStrictChecking, graphNrEdges,
//graphAutoCreate, sourceExistance, sourceEqTarget, sourceDegree
//sourceConnectedTarget, targetExistance
@Rule
public ExpectedException exception = ExpectedException.none();
@Test
@Source("csvFiles/CategoryPartitionAddEdgeSingleGraph.csv")
public void testAddEdge(Boolean idExistance, String idValue, String graphNrNodes,
Boolean graphStrictChecking, String graphNrEdges, Boolean graphAutoCreate,
Boolean sourceEx, Boolean sourceEqTarget, String sourceDegree, Boolean sourceConnectedTarget,
Boolean targetExistence) {
if (idExistance && idValue.equals("correct") && graphNrNodes.equals("many") && graphStrictChecking &&
graphNrEdges.equals("many") && graphAutoCreate && sourceEx && sourceEqTarget
&& sourceDegree.equals("N") && !sourceConnectedTarget && targetExistence) {
test1();
} else if (!idExistance && idValue.equals("correct") && graphNrNodes.equals("many") && !graphStrictChecking &&
graphNrEdges.equals("many") && !graphAutoCreate && sourceEx && !sourceEqTarget
&& sourceDegree.equals("N-1") && !sourceConnectedTarget && !targetExistence) {
test2();
}
// /*
// * Add an edge where the source node is already exist
// */
// if (sourceEx) {
// int edges = singleGraph.getEdgeCount();
// singleGraph.addEdge(id, "Node_1", "Node_"+(nrNodes-1));
// assertEquals("Node_1", singleGraph.getEdge(id).getSourceNode().getId());
// assertEquals(edges + 1, singleGraph.getEdgeCount());
// } else {
//// if (graphStrictChecking)
//// exception.expect(IdAlreadyInUseException.class);
// singleGraph.addEdge(id, "Node_Random", "Node_"+(nrNodes-1));
// }
// singleGraph.removeEdge(id); // removing the edge added to the graph
/*
* Add an edge where the target node is already exist
*/
// if (targetExistence) {
// int edges = singleGraph.getEdgeCount();
// singleGraph.addEdge(id, "Node_"+(nrNodes-1), "Node_1");
// assertEquals("Node_1", singleGraph.getEdge(id).getTargetNode().getId());
// assertEquals(edges + 1, singleGraph.getEdgeCount());
// }
}
private void test3() {
SingleGraph s = new SingleGraph("sings");
MultiNode m1 = new MultiNode(s, "m1");
MultiNode m2 = new MultiNode(s, "m2");
s.addEdge("asda", m1, m2);
s.addEdge("asda1", m1, m2);
System.out.println(s.getEdge("asda"));
s.addNode("s");
}
//true,correct,many,true,many,true,true,true,N,false,true
private void test1() {
SingleGraph singleGraph = new SingleGraph("singleGraph1", true, true);
for (int i = 0; i < 100; i++) {
singleGraph.addNode("Node_" + i);
}
// creaning n-1 edges
for (int i = 2; i < 90; i++) {
singleGraph.addEdge("Edge_"+i, "Node_"+i, "Node_"+(i+1));
}
//sourceDegree N
for (int i = 0; i < 100; i++) {
singleGraph.addEdge("EdgeDegree_"+i, "Node_1", "Node_"+i);
}
exception.expect(IdAlreadyInUseException.class);
singleGraph.addEdge("EdgeDegree_1", "Node_1", "Node_1");
}
//false,correct,many,false,many,false,true,false,N-1,false,false
private void test2() {
SingleGraph singleGraph = new SingleGraph("singleGraph2", false, false);
String id = "myID";
for (int i = 0; i < 100; i++) {
singleGraph.addNode("Node_" + i);
}
for (int i = 2; i < 90; i++) {
singleGraph.addEdge("Edge_"+i, "Node_"+i, "Node_"+(i+1));
}
//sourceDegree N-1
for (int i = 0; i < 99; i++) {
singleGraph.addEdge("EdgeDegree_"+i, "Node_1", "Node_"+(i+1));
}
Edge ed = singleGraph.addEdge(id, "Node_1", "NodeTarget");
assertEquals(100, singleGraph.getNodeCount());
// assertEquals("Node_1", singleGraph.getEdge(id).getSourceNode().getId());
//assertEquals("NodeTarget", singleGraph.getEdge(id).getTargetNode());
}
// /*
// * create an edge with given id to control the id value existence
// * if strict checking is true it will raise IdAlreadynUseException
// * otherwise it will remove the existence edge and add new edge
// * changing the target and source node
// */
// private void test1(SingleGraph singleGraph, String id, int nrNodes) {
// if (id == null) {
// exception.expect(AssertionError.class);
// } else {
// exception.expect(IdAlreadyInUseException.class);
// }
//
// singleGraph.addEdge(id, "Node_1", "Node_"+(nrNodes-1));
// singleGraph.addEdge(id, "Node_2", "Node_"+(nrNodes-2));
//
//
// }
}