File: methods.t

package info (click to toggle)
libdate-pregnancy-perl 0.06-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 168 kB
  • sloc: perl: 169; makefile: 2
file content (91 lines) | stat: -rw-r--r-- 1,417 bytes parent folder | download | duplicates (3)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# $Id$

use strict;
use Test::More tests => 17;
use DateTime;

#test 1
use_ok( "Date::Pregnancy", qw(
	calculate_birthday
	_countback 
	_266days 
	_40weeks
));

my $dt = DateTime->new(
	year  => 2004,
	month => 3,
	day   => 19,
);

#test 2-3
my $birthday;
ok($birthday = _40weeks($dt));
isa_ok($birthday, "DateTime");
$birthday = undef;

#test 4-5
ok($birthday = _266days($dt, 28));
isa_ok($birthday, "DateTime");
$birthday = undef;

#test 6-7
ok($birthday = _countback($dt));
isa_ok($birthday, "DateTime");
$birthday = undef;

#test 8
eval { 
calculate_birthday(
	first_day_of_last_period => $dt,
	method => 'nonexisting')
}; 
like($@, qr/Unknown method: nonexisting/);

$dt = DateTime->new(
	year  => 2004,
	month => 12,
	day   => 24,
);

$birthday = calculate_birthday(
	first_day_of_last_period => $dt,
	method => 'countback'
);

#test 9-11
is($birthday->day, 30);
is($birthday->month, 9);
is($birthday->year, 2005);

$dt = DateTime->new(
	year  => 2006,
	month => 7,
	day   => 1,
);

$birthday = calculate_birthday(
	first_day_of_last_period => $dt,
	method => 'countback'
);

#test 12-14
is($birthday->day, 8);
is($birthday->month, 4);
is($birthday->year, 2007);

$dt = DateTime->new(
	year  => 2007,
	month => 1,
	day   => 1,
);

$birthday = calculate_birthday(
	first_day_of_last_period => $dt,
	method => 'countback'
);

#test 15-17
is($birthday->day, 8);
is($birthday->month, 10);
is($birthday->year, 2007);