-
Notifications
You must be signed in to change notification settings - Fork 7
/
search_test.pl
64 lines (41 loc) · 1.61 KB
/
search_test.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
tests search on prolog in-memory triples / builtin emulation
*/
:- use_module(library(semweb/rdf11)).
:- use_module(library(sparqlprog)).
:- use_module(library(sparqlprog/emulate_builtins)).
:- use_module(library(sparqlprog/search_util)).
:- use_module(library(sparqlprog/ontologies/owl)).
:- begin_tests(search_test,
[setup(load_test_file),
cleanup(rdf_retractall(_,_,_,_))]).
load_test_file :-
% load into a test-specific graph due to cache issue
rdf_load('tests/go_nucleus.ttl',[cache(false), graph(search)]).
test_count(Goal,ExpectedCount) :-
writeln(t=Goal),
findall(Goal,Goal,L),
maplist(writeln,L),
length(L,Len),
assertion(Len == ExpectedCount).
test_once(Goal,Test) :-
findall(Goal,(Goal,Test),L),
assertion(L = [_]).
test(contains) :-
test_count(lsearch(cell,_,_),7),
test_once(lsearch(cell,C,_), C='http://purl.obolibrary.org/obo/GO_0005622').
test(starts_regex) :-
test_count(lsearch('^cell',_,_),3),
test_once(lsearch('^cell',C,_), C='http://purl.obolibrary.org/obo/GO_0005623').
test(regex) :-
RE = 'membrane[\\-|\\s]bounded',
test_count(lsearch(RE,_,_),2),
test_once(lsearch(RE,C,_), C='http://purl.obolibrary.org/obo/GO_0043231').
test(ends) :-
test_count(lsearch('cell$',_,_),1),
test_once(lsearch('cell$',C,_), C='http://purl.obolibrary.org/obo/GO_0005623').
test(wildcard) :-
test_count(lsearch('cell.*component',_,_),1).
test(synonym) :-
test_count(tsearch('protoplast',_),2).
:- end_tests(search_test).