2 # This is automatically generated by author/import-moose-test.pl.
3 # DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4 use t::lib::MooseCompat;
19 isa => 'ArrayRef[Observer]',
21 default => sub { [] },
23 'add_observer' => 'push',
24 'count_observers' => 'count',
30 foreach my $observer ( $self->observers() ) {
31 $observer->update($self);
52 traits => ['Counter'],
62 after qw(inc_counter dec_counter) => sub {
79 my ( $self, $subject ) = @_;
80 like $subject->count, qr{^-?\d+$},
81 'Observed number ' . $subject->count;
87 my $count = Counter->new();
89 ok( $count->can('add_observer'), 'add_observer method added' );
91 ok( $count->can('count_observers'), 'count_observers method added' );
93 ok( $count->can('inc_counter'), 'inc_counter method added' );
95 ok( $count->can('dec_counter'), 'dec_counter method added' );
97 $count->add_observer( Display->new() );
99 is( $count->count_observers, 1, 'Only one observer' );
101 is( $count->count, 0, 'Default to zero' );
105 is( $count->count, 1, 'Increment to one ' );
107 $count->inc_counter for ( 1 .. 6 );
109 is( $count->count, 7, 'Increment up to seven' );
113 is( $count->count, 6, 'Decrement to 6' );
115 $count->dec_counter for ( 1 .. 5 );
117 is( $count->count, 1, 'Decrement to 1' );
119 $count->dec_counter for ( 1 .. 2 );
121 is( $count->count, -1, 'Negative numbers' );
125 is( $count->count, 0, 'Back to zero' );