AI-Gene-Sequence

 view release on metacpan or  search on metacpan

t/tgene.t  view on Meta::CPAN

# Gtest is a small package used to test the AI::Gene::Sequence
# package.  It provides a generate_token method and a seed_gene
# method, the first is highly deterministic (so tests of a module
# which hinge on randomness can work) and the second sets up a gene
# ready for a test.

# Also is a new method, which creates the gene and seeds it and
# 'd' and 'g' methods, which return (stringified) versions of the
# sequence ($self->[0]) and gene (@{$self->[1]}) respectively.

package GTest;
our (@ISA);
use AI::Gene::Sequence;
@ISA = qw(AI::Gene::Sequence);

sub new {
  my $class = shift;
  my $self = ['',[]];
  bless $self, $class;
  $self->seed_gene;
  return $self;

t/tgene.t  view on Meta::CPAN

  my $self = shift;
  return $self->[0];
}

sub g {
  my $self = shift;
  return join('', @{$self->[1]});
}

package main;
use Test;
# see above for a small package ( GTest ) used to test G::G::S
BEGIN {plan tests => 111, todo =>[]}
my $hammer = 30; # set big to bash at methods with randomness

{ # test1
  # first of all, does our testing package behave
  my $gene = GTest->new;
  die "$0: Broken render" unless $gene->d eq 'abcdefghij'
                            and $gene->g eq 'abcdefghij';
  die "$0: Broken generate" unless ($gene->generate_token('a'))[1] eq 'A'
    and ($gene->generate_token())[0] eq 'n';
  ok(1);
}
my $main = GTest->new;
{ print "# clone\n";
  my $gene = $main->clone;
  ok($gene->g, $main->g);
}

{ print "# mutate_minor\n";
  my $gene = $main->clone;
  my $rt = $gene->mutate_minor(1);
  ok ($rt, 1); # return value
  ok ($gene->g ne $main->g); # changed

t/tsimp.t  view on Meta::CPAN


# GtestS is a small package used to test the AI::Gene::Simple
# package.  It provides a generate_token method and a seed_gene
# method, the first is highly deterministic (so tests of a module
# which hinge on randomness can work) and the second sets up a gene
# ready for a test.

# Also is a new method, which creates the gene and seeds it and
# a 'd' method, which returns a stringified version of $self->[0]

package GTestS;
our (@ISA);
use AI::Gene::Simple;
@ISA = qw(AI::Gene::Simple);

sub new {
  my $class = shift;
  my $self = [[]];
  bless $self, $class;
  $self->seed_gene;
  return $self;

t/tsimp.t  view on Meta::CPAN

  }
  return $prev;
}

sub d {
  my $self = shift;
  return join('',@{$self->[0]});
}

package main;
use Test;
# see above for a small package ( GTest ) used to test G::G::S
BEGIN {plan tests => 101, todo =>[]}
my $hammer = 30; # set big to bash at methods with randomness

{ # test1
  # first of all, does our testing package behave
  my $gene = GTestS->new;
  die "$0: Broken render" unless $gene->d eq 'abcdefghij';
  die "$0: Broken generate" unless $gene->generate_token('a') eq 'A'
    and $gene->generate_token eq 'N';
  ok(1);
}
my $main = GTestS->new;
{ print "# clone\n";
  my $gene = $main->clone;
  ok($gene->d, $main->d);
}

{ print "# mutate_minor\n";
  my $gene = $main->clone;
  my $rt = $gene->mutate_minor(1);
  ok ($rt, 1); # return value
  ok ($gene->d ne $main->d); # changed



( run in 0.806 second using v1.01-cache-2.11-cpan-4d50c553e7e )