#!/usr/bin/perl
#
# eg13: slightly expanded test suite for the frequency utilities module..
#

use strict;
use warnings;
use Function::Parameters qw(:strict);
use Test::More;

my @freqtests = (               # array of (arrayref, expectedstring) pairs
        [1],        "1:1",
        [2],        "2:1",
        [1,2],      "1:1,2:1",
        [1,2,1],    "1:2,2:1",
        [1,2,1,2],  "1:2,2:2",
        [1,2,1,3],  "1:2,2:1,3:1",
);

plan tests => 1 + @freqtests/2; # how many tests?
use_ok( 'frequtils' );		# first test.. load module?

#
# my $str = as_string( %hash ):
#	Produce a predictable plain text form of a hash.
#	we've chosen comma separated key:value pairs,
#	sorted by key
#
fun as_string( %hash )
{
	my @k = sort keys %hash;
	return join( ",", map { "$_:$hash{$_}" } @k );
}


#foreach (arrayref,expectedstring) in @freqtests
while( (my $inputarray, my $expected, @freqtests ) = @freqtests )
{
	my $input  = join( ',', @$inputarray );
        my %freq   = build_freq_hash( @$inputarray );
        my $output = as_string( %freq );
        is( $output, $expected, "build_freq_hash($input)=$output" );
}
