Lines 1-259
Link Here
|
1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
2 |
|
2 |
|
3 |
use Modern::Perl; |
3 |
use Modern::Perl; |
4 |
use Test::More tests => 46; |
4 |
use Test::More tests => 7; |
5 |
use C4::Serials qw( GetNextSeq ); |
5 |
use C4::Serials qw( GetNextSeq ); |
6 |
|
6 |
|
7 |
# TEST CASE 1 - 1 variable, from 1 to 4 |
7 |
subtest "TEST CASE 1 - 1 variable, from 1 to 4" => sub { |
8 |
my $subscription = { |
8 |
plan tests => 5; |
9 |
lastvalue1 => 1, lastvalue2 => 1, lastvalue3 => 1, |
|
|
10 |
innerloop1 => 0, innerloop2 => 0, innerloop3 => 0, |
11 |
skip_serialseq => 0, |
12 |
irregularity => '', |
13 |
locale => 'en', |
14 |
}; |
15 |
my $pattern = { |
16 |
add1 => 1, add2 => 0, add3 => 0, |
17 |
every1 => 1, every2 => 0, every3 => 0, |
18 |
whenmorethan1 => 4, whenmorethan2 => 0, whenmorethan3 => 0, |
19 |
setto1 => 1, setto2 => 0, setto3 => 0, |
20 |
numberingmethod => 'X: {X}', |
21 |
numbering1 => '', |
22 |
numbering2 => '', |
23 |
numbering3 => '', |
24 |
}; |
25 |
|
9 |
|
26 |
my $seq = _next_seq($subscription, $pattern); |
10 |
my $subscription = { |
27 |
is($seq, 'X: 2'); |
11 |
lastvalue1 => 1, lastvalue2 => 1, lastvalue3 => 1, |
28 |
$seq = _next_seq($subscription, $pattern); |
12 |
innerloop1 => 0, innerloop2 => 0, innerloop3 => 0, |
29 |
is($seq, 'X: 3'); |
13 |
skip_serialseq => 0, |
30 |
$seq = _next_seq($subscription, $pattern); |
14 |
irregularity => '', |
31 |
is($seq, 'X: 4'); |
15 |
locale => 'en', |
32 |
$seq = _next_seq($subscription, $pattern); |
16 |
}; |
33 |
is($seq, 'X: 1'); |
17 |
my $pattern = { |
34 |
$seq = _next_seq($subscription, $pattern); |
18 |
add1 => 1, add2 => 0, add3 => 0, |
35 |
is($seq, 'X: 2'); |
19 |
every1 => 1, every2 => 0, every3 => 0, |
|
|
20 |
whenmorethan1 => 4, whenmorethan2 => 0, whenmorethan3 => 0, |
21 |
setto1 => 1, setto2 => 0, setto3 => 0, |
22 |
numberingmethod => 'X: {X}', |
23 |
numbering1 => '', |
24 |
numbering2 => '', |
25 |
numbering3 => '', |
26 |
}; |
27 |
|
28 |
my $seq = _next_seq( $subscription, $pattern ); |
29 |
is( $seq, 'X: 2', "X is increased for next issue" ); |
30 |
$seq = _next_seq( $subscription, $pattern ); |
31 |
is( $seq, 'X: 3', "X is increased again" ); |
32 |
$seq = _next_seq( $subscription, $pattern ); |
33 |
is( $seq, 'X: 4', "X is increased again" ); |
34 |
$seq = _next_seq( $subscription, $pattern ); |
35 |
is( $seq, 'X: 1', "X reset when crossing the 'whenmorethan' threshold" ); |
36 |
$seq = _next_seq( $subscription, $pattern ); |
37 |
is( $seq, 'X: 2', "X continues to increase correctly after reset" ); |
36 |
|
38 |
|
37 |
# TEST CASE 2 - 1 variable, use 'dayname' numbering, from 1 to 7 |
|
|
38 |
$subscription = { |
39 |
lastvalue1 => 1, lastvalue2 => 1, lastvalue3 => 1, |
40 |
innerloop1 => 0, innerloop2 => 0, innerloop3 => 0, |
41 |
skip_serialseq => 0, |
42 |
irregularity => '', |
43 |
locale => 'C', |
44 |
}; |
45 |
$pattern = { |
46 |
add1 => 1, add2 => 1, add3 => 0, |
47 |
every1 => 1, every2 => 1, every3 => 0, |
48 |
whenmorethan1 => 7, whenmorethan2 => 7, whenmorethan3 => 0, |
49 |
setto1 => 1, setto2 => 1, setto3 => 0, |
50 |
numberingmethod => 'dayname: {X} | dayabrv: {Y}', |
51 |
numbering1 => 'dayname', |
52 |
numbering2 => 'dayabrv', |
53 |
numbering3 => '', |
54 |
}; |
39 |
}; |
55 |
|
40 |
|
56 |
$seq = _next_seq($subscription, $pattern); |
41 |
subtest "TEST CASE 2 - 1 variable, use 'dayname' numbering, from 1 to 7" => sub { |
57 |
is($seq, 'dayname: Tuesday | dayabrv: Tue'); |
42 |
plan tests => 7; |
58 |
$seq = _next_seq($subscription, $pattern); |
43 |
my $subscription = { |
59 |
is($seq, 'dayname: Wednesday | dayabrv: Wed'); |
44 |
lastvalue1 => 1, lastvalue2 => 1, lastvalue3 => 1, |
60 |
$seq = _next_seq($subscription, $pattern); |
45 |
innerloop1 => 0, innerloop2 => 0, innerloop3 => 0, |
61 |
is($seq, 'dayname: Thursday | dayabrv: Thu'); |
46 |
skip_serialseq => 0, |
62 |
$seq = _next_seq($subscription, $pattern); |
47 |
irregularity => '', |
63 |
is($seq, 'dayname: Friday | dayabrv: Fri'); |
48 |
locale => 'C', |
64 |
$seq = _next_seq($subscription, $pattern); |
49 |
}; |
65 |
is($seq, 'dayname: Saturday | dayabrv: Sat'); |
50 |
my $pattern = { |
66 |
$seq = _next_seq($subscription, $pattern); |
51 |
add1 => 1, add2 => 1, add3 => 0, |
67 |
is($seq, 'dayname: Sunday | dayabrv: Sun'); |
52 |
every1 => 1, every2 => 1, every3 => 0, |
68 |
$seq = _next_seq($subscription, $pattern); |
53 |
whenmorethan1 => 7, whenmorethan2 => 7, whenmorethan3 => 0, |
69 |
is($seq, 'dayname: Monday | dayabrv: Mon'); |
54 |
setto1 => 1, setto2 => 1, setto3 => 0, |
|
|
55 |
numberingmethod => 'dayname: {X} | dayabrv: {Y}', |
56 |
numbering1 => 'dayname', |
57 |
numbering2 => 'dayabrv', |
58 |
numbering3 => '', |
59 |
}; |
70 |
|
60 |
|
71 |
# TEST CASE 3 - 1 variable, use 'monthname' numbering, from 0 to 11 by step of 2 |
61 |
my $seq = _next_seq( $subscription, $pattern ); |
72 |
$subscription = { |
62 |
is( $seq, 'dayname: Tuesday | dayabrv: Tue', "Day name is correctly generated for second day" ); |
73 |
lastvalue1 => 0, lastvalue2 => 0, lastvalue3 => 0, |
63 |
$seq = _next_seq( $subscription, $pattern ); |
74 |
innerloop1 => 0, innerloop2 => 0, innerloop3 => 0, |
64 |
is( $seq, 'dayname: Wednesday | dayabrv: Wed', "Day name is correctly generated for third day" ); |
75 |
skip_serialseq => 0, |
65 |
$seq = _next_seq( $subscription, $pattern ); |
76 |
irregularity => '', |
66 |
is( $seq, 'dayname: Thursday | dayabrv: Thu', "Day name is correctly generated for fourth day" ); |
77 |
locale => 'C', # locale set to 'C' to ensure we'll have english strings |
67 |
$seq = _next_seq( $subscription, $pattern ); |
78 |
}; |
68 |
is( $seq, 'dayname: Friday | dayabrv: Fri', "Day name is correctly generated for fifth day" ); |
79 |
$pattern = { |
69 |
$seq = _next_seq( $subscription, $pattern ); |
80 |
add1 => 2, add2 => 2, add3 => 0, |
70 |
is( $seq, 'dayname: Saturday | dayabrv: Sat', "Day name is correctly generated for sixth day" ); |
81 |
every1 => 1, every2 => 1, every3 => 0, |
71 |
$seq = _next_seq( $subscription, $pattern ); |
82 |
whenmorethan1 => 11, whenmorethan2 => 11, whenmorethan3 => 0, |
72 |
is( $seq, 'dayname: Sunday | dayabrv: Sun', "Day name is correctly generated for seventh day" ); |
83 |
setto1 => 0, setto2 => 0, setto3 => 0, |
73 |
$seq = _next_seq( $subscription, $pattern ); |
84 |
numberingmethod => 'monthname: {X} | monthabrv: {Y}', |
74 |
is( |
85 |
numbering1 => 'monthname', |
75 |
$seq, 'dayname: Monday | dayabrv: Mon', |
86 |
numbering2 => 'monthabrv', |
76 |
"Day is correctly reset and name is correctly generated for first day" |
87 |
numbering3 => '', |
77 |
); |
88 |
}; |
78 |
}; |
89 |
|
79 |
|
90 |
$seq = _next_seq($subscription, $pattern); |
80 |
subtest "TEST CASE 3 - 1 variable, use 'monthname' numbering, from 0 to 11 by step of 2" => sub { |
91 |
is($seq, 'monthname: March | monthabrv: Mar'); |
81 |
plan tests => 7; |
92 |
$seq = _next_seq($subscription, $pattern); |
82 |
my $subscription = { |
93 |
is($seq, 'monthname: May | monthabrv: May'); |
83 |
lastvalue1 => 0, lastvalue2 => 0, lastvalue3 => 0, |
94 |
$seq = _next_seq($subscription, $pattern); |
84 |
innerloop1 => 0, innerloop2 => 0, innerloop3 => 0, |
95 |
is($seq, 'monthname: July | monthabrv: Jul'); |
85 |
skip_serialseq => 0, |
96 |
$seq = _next_seq($subscription, $pattern); |
86 |
irregularity => '', |
97 |
is($seq, 'monthname: September | monthabrv: Sep'); |
87 |
locale => 'C', # locale set to 'C' to ensure we'll have english strings |
98 |
$seq = _next_seq($subscription, $pattern); |
88 |
}; |
99 |
is($seq, 'monthname: November | monthabrv: Nov'); |
89 |
my $pattern = { |
100 |
$seq = _next_seq($subscription, $pattern); |
90 |
add1 => 2, add2 => 2, add3 => 0, |
101 |
is($seq, 'monthname: January | monthabrv: Jan'); |
91 |
every1 => 1, every2 => 1, every3 => 0, |
102 |
$seq = _next_seq($subscription, $pattern); |
92 |
whenmorethan1 => 11, whenmorethan2 => 11, whenmorethan3 => 0, |
103 |
is($seq, 'monthname: March | monthabrv: Mar'); |
93 |
setto1 => 0, setto2 => 0, setto3 => 0, |
|
|
94 |
numberingmethod => 'monthname: {X} | monthabrv: {Y}', |
95 |
numbering1 => 'monthname', |
96 |
numbering2 => 'monthabrv', |
97 |
numbering3 => '', |
98 |
}; |
104 |
|
99 |
|
105 |
# TEST CASE 4 - 1 variable, use 'season' numbering, from 0 to 3 |
100 |
my $seq = _next_seq( $subscription, $pattern ); |
106 |
# Months starts at 0, this implies subscription's lastvalue1 should be 0, |
101 |
is( $seq, 'monthname: March | monthabrv: Mar', "Next month (3) is correctly generated when adding 2" ); |
107 |
# together with setto1 and whenmorethan1 should be 11 |
102 |
$seq = _next_seq( $subscription, $pattern ); |
108 |
$subscription = { |
103 |
is( $seq, 'monthname: May | monthabrv: May', "Next month (5) is correctly generated when adding 2" ); |
109 |
lastvalue1 => 0, lastvalue2 => 0, lastvalue3 => 0, |
104 |
$seq = _next_seq( $subscription, $pattern ); |
110 |
innerloop1 => 0, innerloop2 => 0, innerloop3 => 0, |
105 |
is( $seq, 'monthname: July | monthabrv: Jul', "Next month (7) is correctly generated when adding 2" ); |
111 |
skip_serialseq => 0, |
106 |
$seq = _next_seq( $subscription, $pattern ); |
112 |
irregularity => '', |
107 |
is( $seq, 'monthname: September | monthabrv: Sep', "Next month (9) is correctly generated when adding 2" ); |
113 |
locale => 'C', # locale set to 'C' to ensure we'll have english strings |
108 |
$seq = _next_seq( $subscription, $pattern ); |
114 |
}; |
109 |
is( $seq, 'monthname: November | monthabrv: Nov', "Next month (11) is correctly generated when adding 2" ); |
115 |
$pattern = { |
110 |
$seq = _next_seq( $subscription, $pattern ); |
116 |
add1 => 1, add2 => 1, add3 => 0, |
111 |
is( $seq, 'monthname: January | monthabrv: Jan', "Next month (1) is correctly reset and generated when adding 2" ); |
117 |
every1 => 1, every2 => 1, every3 => 0, |
112 |
$seq = _next_seq( $subscription, $pattern ); |
118 |
whenmorethan1 => 3, whenmorethan2 => 3, whenmorethan3 => 0, |
113 |
is( $seq, 'monthname: March | monthabrv: Mar', "Next month (3) is correctly generated when adding 2" ); |
119 |
setto1 => 0, setto2 => 0, setto3 => 0, |
|
|
120 |
numberingmethod => 'season: {X} | seasonabrv: {Y}', |
121 |
numbering1 => 'season', |
122 |
numbering2 => 'seasonabrv', |
123 |
numbering3 => '', |
124 |
}; |
114 |
}; |
125 |
|
115 |
|
126 |
$seq = _next_seq($subscription, $pattern); |
116 |
subtest "TEST CASE 4 - 1 variable, use 'season' numbering, from 0 to 3" => sub { |
127 |
is($seq, 'season: Summer | seasonabrv: Sum'); |
117 |
plan tests => 5; |
128 |
$seq = _next_seq($subscription, $pattern); |
|
|
129 |
is($seq, 'season: Fall | seasonabrv: Fal'); |
130 |
$seq = _next_seq($subscription, $pattern); |
131 |
is($seq, 'season: Winter | seasonabrv: Win'); |
132 |
$seq = _next_seq($subscription, $pattern); |
133 |
is($seq, 'season: Spring | seasonabrv: Spr'); |
134 |
$seq = _next_seq($subscription, $pattern); |
135 |
is($seq, 'season: Summer | seasonabrv: Sum'); |
136 |
|
118 |
|
137 |
# TEST CASE 5 - 2 variables, from 1 to 12, and from 1 to 4 |
119 |
# Months starts at 0, this implies subscription's lastvalue1 should be 0, |
138 |
$subscription = { |
120 |
# together with setto1 and whenmorethan1 should be 11 |
139 |
lastvalue1 => 1, lastvalue2 => 1, lastvalue3 => 1, |
121 |
my $subscription = { |
140 |
innerloop1 => 0, innerloop2 => 0, innerloop3 => 0, |
122 |
lastvalue1 => 0, lastvalue2 => 0, lastvalue3 => 0, |
141 |
skip_serialseq => 0, |
123 |
innerloop1 => 0, innerloop2 => 0, innerloop3 => 0, |
142 |
irregularity => '', |
124 |
skip_serialseq => 0, |
143 |
locale => 'C', # locale set to 'C' to ensure we'll have english strings |
125 |
irregularity => '', |
144 |
}; |
126 |
locale => 'C', # locale set to 'C' to ensure we'll have english strings |
145 |
$pattern = { |
127 |
}; |
146 |
add1 => 1, add2 => 1, add3 => 0, |
128 |
my $pattern = { |
147 |
every1 => 1, every2 => 4, every3 => 0, |
129 |
add1 => 1, add2 => 1, add3 => 0, |
148 |
whenmorethan1 => 4, whenmorethan2 => 12, whenmorethan3 => 0, |
130 |
every1 => 1, every2 => 1, every3 => 0, |
149 |
setto1 => 1, setto2 => 1, setto3 => 0, |
131 |
whenmorethan1 => 3, whenmorethan2 => 3, whenmorethan3 => 0, |
150 |
numberingmethod => 'Y: {Y}, X: {X}', |
132 |
setto1 => 0, setto2 => 0, setto3 => 0, |
151 |
numbering1 => '', |
133 |
numberingmethod => 'season: {X} | seasonabrv: {Y}', |
152 |
numbering2 => '', |
134 |
numbering1 => 'season', |
153 |
numbering3 => '', |
135 |
numbering2 => 'seasonabrv', |
|
|
136 |
numbering3 => '', |
137 |
}; |
138 |
|
139 |
my $seq = _next_seq( $subscription, $pattern ); |
140 |
is( $seq, 'season: Summer | seasonabrv: Sum', "Next season (Summer) is correctly generated" ); |
141 |
$seq = _next_seq( $subscription, $pattern ); |
142 |
is( $seq, 'season: Fall | seasonabrv: Fal', "Next season (Fall) is correctly generated" ); |
143 |
$seq = _next_seq( $subscription, $pattern ); |
144 |
is( $seq, 'season: Winter | seasonabrv: Win', "Next season (Winter) is correctly generated" ); |
145 |
$seq = _next_seq( $subscription, $pattern ); |
146 |
is( $seq, 'season: Spring | seasonabrv: Spr', "Next season (Spring) is correctly reset and generated" ); |
147 |
$seq = _next_seq( $subscription, $pattern ); |
148 |
is( $seq, 'season: Summer | seasonabrv: Sum', "Next season (Summer) is correctly generated" ); |
154 |
}; |
149 |
}; |
155 |
|
150 |
|
156 |
$seq = _next_seq($subscription, $pattern); |
151 |
subtest "TEST CASE 5 - 2 variables, from 1 to 12, and from 1 to 4" => sub { |
157 |
is($seq, 'Y: 1, X: 2'); |
152 |
plan tests => 9; |
158 |
$seq = _next_seq($subscription, $pattern); |
153 |
my $subscription = { |
159 |
is($seq, 'Y: 1, X: 3'); |
154 |
lastvalue1 => 1, lastvalue2 => 1, lastvalue3 => 1, |
160 |
$seq = _next_seq($subscription, $pattern); |
155 |
innerloop1 => 0, innerloop2 => 0, innerloop3 => 0, |
161 |
is($seq, 'Y: 1, X: 4'); |
156 |
skip_serialseq => 0, |
162 |
$seq = _next_seq($subscription, $pattern); |
157 |
irregularity => '', |
163 |
is($seq, 'Y: 2, X: 1'); |
158 |
locale => 'C', # locale set to 'C' to ensure we'll have english strings |
164 |
$seq = _next_seq($subscription, $pattern); |
159 |
}; |
165 |
is($seq, 'Y: 2, X: 2'); |
160 |
my $pattern = { |
166 |
# Back to the future |
161 |
add1 => 1, add2 => 1, add3 => 0, |
167 |
for (1..39) { |
162 |
every1 => 1, every2 => 4, every3 => 0, |
168 |
$seq = _next_seq($subscription, $pattern); |
163 |
whenmorethan1 => 4, whenmorethan2 => 12, whenmorethan3 => 0, |
169 |
} |
164 |
setto1 => 1, setto2 => 1, setto3 => 0, |
170 |
$seq = _next_seq($subscription, $pattern); |
165 |
numberingmethod => 'Y: {Y}, X: {X}', |
171 |
is($seq, 'Y: 12, X: 2'); |
166 |
numbering1 => '', |
172 |
$seq = _next_seq($subscription, $pattern); |
167 |
numbering2 => '', |
173 |
is($seq, 'Y: 12, X: 3'); |
168 |
numbering3 => '', |
174 |
$seq = _next_seq($subscription, $pattern); |
169 |
}; |
175 |
is($seq, 'Y: 12, X: 4'); |
|
|
176 |
$seq = _next_seq($subscription, $pattern); |
177 |
is($seq, 'Y: 1, X: 1'); |
178 |
|
170 |
|
179 |
# TEST CASE 6 - 3 variables, from 1 to 12, from 1 to 8, and from 1 to 4 |
171 |
my $seq = _next_seq( $subscription, $pattern ); |
180 |
$subscription = { |
172 |
is( $seq, 'Y: 1, X: 2', "X increased to 2" ); |
181 |
lastvalue1 => 1, lastvalue2 => 1, lastvalue3 => 1, |
173 |
$seq = _next_seq( $subscription, $pattern ); |
182 |
innerloop1 => 0, innerloop2 => 0, innerloop3 => 0, |
174 |
is( $seq, 'Y: 1, X: 3', "X increased to 3" ); |
183 |
skip_serialseq => 0, |
175 |
$seq = _next_seq( $subscription, $pattern ); |
184 |
irregularity => '', |
176 |
is( $seq, 'Y: 1, X: 4', "X increased to 4" ); |
185 |
locale => 'C', # locale set to 'C' to ensure we'll have english strings |
177 |
$seq = _next_seq( $subscription, $pattern ); |
186 |
}; |
178 |
is( $seq, 'Y: 2, X: 1', "X increased and reset to 1" ); |
187 |
$pattern = { |
179 |
$seq = _next_seq( $subscription, $pattern ); |
188 |
add1 => 1, add2 => 1, add3 => 1, |
180 |
is( $seq, 'Y: 2, X: 2', "X increased to 2" ); |
189 |
every1 => 1, every2 => 4, every3 => 32, |
181 |
|
190 |
whenmorethan1 => 4, whenmorethan2 => 8, whenmorethan3 => 12, |
182 |
# Back to the future |
191 |
setto1 => 1, setto2 => 1, setto3 => 1, |
183 |
for ( 1 .. 39 ) { |
192 |
numberingmethod => 'Z: {Z}, Y: {Y}, X: {X}', |
184 |
$seq = _next_seq( $subscription, $pattern ); |
193 |
numbering1 => '', |
185 |
} |
194 |
numbering2 => '', |
186 |
$seq = _next_seq( $subscription, $pattern ); |
195 |
numbering3 => '', |
187 |
is( $seq, 'Y: 12, X: 2', "Skipping ahead, Y has incremented to 12, X increased to 2" ); |
|
|
188 |
$seq = _next_seq( $subscription, $pattern ); |
189 |
is( $seq, 'Y: 12, X: 3', "X increased to 3" ); |
190 |
$seq = _next_seq( $subscription, $pattern ); |
191 |
is( $seq, 'Y: 12, X: 4', "X increased to 4" ); |
192 |
$seq = _next_seq( $subscription, $pattern ); |
193 |
is( $seq, 'Y: 1, X: 1', "Y resets after 12, X increased and reset to 1" ); |
196 |
}; |
194 |
}; |
197 |
|
195 |
|
198 |
$seq = _next_seq($subscription, $pattern); |
196 |
subtest "TEST CASE 6 - 3 variables, from 1 to 12, from 1 to 8, and from 1 to 4" => sub { |
199 |
is($seq, 'Z: 1, Y: 1, X: 2'); |
197 |
plan tests => 10; |
200 |
$seq = _next_seq($subscription, $pattern); |
198 |
my $subscription = { |
201 |
is($seq, 'Z: 1, Y: 1, X: 3'); |
199 |
lastvalue1 => 1, lastvalue2 => 1, lastvalue3 => 1, |
202 |
$seq = _next_seq($subscription, $pattern); |
200 |
innerloop1 => 0, innerloop2 => 0, innerloop3 => 0, |
203 |
is($seq, 'Z: 1, Y: 1, X: 4'); |
201 |
skip_serialseq => 0, |
204 |
$seq = _next_seq($subscription, $pattern); |
202 |
irregularity => '', |
205 |
is($seq, 'Z: 1, Y: 2, X: 1'); |
203 |
locale => 'C', # locale set to 'C' to ensure we'll have english strings |
206 |
for (1..24) { |
204 |
}; |
207 |
$seq = _next_seq($subscription, $pattern); |
205 |
my $pattern = { |
208 |
} |
206 |
add1 => 1, add2 => 1, add3 => 1, |
209 |
$seq = _next_seq($subscription, $pattern); |
207 |
every1 => 1, every2 => 4, every3 => 32, |
210 |
is($seq, 'Z: 1, Y: 8, X: 2'); |
208 |
whenmorethan1 => 4, whenmorethan2 => 8, whenmorethan3 => 12, |
211 |
$seq = _next_seq($subscription, $pattern); |
209 |
setto1 => 1, setto2 => 1, setto3 => 1, |
212 |
is($seq, 'Z: 1, Y: 8, X: 3'); |
210 |
numberingmethod => 'Z: {Z}, Y: {Y}, X: {X}', |
213 |
$seq = _next_seq($subscription, $pattern); |
211 |
numbering1 => '', |
214 |
is($seq, 'Z: 1, Y: 8, X: 4'); |
212 |
numbering2 => '', |
215 |
$seq = _next_seq($subscription, $pattern); |
213 |
numbering3 => '', |
216 |
is($seq, 'Z: 2, Y: 1, X: 1'); |
214 |
}; |
217 |
for (1..350) { |
215 |
|
218 |
$seq = _next_seq($subscription, $pattern); |
216 |
my $seq = _next_seq( $subscription, $pattern ); |
219 |
} |
217 |
is( $seq, 'Z: 1, Y: 1, X: 2', "X increased by one, now 2" ); |
220 |
$seq = _next_seq($subscription, $pattern); |
218 |
$seq = _next_seq( $subscription, $pattern ); |
221 |
is($seq, 'Z: 12, Y: 8, X: 4'); |
219 |
is( $seq, 'Z: 1, Y: 1, X: 3', "X increased by one, now 3" ); |
222 |
$seq = _next_seq($subscription, $pattern); |
220 |
$seq = _next_seq( $subscription, $pattern ); |
223 |
is($seq, 'Z: 1, Y: 1, X: 1'); |
221 |
is( $seq, 'Z: 1, Y: 1, X: 4', "X increased by one, now 4" ); |
|
|
222 |
$seq = _next_seq( $subscription, $pattern ); |
223 |
is( $seq, 'Z: 1, Y: 2, X: 1', "X increased by one, now 1, Y increased by 1, now 2" ); |
224 |
|
224 |
|
225 |
# TEST CASE 7 . Specify how many issues to count forward, 1 variable, from 1 to 4 |
225 |
for ( 1 .. 24 ) { |
|
|
226 |
$seq = _next_seq( $subscription, $pattern ); |
227 |
} |
228 |
$seq = _next_seq( $subscription, $pattern ); |
229 |
is( $seq, 'Z: 1, Y: 8, X: 2', "Skipped to Z1, Y8, X2, X increased by one, now 2" ); |
230 |
$seq = _next_seq( $subscription, $pattern ); |
231 |
is( $seq, 'Z: 1, Y: 8, X: 3', "X increased by one, now 3" ); |
232 |
$seq = _next_seq( $subscription, $pattern ); |
233 |
is( $seq, 'Z: 1, Y: 8, X: 4', "X increased by one, now 4" ); |
234 |
$seq = _next_seq( $subscription, $pattern ); |
235 |
is( |
236 |
$seq, 'Z: 2, Y: 1, X: 1', |
237 |
"X increased by one and reset, now 1. Y increased by 1 and reset, now 1. Z increased by one, now 2" |
238 |
); |
226 |
|
239 |
|
227 |
$subscription = { |
240 |
for ( 1 .. 350 ) { |
228 |
lastvalue1 => 1, lastvalue2 => 1, lastvalue3 => 1, |
241 |
$seq = _next_seq( $subscription, $pattern ); |
229 |
innerloop1 => 0, innerloop2 => 0, innerloop3 => 0, |
242 |
} |
230 |
skip_serialseq => 0, |
243 |
$seq = _next_seq( $subscription, $pattern ); |
231 |
irregularity => '', |
244 |
is( $seq, 'Z: 12, Y: 8, X: 4', "Skipped to Z12, Y8, X4, X increased by one, now 4" ); |
232 |
locale => 'en', |
245 |
$seq = _next_seq( $subscription, $pattern ); |
|
|
246 |
is( |
247 |
$seq, 'Z: 1, Y: 1, X: 1', |
248 |
"X increased by one and reset, now 1. Y increased by 1 and reset, now 1. Z increased by one and reset, now 1" |
249 |
); |
233 |
}; |
250 |
}; |
234 |
$pattern = { |
251 |
|
235 |
add1 => 1, add2 => 0, add3 => 0, |
252 |
subtest "TEST CASE 7 . Specify how many issues to count forward, 1 variable, from 1 to 4" => sub { |
236 |
every1 => 1, every2 => 0, every3 => 0, |
253 |
plan tests => 3; |
237 |
whenmorethan1 => 4, whenmorethan2 => 0, whenmorethan3 => 0, |
254 |
|
238 |
setto1 => 1, setto2 => 0, setto3 => 0, |
255 |
my $subscription = { |
239 |
numberingmethod => 'X: {X}', |
256 |
lastvalue1 => 1, lastvalue2 => 1, lastvalue3 => 1, |
240 |
numbering1 => '', |
257 |
innerloop1 => 0, innerloop2 => 0, innerloop3 => 0, |
241 |
numbering2 => '', |
258 |
skip_serialseq => 0, |
242 |
numbering3 => '', |
259 |
irregularity => '', |
|
|
260 |
locale => 'en', |
261 |
}; |
262 |
my $pattern = { |
263 |
add1 => 1, add2 => 0, add3 => 0, |
264 |
every1 => 1, every2 => 0, every3 => 0, |
265 |
whenmorethan1 => 4, whenmorethan2 => 0, whenmorethan3 => 0, |
266 |
setto1 => 1, setto2 => 0, setto3 => 0, |
267 |
numberingmethod => 'X: {X}', |
268 |
numbering1 => '', |
269 |
numbering2 => '', |
270 |
numbering3 => '', |
271 |
}; |
272 |
my $seq = _next_seq( $subscription, $pattern, 1 ); |
273 |
is( $seq, 'X: 2', "When counting forward 1, X increased by one" ); |
274 |
$seq = _next_seq( $subscription, $pattern, 2 ); |
275 |
is( $seq, 'X: 4', "When counting forward 2, X increased by 2" ); |
276 |
$seq = _next_seq( $subscription, $pattern, 2 ); |
277 |
is( $seq, 'X: 2', "When counting forward 2, X correctly reset and counted forward by 2" ); |
243 |
}; |
278 |
}; |
244 |
$seq = _next_seq($subscription, $pattern, 1); |
|
|
245 |
is($seq, 'X: 2'); |
246 |
$seq = _next_seq($subscription, $pattern, 2); |
247 |
is($seq, 'X: 4'); |
248 |
$seq = _next_seq($subscription, $pattern, 2); |
249 |
is($seq, 'X: 2'); |
250 |
|
279 |
|
251 |
sub _next_seq { |
280 |
sub _next_seq { |
252 |
my ($subscription, $pattern, $count_forward) = @_; |
281 |
my ( $subscription, $pattern, $count_forward ) = @_; |
253 |
my $seq; |
282 |
my $seq; |
254 |
($seq, $subscription->{lastvalue1}, $subscription->{lastvalue2}, |
283 |
( |
|
|
284 |
$seq, $subscription->{lastvalue1}, $subscription->{lastvalue2}, |
255 |
$subscription->{lastvalue3}, $subscription->{innerloop1}, |
285 |
$subscription->{lastvalue3}, $subscription->{innerloop1}, |
256 |
$subscription->{innerloop2}, $subscription->{innerloop3}) = |
286 |
$subscription->{innerloop2}, $subscription->{innerloop3} |
257 |
GetNextSeq($subscription, $pattern, undef, undef, $count_forward); |
287 |
) = GetNextSeq( $subscription, $pattern, undef, undef, undef, $count_forward ); |
258 |
return $seq; |
288 |
return $seq; |
259 |
} |
289 |
} |
260 |
- |
|
|