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

View File

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

View File

@ -44,11 +44,11 @@
function graphBasicsSuite() { function graphBasicsSuite() {
//var ERRORS = require("internal").errors; //var ERRORS = require("internal").errors;
var Graph = require("graph").Graph, var Graph = require("graph").Graph;
graph_name = "UnitTestsCollectionGraph", var graph_name = "UnitTestsCollectionGraph";
vertex = "UnitTestsCollectionVertex", var vertex = "UnitTestsCollectionVertex";
edge = "UnitTestsCollectionEdge", var edge = "UnitTestsCollectionEdge";
graph = null; var graph = null;
return { return {
@ -57,10 +57,21 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
setUp : function () { setUp : function () {
db._drop(vertex); try {
db._drop(edge); 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 () { tearDown : function () {
db._drop(vertex); try {
db._drop(edge); if (graph != null) {
graph.drop();
}
}
catch (err) {
console.error("[FAILED] tear-down failed:" + err);
}
}, },
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////