@@ -5,7 +5,70 @@ use Test::More;
5
5
6
6
my $module = $ENV {EXERCISM } ? ' Example' : ' SumOfMultiples' ;
7
7
8
- plan tests => 11;
8
+ my @cases = (
9
+ {
10
+ factors => [3, 5],
11
+ limit => 1,
12
+ expected => 0
13
+ },
14
+ {
15
+ factors => [3, 5],
16
+ limit => 4,
17
+ expected => 3
18
+ },
19
+ {
20
+ factors => [3, 5],
21
+ limit => 10,
22
+ expected => 23
23
+ },
24
+ {
25
+ factors => [3, 5],
26
+ limit => 100,
27
+ expected => 2318
28
+ },
29
+ {
30
+ factors => [3, 5],
31
+ limit => 1000,
32
+ expected => 233168
33
+ },
34
+ {
35
+ factors => [7, 13, 17],
36
+ limit => 20,
37
+ expected => 51
38
+ },
39
+ {
40
+ factors => [4, 6],
41
+ limit => 15,
42
+ expected => 30
43
+ },
44
+ {
45
+ factors => [5, 6, 8],
46
+ limit => 150,
47
+ expected => 4419
48
+ },
49
+ {
50
+ factors => [5, 25],
51
+ limit => 51,
52
+ expected => 275
53
+ },
54
+ {
55
+ factors => [43, 47],
56
+ limit => 10000,
57
+ expected => 2203160
58
+ },
59
+ {
60
+ factors => [1],
61
+ limit => 100,
62
+ expected => 4950
63
+ },
64
+ {
65
+ factors => [],
66
+ limit => 10000,
67
+ expected => 0
68
+ }
69
+ );
70
+
71
+ plan tests => 4 + scalar @cases ;
9
72
10
73
ok -e " $module .pm" , " Missing $module .pm"
11
74
or BAIL_OUT " You need to create file: $module .pm" ;
@@ -19,10 +82,13 @@ can_ok $module, "new"
19
82
can_ok $module , " to"
20
83
or BAIL_OUT " Missing package $module ; or missing sub to()" ;
21
84
22
- is $module -> new-> to(1), 0, " No multiples of 3 or 5 equals zero" ;
23
- is $module -> new-> to(4), 3, " One multiple of 3" ;
24
- is $module -> new-> to(10), 23, " Multiples of 3 and 5" ;
25
- is $module -> new-> to(100), 2_318, " Multiples of 3 and 5 to 100" ;
26
- is $module -> new-> to(1000), 233_168, " A lot of multiples of 3 and 5" ;
27
- is $module -> new(7, 13, 17)-> to(20), 51, " Multiples of 7, 13, 17" ;
28
- is $module -> new(43, 47)-> to(10_000), 2_203_160, " Multiples of 43, 47" ;
85
+
86
+ for my $case (@cases ) {
87
+ my @factors = @{$case -> {factors }};
88
+ my $desc = sprintf " Multiples of %s up to %s equals %s " ,
89
+ (scalar @factors ? (join ' and ' , @factors ) : ' nothing' ),
90
+ $case -> {limit }, $case -> {expected };
91
+
92
+ is $module -> new(@factors )-> to($case -> {limit }), $case -> {expected }, $desc ;
93
+ }
94
+
0 commit comments