Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Toru Yamaguchi committed Dec 6, 2011
1 parent 5de329e commit 597dbab
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 4 deletions.
4 changes: 0 additions & 4 deletions t/00_compile.t

This file was deleted.

3 changes: 3 additions & 0 deletions t/compile.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use Test::LoadAllModules;

BEGIN { all_uses_ok search_path => 'Data::RuledFactory' }
77 changes: 77 additions & 0 deletions t/rule/sequence.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
use strict;
use warnings;

use Test::More;
use Data::RuledFactory::Rule::Sequence;

subtest 'min: 1. max: 10. step: 1' => sub {
my $r = Data::RuledFactory::Rule::Sequence->new(
min => 1,
max => 10,
step => 1,
);

my $i;
for $i (1..10) {
my $expect = 1 + 1 * ( $i - 1 );
ok $r->has_next, sprintf('has_next() is true (times: %d)', $i);
is $r->next, $expect, sprintf('next() is %02.2f (times: %d)', $expect, $i);
}

$i++;

ok !$r->has_next, sprintf('has_next() is false (times: %d)', $i);
is $r->next, undef, sprintf('next() is undef (times: %d)', $i);
};

subtest 'min: 1. max: 10. step: 1.5' => sub {
my $r = Data::RuledFactory::Rule::Sequence->new(
min => 1,
max => 10,
step => 1.5,
);

my $i;
for $i (1..7) {
my $expect = 1 + 1.5 * ( $i - 1 );
ok $r->has_next, sprintf('has_next() is true (times: %d)', $i);
is $r->next, $expect, sprintf('next() is %02.2f (times: %d)', $expect, $i);
}

$i++;

ok !$r->has_next, sprintf('has_next() is false (times: %d)', $i);
is $r->next, undef, sprintf('next() is undef (times: %d)', $i);
};

subtest 'min: -10. max: -1. step: -3' => sub {
my $r = Data::RuledFactory::Rule::Sequence->new(
min => -10,
max => -1,
step => -3,
);

my $i;
for $i (1..4) {
my $expect = -1 - 3 * ( $i - 1 );
ok $r->has_next, sprintf('has_next() is true (times: %d)', $i);
is $r->next, $expect, sprintf('next() is %02.2f (times: %d)', $expect, $i);
}

$i++;

ok !$r->has_next, sprintf('has_next() is false (times: %d)', $i);
is $r->next, undef, sprintf('next() is undef (times: %d)', $i);
};

done_testing;

# Local Variables:
# mode: perl
# perl-indent-level: 4
# indent-tabs-mode: nil
# coding: utf-8-unix
# End:
#
# vim: expandtab shiftwidth=4:

0 comments on commit 597dbab

Please sign in to comment.