File: step.t

package info (click to toggle)
libbusiness-isbn-perl 3.003-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,412 kB
  • ctags: 89
  • sloc: perl: 647; makefile: 7
file content (70 lines) | stat: -rw-r--r-- 1,754 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use Test::More 0.95;

use strict;
use warnings;

my $class       = 'Business::ISBN';
my @methods     = qw( increment decrement _step_article_code );
my $isbn_string = '978-1-4493-9311-3'; # Mastering Perl

my $isbn;

subtest setup => sub {
	use_ok( $class );
	can_ok( $class, @methods );
	};

subtest make_isbn => sub {
	$isbn = $class->new( $isbn_string );
	isa_ok( $isbn, $class );
	can_ok( $class, @methods );	
	};

subtest one_more => sub {
	my $isbn     = $class->new( '978-1-4493-9311-3' );
	isa_ok( $isbn, $class );
	my $one_more = $class->new( '978-1-4493-9312-3' );
	$one_more->fix_checksum;
	isa_ok( $one_more, $class );

	my $isbn_one_more = $isbn->increment;
	isa_ok( $isbn_one_more, $class );
	
	is( $one_more->as_string, $isbn_one_more->as_string, 'One more matches' );
	};

subtest one_less => sub {
	my $isbn     = $class->new( '978-1-4493-9311-3' );
	isa_ok( $isbn, $class );
	my $one_less = $class->new( '978-1-4493-9310-3' );
	$one_less->fix_checksum;
	isa_ok( $one_less, $class );

	my $isbn_one_less = $isbn->decrement;
	isa_ok( $isbn_one_less, $class );
	
	is( $one_less->as_string, $isbn_one_less->as_string, 'One less matches' );
	};

subtest too_little => sub {
	my $isbn     = $class->new( '978-1-4493-0000-3' );
	$isbn->fix_checksum;
	isa_ok( $isbn, $class );

	my $isbn_one_less = $isbn->decrement;

	is( $isbn_one_less, Business::ISBN::ARTICLE_CODE_OUT_OF_RANGE(),
		'Incrementing below 0 would be out of range' );
	};

subtest too_much => sub {
	my $isbn     = $class->new( '978-1-4493-9999-3' );
	$isbn->fix_checksum;
	isa_ok( $isbn, $class );

	my $isbn_one_more = $isbn->increment;
	is( $isbn_one_more, Business::ISBN::ARTICLE_CODE_OUT_OF_RANGE(),
		'Incrementing past 9999 would be out of range' );
	};

done_testing();