3 # This Koha test module is a stub!
4 # Add more tests here!!!
9 use Test
::More tests
=> 32;
17 my $tags = \
@tagsarray;
18 my ($min, $max) = C4
::Tags
::stratify_tags
(0, $tags);
19 is
($min, 0, 'Empty array min');
20 is
($max, 0, 'Empty array max');
22 # Simple 'sequential 5' test
23 $tags = make_tags
(1,2,3,4,5);
24 my @strata = (0,1,2,3,4);
25 ($min, $max) = C4
::Tags
::stratify_tags
(5, $tags);
26 check_tag_strata
($tags, \
@strata, 'Sequential 5');
27 is
($min, 0, 'Sequential 5 min');
28 is
($max, 4, 'Sequential 5 max');
30 # Reverse test - should have the same results as previous
31 $tags = make_tags
(5,4,3,2,1);
32 @strata = (4,3,2,1,0);
33 ($min, $max) = C4
::Tags
::stratify_tags
(5, $tags);
34 check_tag_strata
($tags, \
@strata, 'Reverse Sequential 5');
35 is
($min, 0, 'Sequential 5 min');
36 is
($max, 4, 'Sequential 5 max');
38 # All the same test - should all have the same results
39 $tags = make_tags
(4,4,4,4,4);
40 @strata = (0,0,0,0,0);
41 ($min, $max) = C4
::Tags
::stratify_tags
(5, $tags);
42 check_tag_strata
($tags, \
@strata, 'All The Same');
43 is
($min, 0, 'Sequential 5 min');
44 is
($max, 0, 'Sequential 5 max');
46 # Some the same, some different
47 $tags = make_tags
(1,2,2,3,3,8);
48 @strata = (0,0,0,1,1,4);
49 ($min, $max) = C4
::Tags
::stratify_tags
(5, $tags);
50 check_tag_strata
($tags, \
@strata, 'All The Same');
51 is
($min, 0, 'Sequential 5 min');
52 is
($max, 7, 'Sequential 5 max');
54 # Runs tests against the results
55 sub check_tag_strata
{
56 my ($tags, $expected, $name) = @_;
58 foreach my $t (@
$tags) {
59 my $w = $t->{weight_total
};
60 my $s = $t->{stratum
};
61 is
($s, shift @
$expected, $name . " - $w ($s)");
65 # Makes some tags with just enough info to test
69 push @res, { weight_total
=> shift @_ };