AI-Prolog
view release on metacpan or search on metacpan
t/50engine.t view on Meta::CPAN
@keys = sort keys %{$database->ht};
is_deeply \@keys, \@expected,
'... and the basic prolog terms should be bootstrapped';
can_ok $engine, 'results';
is $engine->results, 'append([], [a,b,c,d], [a,b,c,d])',
'... calling it the first time should provide the first unification';
is $engine->results, 'append([a], [b,c,d], [a,b,c,d])',
'... and then the second unification';
is $engine->results, 'append([a,b], [c,d], [a,b,c,d])',
'... and then the third unification';
is $engine->results, 'append([a,b,c], [d], [a,b,c,d])',
'... and then the fifth unification';
is $engine->results, 'append([a,b,c,d], [], [a,b,c,d])',
'... and then the last unification unification';
ok ! defined $engine->results,
'... and it should return undef when there are no more results';
my $bootstrapped_db = clone($database);
$query = Term->new('append(X,[d],[a,b,c,d]).');
can_ok $engine, 'query';
$engine->query($query);
is $engine->results,'append([a,b,c], [d], [a,b,c,d])',
'... and it should let us issue a new query against the same db';
ok !$engine->results, '... and it should not return spurious results';
# this will eventually test data structures
can_ok $CLASS, 'formatted';
$engine->formatted(0);
$engine->query(Term->new('append(X,Y,[a,b,c,d])'));
my $result = $engine->results;
is_deeply $result->X, [], '... and the X result should be correct';
is_deeply $result->Y, [qw/a b c d/], '... and the Y result should be correct';
$result = $engine->results;
is_deeply $result->X, [qw/a/], '... and the X result should be correct';
is_deeply $result->Y, [qw/b c d/], '... and the Y result should be correct';
$result = $engine->results;
is_deeply $result->X, [qw/a b/], '... and the X result should be correct';
is_deeply $result->Y, [qw/c d/], '... and the Y result should be correct';
$result = $engine->results;
is_deeply $result->X, [qw/a b c/], '... and the X result should be correct';
is_deeply $result->Y, [qw/d/], '... and the Y result should be correct';
$result = $engine->results;
is_deeply $result->X, [qw/a b c d/], '... and the X result should be correct';
is_deeply $result->Y, [], '... and the Y result should be correct';
ok ! defined ($result = $engine->results),
'... and results() should return undef when there are no more results';
can_ok $CLASS, 'raw_results';
$CLASS->raw_results(1);
$CLASS->formatted(0);
$engine->query(Term->new('append(X,Y,[a,b,c,d])'));
is_deeply $engine->results, ['append', [], [qw/a b c d/], [qw/a b c d/]],
'... and subsequent results should match expectations';
is_deeply $engine->results, ['append', [qw/a/], [qw/b c d/], [qw/a b c d/]],
'... and subsequent results should match expectations';
is_deeply $engine->results, ['append', [qw/a b/], [qw/c d/], [qw/a b c d/]],
'... and subsequent results should match expectations';
is_deeply $engine->results, ['append', [qw/a b c/], [qw/d/], [qw/a b c d/]],
'... and subsequent results should match expectations';
is_deeply $engine->results, ['append', [qw/a b c d/], [], [qw/a b c d/]],
'... and subsequent results should match expectations';
ok ! defined $engine->results,
'... and it should return undef when there are no more results'
( run in 1.444 second using v1.01-cache-2.11-cpan-39bf76dae61 )