/*
Creates and prints the graph seen in diagrams/simple-graph.png.
*/
void createSimpleGraph() {
	uint64 one = 1;
	uint64 two = 2;
	uint64 three = 3;
	uint64 four = 4;
	uint64 five = 5;

	// From our sample graph we know that 1 has the most children (3) so 
	// maxEdges MUST be at least that number.
	uint64 maxEdges = 3;
	// We also know that there are 5 nodes.
	uint64 initialCapacity = 5;
	RoomyGraph *g = RoomyGraph_make("simple-graph", maxEdges, initialCapacity);

	// Add all the nodes
	RoomyGraph_addNode(g, one);
	RoomyGraph_addNode(g, two);
	RoomyGraph_addNode(g, three);
	RoomyGraph_addNode(g, four);
	RoomyGraph_addNode(g, five);

	// Now, add all the edges
	RoomyGraph_addEdge(g, one, two);
	RoomyGraph_addEdge(g, one, three);
	RoomyGraph_addEdge(g, one, five);
	RoomyGraph_addEdge(g, three, one);
	RoomyGraph_addEdge(g, five, five);
	
	RoomyGraph_sync(g);
	uint64 nodeCount = RoomyGraph_nodeCount(g);
	printf("There are %lli nodes.\n", nodeCount);
	RoomyGraph_print(g);
	
	RoomyGraph_destroy(g);
}
Ejemplo n.º 2
0
int destroyGraph() {
	RoomyGraph *g = RoomyGraph_make("destroy", 1, 1);
	assert(NULL != g);
	RoomyGraph_destroy(g);
	printf("destroyGraph completed successfully.\n");
	return PASSED;
}
Ejemplo n.º 3
0
int addNode() {
	// Create a very simple RG so we can add a single node to it.
	RoomyGraph *g = RoomyGraph_make("addNode", 2, 2);
	uint64 node = 3;
	RoomyGraph_addNode(g, node);
	RoomyGraph_sync(g);
	assert(TRUE == RoomyGraph_containsNode(g, node));
	RoomyGraph_destroy(g);
	printf("addNode completed successfully.\n");
	return PASSED;
}
Ejemplo n.º 4
0
int containsNodeTest() {
	RoomyGraph *g = RoomyGraph_make("containsNodeTest", 2, 2);
	uint64 node = 3;
	RoomyGraph_addNode(g, node);
	RoomyGraph_sync(g);
	uint64 notIn = 4;
	assert(TRUE == RoomyGraph_containsNode(g, node));
	assert(FALSE == RoomyGraph_containsNode(g, notIn));
	RoomyGraph_destroy(g);
	printf("containsNodeTest completed successfully.\n");
	return PASSED;
}
Ejemplo n.º 5
0
// Failing functions should return 1, otherwise 0.
int createGraph() {
  uint64 maxEdges = 10;
  uint64 initialCapacity = 10;
	RoomyGraph *g = RoomyGraph_make("g", maxEdges, initialCapacity);

  assert(NULL != g);
  assert(g->maxEdges == 10);
  assert(NULL != g->graph);

	printf("createGraph completed successfully.\n");
	RoomyGraph_destroy(g);
  return PASSED;
}
Ejemplo n.º 6
0
int ableToAddMoreThanInitialSize() {
	RoomyGraph *g = RoomyGraph_make("increaseCapacity", 2, 2);
	uint64 count = 0;
	while(count < 4) {
		count++;
		RoomyGraph_addNode(g, count);	
	}
	RoomyGraph_sync(g);
	assert(4 == RoomyGraph_nodeCount(g));
	//printf("Contents of RoomyGraph that has been expanded from size 2 to 4...\n");
	//RoomyGraph_print(g);
	RoomyGraph_destroy(g);
	printf("ableToAddMoreThanInitialSize completed successfully.\n");
	return PASSED;
}
Ejemplo n.º 7
0
int addMultipleNodes() {
	RoomyGraph *g = RoomyGraph_make("multiNode", 2, 4);
	uint64 first = 1;
	uint64 second = 2;
	RoomyGraph_addNode(g, first);
	RoomyGraph_addNode(g, second);
	RoomyGraph_sync(g);
	
	assert(TRUE == RoomyGraph_containsNode(g, first));
	assert(TRUE == RoomyGraph_containsNode(g, second));

	RoomyGraph_destroy(g);
	printf("addMultipleNodes completed successfully.\n");
	return PASSED;
}
Ejemplo n.º 8
0
int addEdgeTest() {
	RoomyGraph *g = RoomyGraph_make("addEdgeTest", 2, 2);
	uint64 from = 2;
	uint64 to = 4;
	RoomyGraph_addNode(g, from);
	RoomyGraph_addNode(g, to);
	RoomyGraph_addEdge(g, from, to);
	RoomyGraph_sync(g);

//	RoomyGraph_print(g);

	assert(TRUE == RoomyGraph_containsEdge(g, from, to));
	assert(FALSE == RoomyGraph_containsEdge(g, to, from));

	RoomyGraph_destroy(g);
	printf("addEdgeTest completed successfully.\n");
	return PASSED;
}
Ejemplo n.º 9
0
int addingSameNodeDoesntIncreaseCount() {
	RoomyGraph *g = RoomyGraph_make("multiAdds", 2, 2);
	uint64 node = 653;
	RoomyGraph_addNode(g, node);
	RoomyGraph_sync(g);
	assert(1 == RoomyGraph_nodeCount(g));
	
	RoomyGraph_addNode(g, node);
	RoomyGraph_sync(g);
	assert(1 == RoomyGraph_nodeCount(g));

	uint64 node2 = 1127;
	RoomyGraph_addNode(g, node2);
	RoomyGraph_sync(g);
	assert(2 == RoomyGraph_nodeCount(g));
	
	RoomyGraph_destroy(g);

	printf("addingSameNodeDoesntIncreaseCount completed successfully.\n");
	return PASSED;
}