AI-Fuzzy

 view release on metacpan or  search on metacpan

test.pl  view on Meta::CPAN

use Test;
BEGIN { plan tests => 17 };
use AI::Fuzzy;
ok(1); # If we made it this far, we're ok.

$l = new AI::Fuzzy::Label;
ok(2); # If we made it this far, we're ok.

$s = new AI::Fuzzy::Set;
ok(3); # If we made it this far, we're ok.

$a = new AI::Fuzzy::Axis;
ok(4); # If we made it this far, we're ok.

$a->addlabel("baby",        -1,   1, 2.5);
$a->addlabel("toddler",      1, 1.5, 3.5);
$a->addlabel("little kid",   2,   7,  12);
$a->addlabel("kid",          6,  10,  14);
$a->addlabel("teenager",    12,  16,  20);
$a->addlabel("young adult", 18,  27,  35);
$a->addlabel("adult",       25,  50,  75);
$a->addlabel("senior",      60,  80, 110);
$a->addlabel("relic",      100, 150, 200);


ok($a->labelvalue(50)->name, "adult");
ok($a->labelvalue(5)->name,  "little kid");


$fs_tall_people = new AI::Fuzzy::Set( Lester=>34, Bob=>100, Max=>86 );
   
# $x will be 86
$x = $fs_tall_people->membership( "Max" );
ok($x, 86);

# get list of members, sorted from least membership to greatest:
@shortest_first =  $fs_tall_people->members();
ok @shortest_first, 3, "got " . join(',', @shortest_first) . ", wanted " . join(',', qw(Lester Max Bob));


$a1 = new AI::Fuzzy::Axis;

$a1->addlabel( "cold", 32, 60, 70 );
$a1->addlabel( "warm", 60, 70, 90 );
$a1->addlabel( "hot", 77, 80, 100 );
    # what I consider hot. :) (in Farenheit, of course!)
ok $a1;

$a = $a1->applicability(99,"hot");
    # $a is now the degree to which $label applies to $value
ok $a;

$l = $a1->labelvalue(99);
    # applies a label to $value
ok ($l->name, "hot");

@l = $a1->labelvalue(65);
%l = $a1->labelvalue(65);
    # returns a list of labels and their applicability values
ok @l, 4, "got " . join (',',@l) . " wanted " . join(',',qw(cold 0.5 warm 0.5));
ok ($l{cold}, .5);



( run in 0.420 second using v1.01-cache-2.11-cpan-7fcb06a456a )