-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcharge_test.t
94 lines (72 loc) · 3.87 KB
/
charge_test.t
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
92
93
94
use strict;
use warnings;
use Test::More 'no_plan';
use_ok 'BabySitterCharges';
my $bsc = new BabySitterCharges();
isa_ok($bsc, 'BabySitterCharges');
# Tests for setting start time
ok($bsc->set_start_time("5:00 PM"), "Setting start time to 5:00 PM is successful");
is($bsc->get_start_time(), "5:00 PM", "Retrieve start time of 5:00 PM");
is($bsc->get_start_hour(), 17, "Got 17 as hour for start time");
$bsc = new BabySitterCharges();
ok(!$bsc->set_start_time("4:00 PM"), "Setting start time to 4:00 PM is un-successful");
is($bsc->get_start_time(), undef, "Verify start time didn't save");
is($bsc->get_start_hour(), undef, "Verify start hour didn't save");
# Tests for setting end time
$bsc = new BabySitterCharges();
ok($bsc->set_end_time("4:00 AM"), "Setting end time to 4:00 AM is successful");
is($bsc->get_end_time(), "4:00 AM", "Retrieve end time of 4:00 AM");
is($bsc->get_end_hour(), 28, "Got 28 as hour for end time");
$bsc = new BabySitterCharges();
ok(!$bsc->set_end_time("5:00 AM"), "Setting end time to 5:00 AM is un-successful");
is($bsc->get_end_time(), undef, "Verify end time didn't save");
is($bsc->get_end_hour(), undef, "Verify end hour didn't save");
# Test military time
$bsc = new BabySitterCharges();
$bsc->set_start_time("18:00");
is($bsc->get_start_time(), "18:00", "Retrieved start time of 18:00");
is($bsc->get_start_hour(), "18", "Got 18 as hour for start time");
$bsc = new BabySitterCharges();
$bsc->set_end_time("23:00");
is($bsc->get_end_time(), "23:00", "Retrieved end time of 23:00");
is($bsc->get_end_hour(), "23", "Got 23 as hour for end time");
# Test invalid time
$bsc = new BabySitterCharges();
ok(!$bsc->set_start_time('abc'), "Fail to set start time for invalid time");
ok(!$bsc->set_start_time('16'), "Fail to set start time for invalid time");
ok(!$bsc->set_start_time(), "Fail to set start time for invalid time");
ok(!$bsc->set_end_time('abc'), "Fail to set end time for invalid time");
ok(!$bsc->set_end_time('16'), "Fail to set end time for invalid time");
ok(!$bsc->set_end_time(), "Fail to set end time for invalid time");
ok(!$bsc->set_bed_time('abc'), "Fail to set bed time for invalid time");
ok(!$bsc->set_bed_time('16'), "Fail to set bed time for invalid time");
ok(!$bsc->set_bed_time(), "Fail to set bed time for invalid time");
# Setting bed time
$bsc = new BabySitterCharges();
ok(!$bsc->set_bed_time("9:00 PM"), "Fail to set bedtime when there's no start or end time");
$bsc->set_start_time("5:00 PM");
ok(!$bsc->set_bed_time("9:00 PM"), "Fail to set bedtime when there's no end time");
$bsc = new BabySitterCharges();
$bsc->set_end_time("1:00 AM");
ok(!$bsc->set_bed_time("9:00 PM"), "Fail to set bedtime when there's no start time");
$bsc = new BabySitterCharges();
$bsc->set_start_time("8:00 PM");
$bsc->set_end_time("1:00 AM");
ok(!$bsc->set_bed_time("7:00 PM"), "Fail to set bedtime when it's not between start and end time");
is($bsc->get_bed_time(), undef, "Verify set bed time didn't save");
is($bsc->get_bed_hour(), undef, "Verify set bed hour didn't save");
ok(!$bsc->set_bed_time("12:00 PM"), "Fail to set bedtime if it's midnight");
is($bsc->get_bed_time(), undef, "Verify set bed time didn't save");
is($bsc->get_bed_hour(), undef, "Verify set bed hour didn't save");
ok(!$bsc->set_bed_time("1:00 AM"), "Fail to set bedtime if it's after midnight");
is($bsc->get_bed_time(), undef, "Verify set bed time didn't save");
is($bsc->get_bed_hour(), undef, "Verify set bed hour didn't save");
ok($bsc->set_bed_time("10:00 PM"), "Setting bed time between start and end time successful");
is($bsc->get_bed_time(), "10:00 PM", "Retrieve bed time of 10:00 PM");
is($bsc->get_bed_hour(), "22", "Got 22 as hour for bed time");
is($bsc->calculate(), '$56.00', 'Got $56.00 for the night');
$bsc = new BabySitterCharges();
$bsc->set_start_time("5:00 PM");
$bsc->set_end_time("4:00 AM");
$bsc->set_bed_time("9:00 PM");
is($bsc->calculate(), '$136.00', 'Got $136.00 for the night');