1
0
Fork 0

added tests

This commit is contained in:
Jan Steemann 2012-04-24 14:56:46 +02:00
parent 19d7a70d65
commit 663afb0fa1
3 changed files with 83 additions and 2 deletions

View File

@ -1235,7 +1235,6 @@ function AHUACATL_MERGE () {
var element = arguments[i];
if (AHUACATL_TYPEWEIGHT(element) !== AHUACATL_TYPEWEIGHT_DOCUMENT) {
print(element);
throw "expecting documents for merge";
}
@ -1251,6 +1250,32 @@ function AHUACATL_MERGE () {
return result;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief create the union (all) of all arguments
////////////////////////////////////////////////////////////////////////////////
function AHUACATL_UNION () {
var result = [ ];
for (var i in arguments) {
var element = arguments[i];
if (AHUACATL_TYPEWEIGHT(element) !== AHUACATL_TYPEWEIGHT_LIST) {
throw "expecting lists for union";
}
for (var k in element) {
if (!element.hasOwnProperty(k)) {
continue;
}
result.push(element[k]);
}
}
return result;
}
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////

View File

@ -1236,7 +1236,6 @@ static string JS_server_ahuacatl =
" var element = arguments[i];\n"
"\n"
" if (AHUACATL_TYPEWEIGHT(element) !== AHUACATL_TYPEWEIGHT_DOCUMENT) {\n"
" print(element);\n"
" throw \"expecting documents for merge\";\n"
" }\n"
"\n"
@ -1253,6 +1252,32 @@ static string JS_server_ahuacatl =
"}\n"
"\n"
"////////////////////////////////////////////////////////////////////////////////\n"
"/// @brief create the union (all) of all arguments\n"
"////////////////////////////////////////////////////////////////////////////////\n"
"\n"
"function AHUACATL_UNION () {\n"
" var result = [ ];\n"
"\n"
" for (var i in arguments) {\n"
" var element = arguments[i];\n"
"\n"
" if (AHUACATL_TYPEWEIGHT(element) !== AHUACATL_TYPEWEIGHT_LIST) {\n"
" throw \"expecting lists for union\";\n"
" }\n"
"\n"
" for (var k in element) {\n"
" if (!element.hasOwnProperty(k)) {\n"
" continue;\n"
" }\n"
"\n"
" result.push(element[k]);\n"
" }\n"
" }\n"
"\n"
" return result; \n"
"}\n"
"\n"
"////////////////////////////////////////////////////////////////////////////////\n"
"/// @}\n"
"////////////////////////////////////////////////////////////////////////////////\n"
"\n"

View File

@ -161,6 +161,37 @@ function ahuacatlFunctionsTestSuite () {
var actual = getQueryResults("FOR u IN [ { \"id\" : 100, \"name\" : \"John\", \"age\" : 15 }, { \"id\" : 101, \"name\" : \"Corey\", \"age\" : 19 } ] return MERGE(u, { \"id\" : 9 }, { \"name\" : \"foo\", \"id\" : 33 })", false);
assertEqual(expected, actual);
},
////////////////////////////////////////////////////////////////////////////////
/// @brief test union function
////////////////////////////////////////////////////////////////////////////////
testUnion1 : function () {
var expected = [ [ 1, 2, 3, 1, 2, 3 ], [ 1, 2, 3, 1, 2, 3 ] ];
var actual = getQueryResults("FOR u IN [ 1, 2 ] return UNION([ 1, 2, 3 ], [ 1, 2, 3 ])", true);
assertEqual(expected, actual);
},
////////////////////////////////////////////////////////////////////////////////
/// @brief test union function
////////////////////////////////////////////////////////////////////////////////
testUnion2 : function () {
var expected = [ [ 1, 2, 3, 3, 2, 1 ], [ 1, 2, 3, 3, 2, 1 ] ];
var actual = getQueryResults("FOR u IN [ 1, 2 ] return UNION([ 1, 2, 3 ], [ 3, 2, 1 ])", true);
assertEqual(expected, actual);
},
////////////////////////////////////////////////////////////////////////////////
/// @brief test union function
////////////////////////////////////////////////////////////////////////////////
testUnion3 : function () {
var expected = [ "Fred", "John", "John", "Amy" ];
var actual = getQueryResults("FOR u IN UNION([ \"Fred\", \"John\" ], [ \"John\", \"Amy\"]) return u", true);
assertEqual(expected, actual);
},
};
}