| 1 | package Test::Attean::TripleStore; | ||
| 2 | |||
| 3 | 1 | ▶ | use v5.14; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use Test::Roo::Role; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 1 | ▶ | use Test::Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 1 | ▶ | use Attean; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 1 | ▶ | use Attean::RDF; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 1 | requires 'create_store'; # create_store( triples => \@triples ) | |
| 11 | 6 | ▶ | sub cleanup_store {} # cleanup_store( $store ) |
|
Subroutine
cleanup_store: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 12 | |||
| 13 | 1 | ▶ | test 'get_triples' => sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 14 | 1 | my $self = shift; | |
| 15 | 1 | my $t1 = triple(iri('http://example.org/s'), iri('http://example.org/p'), iri('http://example.org/o')); | |
| 16 | 1 | my $t2 = triple(iri('http://example.org/x'), iri('http://example.org/y'), iri('http://example.org/z')); | |
| 17 | 1 | my @triples = ($t1, $t2); | |
| 18 | 1 | my $store = $self->create_store(triples => \@triples); | |
| 19 | 1 | ok $store->does('Attean::API::Store'); | |
| 20 | 1 | ok $store->does('Attean::API::TripleStore'); | |
| 21 | 1 | $self->cleanup_store($store); | |
| 22 | 1 | }; | |
| 23 | |||
| 24 | 1 | ▶ | test 'count_triples' => sub { |
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||
| 25 | 1 | my $self = shift; | |
| 26 | 1 | my @triples; | |
| 27 | 1 | foreach (1 .. 20) { | |
| 28 | 20 | push(@triples, triple(iri('http://example.org/s'), iri('http://example.org/p'), literal($_))); | |
| 29 | } | ||
| 30 | 1 | foreach (1,10,20,50) { | |
| 31 | 4 | push(@triples, triple(iri('http://example.org/z'), iri('http://example.org/p'), literal($_))); | |
| 32 | } | ||
| 33 | 1 | foreach (1 .. 20) { | |
| 34 | 20 | push(@triples, triple(iri('http://example.org/s'), iri('http://example.org/q'), blank("b$_"))); | |
| 35 | } | ||
| 36 | 1 | my $store = $self->create_store(triples => \@triples); | |
| 37 | 1 | is($store->count_triples(iri('http://example.org/UNEXPECTED')), 0, 'unexpected IRI'); | |
| 38 | 1 | is($store->count_triples(iri('http://example.org/s')), 40, 'expected subject'); | |
| 39 | 1 | is($store->count_triples(undef, iri('http://example.org/q')), 20, 'expected predicate'); | |
| 40 | 1 | is($store->count_triples(undef, undef, literal('7')), 1, 'expected object'); | |
| 41 | 1 | is($store->count_triples(undef, undef, literal('10')), 2, 'expected object (2)'); | |
| 42 | 1 | is($store->count_triples(iri('http://example.org/z'), undef, literal('10')), 1, 'expected subject/object'); | |
| 43 | 1 | is($store->count_triples(variable('s'), iri('http://example.org/q')), 20, 'expected predicate with variable'); | |
| 44 | 1 | is($store->count_triples(variable('s'), variable('p'), literal('7')), 1, 'expected object with variable'); | |
| 45 | 1 | is($store->count_triples(variable('s'), variable('p'), literal('10')), 2, 'expected object (2) with variable'); | |
| 46 | 1 | is($store->count_triples(iri('http://example.org/z'), variable('o'), literal('10')), 1, 'expected subject/object with variable'); | |
| 47 | 1 | cmp_ok($store->count_triples_estimate(iri('http://example.org/z')), '>=', 0, 'count_triples_estimate'); | |
| 48 | 1 | $self->cleanup_store($store); | |
| 49 | 1 | }; | |
| 50 | |||
| 51 | |||
| 52 | # test 'count_triples_estimate' => sub {}; | ||
| 53 | |||
| 54 | 1 | ▶ | test 'size' => sub { |
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||
| 55 | 1 | my $self = shift; | |
| 56 | 1 | foreach my $size (1, 10, 25, 57) { | |
| 57 | 4 | my @triples; | |
| 58 | 4 | foreach (1 .. $size) { | |
| 59 | 93 | push(@triples, triple(iri('http://example.org/s'), iri('http://example.org/p'), literal($_))); | |
| 60 | } | ||
| 61 | 4 | my $store = $self->create_store(triples => \@triples); | |
| 62 | 4 | is($store->size(), $size); | |
| 63 | 4 | $self->cleanup_store($store); | |
| 64 | } | ||
| 65 | 1 | }; | |
| 66 | |||
| 67 | 1 | 1; | |