AI-Prolog

 view release on metacpan or  search on metacpan

t/80preprocessor_math.t  view on Meta::CPAN

#!/usr/bin/perl
# '$Id: 80preprocessor_math.t,v 1.3 2005/08/06 23:28:40 ovid Exp $';
use warnings;
use strict;
use Test::More tests => 140;
#use Test::More qw/no_plan/;

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

foreach my $compare (qw( is = < <= > >= == \= )) {
    ok $CLASS->_compare($compare), "$compare matches : compare";
}

my @math_terms = qw/
    X
    Y_
    3
    0.3
    3.0
    .3
    -7
    +.3
    -.19
/;
foreach my $math_term (@math_terms) {
    ok $CLASS->_simple_math_term($math_term), "$math_term matches : simple math term";
}
my @not_math_terms = qw/
    x
    y_
    .
    _
    _y
    _9
/;
foreach my $not_math_term (@not_math_terms) {
    ok ! $CLASS->_simple_math_term($not_math_term), "$not_math_term should not match : simple math term";
}

foreach my $op (qw{- + * / % **}) {
    ok $CLASS->_op($op), "$op matches : op";
}

foreach my $not_op (qw{ . _ ( ) }) {
    ok ! $CLASS->_op($not_op), "$not_op should not match :  op";
}
 
my @rhs = (
    '3',
    'A%2',
    'A % 2',
    '17.2 * A % 2',
    'A+B+C+D+2',
    '7/2 ** 4',
);
foreach my $simple_rhs (@rhs) {
    ok $CLASS->_simple_rhs($simple_rhs), "$simple_rhs matches : simple rhs";
}



( run in 1.073 second using v1.01-cache-2.11-cpan-98d9bbf8dc8 )