File Coverage

blib/lib/Test/Attean/QuadStore.pm
Criterion Covered Total %
statement 17 17 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 23 23 100.0


line stmt bran cond sub pod time code
1              
2             use v5.14;
3 2     2   1259 use warnings;
  2         8  
4 2     2   12 use Test::Roo::Role;
  2         3  
  2         55  
5 2     2   836 use Test::Moose;
  2         962  
  2         10  
6 2     2   2833 use Attean;
  2         199052  
  2         11  
7 2     2   953 use Attean::RDF;
  2         3  
  2         17  
8 2     2   9  
  2         5  
  2         27  
9             requires 'create_store'; # create_store( quads => \@quads )
10             with 'Test::Attean::StoreCleanup';
11              
12             test 'quadstore roles' => sub {
13             my $self = shift;
14             my $store = $self->create_store(quads => []);
15             ok $store->does('Attean::API::Store');
16             ok $store->does('Attean::API::QuadStore');
17             my $qiter = $store->get_quads();
18             ok $qiter->does('Attean::API::Iterator');
19             is($qiter->item_type, 'Attean::API::Quad');
20              
21             my $giter = $store->get_graphs;
22             ok $giter->does('Attean::API::Iterator');
23             is($giter->item_type, 'Attean::API::Term');
24             $self->cleanup_store($store);
25             };
26              
27             test 'quadstore get_quads empty' => sub {
28             my $self = shift;
29             my $store = $self->create_store(quads => []);
30             {
31             my $iter = $store->get_quads();
32             my @elements = $iter->elements;
33             is(scalar(@elements), 0);
34             }
35             {
36             my $iter = $store->get_quads(iri('s'), iri('p'));
37             my @elements = $iter->elements;
38             is(scalar(@elements), 0);
39             }
40             $self->cleanup_store($store);
41             };
42              
43             test 'quadstore get_quads with quads' => sub {
44             my $self = shift;
45             my $q1 = quad(iri('s'), iri('p'), iri('o'), iri('g'));
46             my $q2 = quad(iri('x'), iri('y'), iri('z'), iri('g'));
47             my $store = $self->create_store(quads => [$q1, $q2]);
48             {
49             my $iter = $store->get_quads();
50             my @elements = $iter->elements;
51             is(scalar(@elements), 2, '2 quads');
52             }
53             {
54             my $iter = $store->get_quads(iri('s'));
55             my @elements = $iter->elements;
56             is(scalar(@elements), 1, '1 quad with <s> as subject');
57             }
58             {
59             my $iter = $store->get_quads(variable('s'), undef, undef, iri('g'));
60             my @elements = $iter->elements;
61             is(scalar(@elements), 2, '2 quads with <g> as graph');
62             }
63             {
64             my $iter = $store->get_quads(iri('abc'));
65             my @elements = $iter->elements;
66             is(scalar(@elements), 0, '0 quads with <abc> as subject');
67             }
68             $self->cleanup_store($store);
69             };
70              
71             test 'count_quads' => sub {
72             my $self = shift;
73             my $q1 = quad(iri('s'), iri('p'), iri('o'), iri('g'));
74             my $q2 = quad(iri('x'), iri('y'), iri('z'), iri('g'));
75             my $store = $self->create_store(quads => [$q1, $q2]);
76             is($store->count_quads(), 2, '2 quads');
77             is($store->count_quads(iri('s')), 1, '1 quad with <s> as subject');
78             is($store->count_quads(variable('s'), undef, undef, iri('g')), 2, '2 quads with <g> as graph');
79             is($store->count_quads(iri('abc')), 0, '0 quads with <abc> as subject');
80             cmp_ok($store->count_quads_estimate(iri('abc')), '>=', 0, 'count_quads_estimate');
81             $self->cleanup_store($store);
82             };
83              
84             # test 'count_quads_estimate' => sub {};
85              
86             test 'size' => sub {
87             my $self = shift;
88             my $q1 = quad(iri('s'), iri('p'), iri('o'), iri('g'));
89             my $q2 = quad(iri('x'), iri('y'), iri('z'), iri('g'));
90             my $q3 = quad(iri('x'), iri('y'), iri('z'), iri('g2'));
91             my $store = $self->create_store(quads => [$q1, $q2, $q3]);
92             is($store->size(), 3);
93             $self->cleanup_store($store);
94             };
95              
96             test 'get_graphs' => sub {
97             my $self = shift;
98             my $q1 = quad(iri('s'), iri('p'), iri('o'), iri('g'));
99             my $q2 = quad(iri('x'), iri('y'), iri('z'), iri('g'));
100             my $q3 = quad(iri('x'), iri('y'), iri('z'), iri('g2'));
101             my $store = $self->create_store(quads => [$q1, $q2, $q3]);
102             my $iter = $store->get_graphs;
103             my @graphs = sort map { $_->value } $iter->elements;
104             is_deeply(\@graphs, ['g', 'g2']);
105             $self->cleanup_store($store);
106             };
107              
108             1;