Add example data and tests
Change-Id: Ife7b03d33607ec6c27da39b783e66e28f6496bbc
diff --git a/t/server-test.t b/t/server-test.t
new file mode 100644
index 0000000..128707e
--- /dev/null
+++ b/t/server-test.t
@@ -0,0 +1,43 @@
+use strict;
+use warnings;
+use Test::More tests=>5;
+use Mojo::JSON qw(decode_json encode_json to_json);
+use REST::Client;
+use Data::Dump qw(dump);
+
+my $pid = fork();
+my $res;
+unless ($pid) {
+ unless (fork) {
+ exec "MOJO_CONFIG=../example.conf morbo script/derekovecs-server";
+ die "exec failed!";
+ }
+ exit(0);
+}
+sleep(20);
+
+my $client = REST::Client->new();
+$client->GET('http://localhost:3000/?word=Grund&json=1');
+$res = decode_json($client->responseContent());
+is( $res->{list}->[0]->[1]->{word}, "Reaktion", "primary paradigmatic neighbour of Grund" );
+is( $res->{collocators}->[0]->{word}, "Hitchcock", "primary syntagmatic neighbour of Grund" );
+
+$client->GET('http://localhost:3000/getClassicCollocators?w=Grund');
+#print STDERR dump($res);
+$res = decode_json($client->responseContent());
+is( $res->{collocates}->[0]->{word}, "diesem", "primary collocate of Grund" );
+
+$client->GET('http://localhost:3000/getClassicCollocators?w=Grund');
+$res = decode_json($client->responseContent());
+is( $res->{collocates}->[0]->{word}, "diesem", "primary collocate of Grund (cached)" );
+
+$client->GET('http://localhost:3000/getCollocationAssociation?w=Grund&c=diesem');
+$res = decode_json($client->responseContent());
+is($res->{f1}, 29, "collocation association");
+
+for (my $i=0; $i<4; $i++) {
+ $pid++;
+ print STDERR "killing PID $pid\n";
+ system("kill -9 $pid");
+}
+done_testing;
diff --git a/t/test.t b/t/test.t
new file mode 100644
index 0000000..f45afb3
--- /dev/null
+++ b/t/test.t
@@ -0,0 +1,31 @@
+use strict;
+use warnings;
+use Test::More tests => 3;
+use Mojo::JSON qw(decode_json encode_json to_json);
+
+use_ok('IDS::DeReKoVecs::Read');
+
+IDS::DeReKoVecs::Read::init_net(
+ "example-models/wpd19_10000/wpd19_10000.vecs",
+ "example-models/wpd19_10000/wpd19_10000.net",
+ 0, 1
+);
+my $word = "Grund";
+my $dedupe = 0;
+my $nosp = 0;
+my $res;
+my $cutoff = 50000;
+
+subtest 'predictive neighbours' => sub {
+ $res = get_neighbours( $word, 100, 0, 0, $cutoff, $dedupe, $nosp );
+ is( $res->{paradigmatic}->[1]->{word}, "Reaktion", "primary paradigmatic neighbour of Grund" );
+ is( $res->{syntagmatic}->[0]->{word}, "Hitchcock", "primary syntagmatic neighbour of Grund" );
+};
+
+subtest 'count based collocates' => sub {
+ $res = IDS::DeReKoVecs::Read::getClassicCollocators( getWordNumber($word) );
+ $res = decode_json($res);
+ is( $res->{collocates}->[0]->{word}, "diesem", "primary collocate of Grund" );
+};
+
+done_testing;