CategoryPartitionAddNodeSingleGraph1.java
package org.graphstream.graph.implementations;
import static org.junit.Assert.*;
import java.util.Random;
import org.databene.benerator.anno.Source;
import org.databene.feed4junit.Feeder;
import org.graphstream.graph.ElementNotFoundException;
import org.graphstream.graph.IdAlreadyInUseException;
import org.graphstream.graph.Node;
import org.graphstream.graph.implementations.SingleGraph;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
@RunWith(Feeder.class)
public class CategoryPartitionAddNodeSingleGraph1 {
@Rule
public ExpectedException exception = ExpectedException.none();
@Test
@Source("csvFiles/addNodeInput.csv")
public void mainTest(String graphDeg,String strictChecking,String nodeStr, String nodeExist){
Random random = new Random();
int r = random.nextInt(100) + 129;
SingleGraph graph = createGraph(r, strictChecking);
String id = null;
if(nodeStr.equals("empty")){
id = "";
} else if(nodeStr.equals("random")){
char[] chars = "abcdefghijklmnopqrstuvwxyz1234567890".toCharArray();
StringBuilder sb = new StringBuilder();
int max = random.nextInt(10);
for (int i = 0; i < max; i++) {
char c = chars[random.nextInt(chars.length)];
sb.append(c);
}
id = sb.toString();
}
if(strictChecking.equals("no")){
if(nodeExist.equals("yes")){
Node n1 = graph.addNode(id);
System.out.println(n1 +" "+ strictChecking);
Node n2 = graph.addNode(id);
assertEquals(n1, n2);
assertEquals(r+1, graph.getNodeCount());
} else{
Node n1 = graph.addNode(id);
assertEquals(r+1, graph.getNodeCount());
}
} else{
if(nodeExist.equals("yes")){
exception.expect(IdAlreadyInUseException.class);
Node n1 = graph.addNode(id);
Node n2 = graph.addNode(id);
assertEquals(r+1, graph.getNodeCount());
} else{
Node n1 = graph.addNode(id);
assertEquals(r+1, graph.getNodeCount());
}
}
}
public SingleGraph createGraph(int n, String strictChecking){
boolean strtCheck = false;
if(strictChecking.equals("yes")){
strtCheck = true;
}
SingleGraph graph = new SingleGraph("graph", strtCheck, true);
for(int i =0; i<n; i++){
graph.addNode("node"+i);
}
return graph;
}
}