1
0
Fork 0

fixed unit tests

This commit is contained in:
Frank Celler 2012-04-21 18:39:36 +02:00
parent b068e6b6c9
commit ae18204d1c
3 changed files with 82 additions and 25 deletions

View File

@ -63,6 +63,7 @@
/// <li>@ref JSModuleGraphGraphGetVertices "Graph.getVertices"</li>
/// <li>@ref JSModuleGraphGraphRemoveEdge "Graph.removeEdge"</li>
/// <li>@ref JSModuleGraphGraphRemoveVertex "Graph.removeVertex"</li>
/// <li>@ref JSModuleGraphGraphDrop "Graph.drop"</li>
/// </ol>
/// </li>
/// <li>@ref JSModuleGraphVertex
@ -140,6 +141,10 @@
///
/// @anchor JSModuleGraphGraphRemoveEdge
/// @copydetails JSF_Graph_prototype_removeEdge
/// <hr>
///
/// @anchor JSModuleGraphGraphDrop
/// @copydetails JSF_Graph_prototype_drop
///
/// @section JSModuleGraphVertex Vertex Methods
///////////////////////////////////////////////

View File

@ -307,6 +307,7 @@ Edge.prototype.properties = function () {
////////////////////////////////////////////////////////////////////////////////
Edge.prototype._PRINT = function (seen, path, names) {
// Ignores the standard arguments
seen = path = names = null;
@ -785,11 +786,10 @@ function Graph (name, vertices, edges) {
var col;
var props;
gdb = internal.db._collection(name);
gdb = internal.db._collection("_graph");
if (gdb === null) {
gdb = internal.db._create(name,
{ waitForSync : true, isSystem : true });
gdb = internal.db._create("_graph", { waitForSync : true, isSystem : true });
// gdb.ensureUniqueConstraint("name");
}
@ -797,12 +797,21 @@ function Graph (name, vertices, edges) {
if (vertices === undefined && edges == undefined) {
props = gdb.firstExample('name', name);
if (props == null) {
if (props === null) {
throw "no graph named '" + name + "' found";
}
vertices = internal.db._collection(props.vertices);
if (vertices == null) {
throw "vertex collection '" + props.vertices + "' has vanished";
}
edges = internal.edges._collection(props.edges);
if (edges == null) {
throw "edge collection '" + props.edges + "' has vanished";
}
}
else {
@ -814,6 +823,10 @@ function Graph (name, vertices, edges) {
col = internal.db._create(vertices);
}
if (col == null) {
throw "vertex collection '" + vertices + "' has vanished";
}
// col.ensureUniqueConstraint("$id");
vertices = col;
@ -824,7 +837,11 @@ function Graph (name, vertices, edges) {
col = internal.edges._collection(edges);
if (col === null) {
col = internal.db._create(edges);
col = internal.edges._create(edges);
}
if (col == null) {
throw "edge collection '" + edges + "' has vanished";
}
// col.ensureUniqueConstraint("$id");
@ -869,11 +886,11 @@ function Graph (name, vertices, edges) {
}
}
if (!vertices instanceof AvocadoCollection) {
if (! (vertices instanceof AvocadoCollection)) {
throw "<vertices> must be a document collection";
}
if (!edges instanceof AvocadoEdgesCollection) {
if (! (edges instanceof AvocadoEdgesCollection)) {
throw "<edges> must be an edges collection";
}
@ -901,6 +918,25 @@ function Graph (name, vertices, edges) {
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief drops the graph, the vertices, and the edges
///
/// @FUN{@FA{graph}.drop()}
///
/// Drops the graph, the vertices, and the edges. Handle with care.
////////////////////////////////////////////////////////////////////////////////
Graph.prototype.drop = function () {
var gdb;
gdb = internal.db._collection("_graph");
gdb.remove(this._properties);
this._vertices.drop();
this._edges.drop();
}
////////////////////////////////////////////////////////////////////////////////
/// @brief adds an edge to the graph
///
@ -1008,7 +1044,7 @@ Graph.prototype.addVertex = function (id, data) {
///
/// @FUN{@FA{graph}.getVertex(@FA{id})}
///
/// Returns the vertex identified by @FA{id} or undefined.
/// Returns the vertex identified by @FA{id} or @LIT{null}.
///
/// @EXAMPLES
///
@ -1019,13 +1055,13 @@ Graph.prototype.getVertex = function (id) {
var ref,
vertex;
ref = this._vertices.select({ $id : id });
ref = this._vertices.firstExample('$id', id);
if (ref.count() === 1) {
vertex = this.constructVertex(ref.next()._id);
if (ref !== null) {
vertex = this.constructVertex(ref._id);
}
else {
vertex = undefined;
vertex = null;
}
return vertex;
@ -1271,6 +1307,5 @@ exports.Vertex = Vertex;
// Local Variables:
// mode: outline-minor
// outline-regexp:
// "^\\(/// @brief\\|/// @addtogroup\\|// --SECTION--\\|/// @page\\|/// @}\\)"
// outline-regexp: "^\\(/// @brief\\|/// @addtogroup\\|// --SECTION--\\|/// @page\\|/// @}\\)"
// End:

View File

@ -44,11 +44,11 @@
function graphBasicsSuite() {
//var ERRORS = require("internal").errors;
var Graph = require("graph").Graph,
graph_name = "UnitTestsCollectionGraph",
vertex = "UnitTestsCollectionVertex",
edge = "UnitTestsCollectionEdge",
graph = null;
var Graph = require("graph").Graph;
var graph_name = "UnitTestsCollectionGraph";
var vertex = "UnitTestsCollectionVertex";
var edge = "UnitTestsCollectionEdge";
var graph = null;
return {
@ -57,10 +57,21 @@
////////////////////////////////////////////////////////////////////////////////
setUp : function () {
db._drop(vertex);
db._drop(edge);
try {
try {
graph = new Graph(graph_name);
print("FOUND: ");
PRINT_OBJECT(graph);
graph.drop();
}
catch (err) {
}
graph = new Graph(graph_name, vertex, edge);
graph = new Graph(graph_name, vertex, edge);
}
catch (err) {
console.error("[FAILED] setup failed:" + err);
}
},
////////////////////////////////////////////////////////////////////////////////
@ -68,8 +79,14 @@
////////////////////////////////////////////////////////////////////////////////
tearDown : function () {
db._drop(vertex);
db._drop(edge);
try {
if (graph != null) {
graph.drop();
}
}
catch (err) {
console.error("[FAILED] tear-down failed:" + err);
}
},
////////////////////////////////////////////////////////////////////////////////
@ -132,4 +149,4 @@
jsunity.run(graphBasicsSuite);
jsunity.done();
}());
}());