Below is some code I've just cooked up to compare databank contents
(to be used mainly for testing).
It works, but I can't help feeling there's a better way than the brute
force approach I'm using here.
E.g., for jQuery DOM comparisons I've been able to use jQuery
functions like .is() to avoid having to iterate right down to the
level of individual items. All this makes me feel I'm missing some
appropriate idiom for using rdfquery.
Any comments?
#g
--
{{{
containsTriple = function (databank, triple)
{
var match = false;
databank.triples().each( function(i, t)
{
if (t == triple)
{
match = true;
return false; // break
}
return true; //continue
});
return match;
};
assertSameDatabankContents = function (val, exp, txt)
{
equals(val.size(), exp.size(), txt+": different sizes");
same(val.prefix(), exp.prefix(), txt+": different prefixes");
val.triples().each( function (i, t)
{
ok(containsTriple(exp, t), txt+": unexpected triple:
"+t);
});
exp.triples().each( function (i, t)
{
ok(containsTriple(val, t), txt+": missing triple:
"+t);
});
};
test("testCompareDatabanks", function ()
{
var rdfdatabank1 = jQuery.rdf.databank()
.base("")
.prefix("rdf", "
http://www.w3.org/1999/02/22-rdf-syntax-
ns#")
.prefix("shuffl", "
http://purl.org/NET/Shuffl/vocab#")
.add("<
http://example.com/card#id_1> rdf:type
shuffl:Card")
.add("<
http://example.com/card#id_1> shuffl:id \"id_1\"")
;
var rdfdatabank2 = jQuery.rdf.databank()
.base("")
.prefix("rdf", "
http://www.w3.org/1999/02/22-rdf-syntax-
ns#")
.prefix("shuffl", "
http://purl.org/NET/Shuffl/vocab#")
.add("<
http://example.com/card#id_1> rdf:type
shuffl:Card")
.add("<
http://example.com/card#id_1> shuffl:id \"id_1\"")
;
assertSameDatabankContents(rdfdatabank1, rdfdatabank2,
"Compare Databanks");
});
}}}