Bug 9259: Use is instead of is_deeply
[koha.git] / t / db_dependent / Tags.t
1 #!/usr/bin/perl
2 #
3 # This Koha test module is a stub!  
4 # Add more tests here!!!
5
6 use strict;
7 use warnings;
8
9 use Test::More tests => 32;
10
11 BEGIN {
12         use_ok('C4::Tags');
13 }
14
15 # Check no tags case.
16 my @tagsarray;
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');
21
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');
29
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');
37
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');
45
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');
53
54 # Runs tests against the results
55 sub check_tag_strata {
56     my ($tags, $expected, $name) = @_;
57
58     foreach my $t (@$tags) {
59         my $w = $t->{weight_total};
60         my $s = $t->{stratum};
61         is($s, shift @$expected, $name . " - $w ($s)");
62     }
63 }
64
65 # Makes some tags with just enough info to test
66 sub make_tags {
67     my @res;
68     while (@_) {
69         push @res, { weight_total => shift @_ };
70     }
71     return \@res;
72 }