Skip to content

Commit

Permalink
Add a simple test
Browse files Browse the repository at this point in the history
  • Loading branch information
kamahen authored and JanWielemaker committed Dec 19, 2023
1 parent 73e8097 commit 056c121
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,15 @@ $(HDTLIB)/libhdt.a $(HDTLIB)/libcds.a: FORCE
FORCE:

check::
$(SWIPL) -g test_hdt -t halt test/test_hdt.pl

install::

clean:
rm -f $(OBJ) $(OBJ2)
[ ! -f $(HDTHOME)/Makefile ] || (cd $(HDTHOME) && git reset --hard)
[ ! -f $(HDTHOME)/Makefile ] || $(MAKE) -C $(HDTHOME) clean

distclean: clean
rm -f $(SOBJ)
[ ! -f $(HDTHOME)/Makefile ] || $(MAKE) -C $(HDTHOME) distclean
2 changes: 1 addition & 1 deletion pack.pl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name(hdt).
version('0.5.2').
version('0.5.3').
% TODO: swipl_version([90121]).
title('Access RDF HDT files').
keywords(['RDF']).
Expand Down
13 changes: 13 additions & 0 deletions test/data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
The files were generated by:

```
./hdt-cpp/libhdt/tools/hdtInfo hdt-cpp/libhdt/data/literals.hdt >literals.hdtInfo-output
echo '? ? ?' | ./libhdt/tools/hdtSearch lib-cpp/libhdt/data/literals.hdt 2>/dev/null >literals.hdtSearch-output
```

To do this, you need to run "make" separately (the "make" that runs from `pack_install(.)` does something different because it has other options to `./configure`):
```sh
cd hdt-cpp && ./autogen.sh && ./configure && make -j8
```

TODO: use hdt2rdf, rdf2hdt
28 changes: 28 additions & 0 deletions test/data/literals.hdtInfo-output
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<file://literals.ttl> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.org/HDT/hdt#Dataset> .
<file://literals.ttl> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://rdfs.org/ns/void#Dataset> .
<file://literals.ttl> <http://rdfs.org/ns/void#triples> "9" .
<file://literals.ttl> <http://rdfs.org/ns/void#properties> "1" .
<file://literals.ttl> <http://rdfs.org/ns/void#distinctSubjects> "1" .
<file://literals.ttl> <http://rdfs.org/ns/void#distinctObjects> "9" .
<file://literals.ttl> <http://purl.org/HDT/hdt#statisticalInformation> _:statistics .
<file://literals.ttl> <http://purl.org/HDT/hdt#publicationInformation> _:publicationInformation .
<file://literals.ttl> <http://purl.org/HDT/hdt#formatInformation> _:format .
_:format <http://purl.org/HDT/hdt#dictionary> _:dictionary .
_:format <http://purl.org/HDT/hdt#triples> _:triples .
_:dictionary <http://purl.org/dc/terms/format> <http://purl.org/HDT/hdt#dictionaryLiteral> .
_:dictionary <http://purl.org/HDT/hdt#dictionarynumSubjects> "1" .
_:dictionary <http://purl.org/HDT/hdt#dictionarynumPredicates> "1" .
_:dictionary <http://purl.org/HDT/hdt#dictionarynumObjects> "9" .
_:dictionary <http://purl.org/HDT/hdt#dictionarynumSharedSubjectObject> "0" .
_:dictionary <http://purl.org/HDT/hdt#dictionarymaxSubjectID> "1" .
_:dictionary <http://purl.org/HDT/hdt#dictionarymaxPredicateID> "1" .
_:dictionary <http://purl.org/HDT/hdt#dictionarymaxObjectID> "9" .
_:dictionary <http://purl.org/HDT/hdt#dictionarymapping> "1" .
_:dictionary <http://purl.org/HDT/hdt#dictionarysizeStrings> "2710" .
_:dictionary <http://purl.org/HDT/hdt#dictionaryblockSize> "8" .
_:triples <http://purl.org/dc/terms/format> <http://purl.org/HDT/hdt#triplesBitmap> .
_:triples <http://purl.org/HDT/hdt#triplesnumTriples> "9" .
_:triples <http://purl.org/HDT/hdt#triplesOrder> "SPO" .
_:statistics <http://purl.org/HDT/hdt#originalSize> "156" .
_:statistics <http://purl.org/HDT/hdt#hdtSize> "2940" .
_:publicationInformation <http://purl.org/dc/terms/issued> "2015-02-13T17:21:30+0100" .
10 changes: 10 additions & 0 deletions test/data/literals.hdtSearch-output
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
s p "a"
s p "a"@en
s p "a"^^<bcd>
s p "abc"
s p "abc"@en
s p "abc"^^<bcd>
s p "bc"
s p "bc"@en
s p "bc"^^<bcd>
9 results in 162 us
41 changes: 41 additions & 0 deletions test/test_hdt.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
% -*- mode: Prolog; coding: utf-8 -*-

/* These tests use the data in ../hdt-cpp/libhdt/data/literals.hdt
See the comments in data/README.md if a test fails - the failure
might be because the data has changed.
*/

:- module(test_hdt,
[ test_hdt/0
]).

:- use_module(library(plunit)).
:- use_module(library(hdt)).

test_hdt :-
run_tests([hdt]).

:- begin_tests(hdt).

test(hdt_search_id) :-
hdt_open_literals(H),
bagof(S:P:O, hdt_search_id(H, S, P, O), SPOs),
assertion(SPOs == [1:1:1,
1:1:2,
1:1:3,
1:1:4,
1:1:5,
1:1:6,
1:1:7,
1:1:8,
1:1:9]),
hdt_close(H).

hdt_open_literals(H) :-
predicate_property(test_hdt, file(TestHdtFile)),
directory_file_path(TestHdtDir, _, TestHdtFile),
atom_concat(TestHdtDir, '/../hdt-cpp/libhdt/data/literals.hdt', LiteralsHdtPath),
hdt_open(H, LiteralsHdtPath).

:- end_tests(hdt).

0 comments on commit 056c121

Please sign in to comment.