AI-Prolog

 view release on metacpan or  search on metacpan

t/50engine.t  view on Meta::CPAN

#!/usr/bin/perl
# '$Id: 50engine.t,v 1.10 2005/08/06 23:28:40 ovid Exp $';
use warnings;
use strict;
use Test::More tests => 35;

#use Test::More 'no_plan';
use Clone qw/clone/;

my $CLASS;

BEGIN {
    chdir 't' if -d 't';
    unshift @INC => '../lib';
    $CLASS = 'AI::Prolog::Engine';
    use_ok($CLASS) or die;
}

# I hate the fact that they're interdependent.  That brings a 
# chicken and egg problem to squashing bugs.
use aliased 'AI::Prolog::TermList';
use aliased 'AI::Prolog::Term';
use aliased 'AI::Prolog::Parser';

my $database = Parser->consult(<<'END_PROLOG');
append([], X, X).
append([W|X],Y,[W|Z]) :- append(X,Y,Z).
END_PROLOG
my @keys = sort keys %{$database->{ht}};
my @expected = qw{append/3};
is_deeply \@keys, \@expected,
    'A brand new database should only have the predicates listed in the query';

my $parser = Parser->new("append(X,Y,[a,b,c,d]).");
my $query  = $parser->_term;

can_ok $CLASS, 'new';
ok my $engine = $CLASS->new($query, $database),
    '... and calling new with a valid query and database should succeed';
isa_ok $engine, $CLASS, '... and the object it returns';

@expected = qw{
    !/0
    append/3
    assert/1
    call/1
    consult/1
    eq/2
    fail/0
    ge/2
    gensym/1
    gt/2
    halt/0
    help/0
    help/1
    if/3
    is/2
    le/2
    listing/0
    listing/1
    lt/2
    ne/2
    nl/0
    not/1
    notrace/0
    once/1
    or/2



( run in 0.778 second using v1.01-cache-2.11-cpan-39bf76dae61 )