Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Practical Test-driven Development Presentation

.pdf
Скачиваний:
5
Добавлен:
23.02.2015
Размер:
836.08 Кб
Скачать

Adding more tests with Test::Class

Basic Testing in Perl

--(0)> prove -Ilib t/TestPercentOwnership.pm

t/TestPercentOwnership....ok 1/27Use of uninitialized value in sprintf at lib/ PercentOwnership.pm line 29.

Use of uninitialized value in multiplication (*) at lib/PercentOwnership.pm line 29.

#Failed test 'return undef for non-existant units'

#at t/TestPercentOwnership.pm line 109.

#(in TestPercentOwnership->non_existant_unit)

#

got: '0'

 

 

#

expected: undef

 

 

t/TestPercentOwnership....

NOK 13/27# Looks

like you failed 1 test of 27.

t/TestPercentOwnership....

dubious

 

 

Test returned status 1 (wstat 256,

0x100)

DIED. FAILED test 13

 

 

 

Failed 1/27 tests, 96.30% okay

 

Failed Test

Stat Wstat Total

Fail List of Failed

-------------------------------------------------------------------------------

t/TestPercentOwnership.pm

1

256

27

1

13

Failed 1/1 test scripts. 1/27 subtests

failed.

 

 

Files=1, Tests=27, 0 wallclock secs (

0.05 cusr

+ 0.02 csys = 0.07 CPU)

Failed 1/1 test programs. 1/27

subtests

failed.

 

121

Adding more tests with Test::Class

Basic Testing in Perl

"lib/PercentOwnership.pm"

21

sub percent_ownership {

22

my ($self, %args) = @_;

23

 

24

return unless exists $self->{unit_info}->{$args{unit_number}};

25

 

26

my $adjusted_building_size = sum map {

27

$self->{unit_info}->{$_}->{square_footage} *

28

sprintf( "1.%02d", $self->{unit_info}->{$_}->{floor} )

29

} keys %{ $self->{unit_info} };

30

 

31

my $adjusted_unit_size =

32

$self->{unit_info}->{ $args{unit_number} }->{square_footage} *

33

sprintf( "1.%02d", $self->{unit_info}->{ $args{unit_number} }->{floor} );

34

 

35return sprintf( "%0.4f", $adjusted_unit_size / $adjusted_building_size ) * 100;

36}

122

Adding more tests with Test::Class

Basic Testing in Perl

--(0)> prove -Ilib t/TestPercentOwnership.pm t/TestPercentOwnership....ok

All tests successful.

Files=1, Tests=27, 1 wallclock secs ( 0.05 cusr + 0.02 csys = 0.07 CPU)

123

Adding more tests with Test::Class

Basic Testing in Perl

"t/PercentOwnership.pm"

116 sub add_unit_with_no_arguments : Test(1) {

117my ($self) = @_;

118is(

119

$self->{po}->add_unit,

120

undef,

121

'no arguments provided to add_unit'

122);

123}

124

Adding more tests with Test::Class

Basic Testing in Perl

--(0)> prove -Ilib t/TestPercentOwnership.pm

t/TestPercentOwnership....ok 1/30Use of uninitialized value in numeric lt (<) at lib/ PercentOwnership.pm line 16.

Use of uninitialized value in hash element at lib/PercentOwnership.pm line 18.

#Failed test 'no arguments provided to add_unit'

#at t/TestPercentOwnership.pm line 118.

#(in TestPercentOwnership->add_unit_with_no_arguments)

#got: 'HASH(0x86fde0)'

#expected: undef

t/TestPercentOwnership....

NOK 5/30# Looks like you failed 1 test of 30.

t/TestPercentOwnership....

dubious

Test returned status 1 (wstat 256, 0x100)

DIED. FAILED test 5

 

Failed 1/30 tests, 96.67% okay

Failed Test

Stat Wstat Total Fail List of Failed

-------------------------------------------------------------------------------

t/TestPercentOwnership.pm

1

256

30

1

5

 

Failed 1/1 test scripts. 1/30 subtests

failed.

 

 

 

Files=1, Tests=30, 0 wallclock secs (

0.05 cusr +

0.02 csys = 0.07 CPU)

Failed 1/1 test programs. 1/30

subtests

failed.

 

 

125

Adding more tests with Test::Class

Basic Testing in Perl

"lib/PercentOwnership.pm"

13

sub add_unit {

14

my ($self, %unit_info) = @_;

15

 

16

return unless

17

(grep { exists $unit_info{$_} }

18

qw(unit_number square_footage floor)) == 3;

19

 

20

$unit_info{floor} = 0 if( $unit_info{floor} < 0 );

21

 

22$self->{unit_info}->{ $unit_info{unit_number} } = \%unit_info;

23}

126

Adding more tests with Test::Class

Basic Testing in Perl

--(0)> prove -Ilib t/TestPercentOwnership.pm t/TestPercentOwnership....ok

All tests successful.

Files=1, Tests=30, 0 wallclock secs ( 0.05 cusr + 0.02 csys = 0.07 CPU)

127

Adding more tests with Test::Class

Basic Testing in Perl

"t/PercentOwnership.pm"

125 sub percent_ownership_with_no_arguments : Test(1) {

126my ($self) = @_;

127$self->unit_adder( 100, 500, 1 );

128is(

129

$self->{po}->percent_ownership,

130

undef,

131

'no arguments provided to percent_ownership'

132);

133}

128

Adding more tests with Test::Class

Basic Testing in Perl

--(0)> prove -Ilib t/TestPercentOwnership.pm

t/TestPercentOwnership....ok 1/33Use of uninitialized value in exists at lib/ PercentOwnership.pm line 28.

t/TestPercentOwnership....ok All tests successful.

Files=1, Tests=33, 0 wallclock secs ( 0.05 cusr + 0.02 csys = 0.07 CPU)

129

Adding more tests with Test::Class

Basic Testing in Perl

"lib/PercentOwnership.pm"

25 sub percent_ownership {

26 my ($self, %args) = @_; 27

28return unless exists $args{unit_number};

29return unless exists $self->{unit_info}->{$args{unit_number}};

31my $adjusted_building_size = sum map {

32$self->{unit_info}->{$_}->{square_footage} *

33

sprintf( "1.%02d", $self->{unit_info}->{$_}->{floor} )

34

} keys %{ $self->{unit_info} };

35

 

36

my $adjusted_unit_size =

37

$self->{unit_info}->{ $args{unit_number} }->{square_footage} *

38

sprintf( "1.%02d", $self->{unit_info}->{ $args{unit_number} }->{floor} );

39

 

40return sprintf( "%0.4f", $adjusted_unit_size / $adjusted_building_size ) * 100;

41}

130

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]