Skip to content

Instantly share code, notes, and snippets.

@wchristian
Created November 6, 2010 15:19
Show Gist options
  • Save wchristian/665481 to your computer and use it in GitHub Desktop.
Save wchristian/665481 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
package avg_size_calculation;
BEGIN {
use Cwd;
chdir '..' if getcwd =~ m@/t$@;
use lib '../lib';
}
use Test::Most;
use lib 'lib';
use TFX::DownloadTOFiles::File;
test_avg_size_calculation();
done_testing;
exit;
sub test_avg_size_calculation {
my @get;
no warnings 'redefine';
local *TFX::DownloadTOFiles::File::_get_size_tail_from_db = sub { @get };
my $file = TFX::DownloadTOFiles::File->new( { db => { expected_size => 2 } } );
@get = qw();
is( $file->compute_average_size_of_tail, 2, 'average size with no previous sizes returns the expected size' );
@get = qw( 5 5 5 5 5 );
is( $file->compute_average_size_of_tail, 2, 'average size with too few previous sizes returns the expected size' );
@get = qw( 5 5 5 5 5 5 );
is( $file->compute_average_size_of_tail, 5, 'average size with enough previous sizes returns the average' );
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment