This repository has been archived by the owner on May 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
tester
executable file
·91 lines (65 loc) · 3.01 KB
/
tester
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env perl
# Copyright (c) 2008 Yahoo! Inc. All rights reserved. The copyrights
# embodied in the content of this file are licensed by Yahoo! Inc.
# under the BSD (revised) open source license
use strict;
# Enable unicode output (microseconds units designator)
use utf8;
binmode(STDOUT, ":utf8");
use FindBin;
# Users can symlink this script and it will still add the correct locations to
# perls path using FindBin::RealBin, but to ensure compatibility with old perl
# we need to be a bit more clever
sub get_lib {
# Start with a sensible default
my $bin_path = $FindBin::Bin;
{
no warnings 'uninitialized';
my $real_path="$FindBin::RealBin"; #This may fail on Perl < 5.10
if ($real_path ne ''){ # if the value is set, we'll use it
$bin_path = $real_path;
}
}
return $bin_path;
}
use lib get_lib();
use MySQL_Script_Utils;
sub assert {
my( $name, $expected, $method ) = (shift, shift, shift);
my $result = $method->(@_);
if( $result ne $expected ) {
die "$name: Results mismatch: '$result' != '$expected'\n";
} else {
print "$name: pass\n";
}
}
# Test numbers
assert( 'one is the lonliest number', '1', \&format_number, 1, 0, 3 );
assert( 'one point oh', '1.0', \&format_number, 1, 1, 3 );
assert( 'five hundred', '500', \&format_number, 500, 0, 3 );
assert( 'one kay', '1k', \&format_number, 1000, 0, 3 );
assert( 'one zero zero zero', '1000', \&format_number, 1000, 0, 4 );
assert( 'round up to 1k', '1k', \&format_number, 501, 0, 2 );
assert( 'round down to 0k', '0k', \&format_number, 500, 0, 2 ); # sprintf rounds 0.5 down
assert( 'twelve k', '12k', \&format_number, 12300, 0, 4 );
assert( 'one twenty three k', '123k', \&format_number, 123000, 0, 4 );
assert( 'twelve m', '12m', \&format_number, 12300000, 0, 4 );
assert( 'twelve point three m', '12.3m', \&format_number, 12300000, 0, 5 );
# Test memory
assert( 'one bee', '1b', \&format_memory, 1, 0, 3 );
assert( 'one point nil', '1b', \&format_memory, 1, 1, 3 );
assert( 'one point oh', '1.0b', \&format_memory, 1, 1, 4 );
assert( 'five oh oh rounded down', '0K', \&format_memory, 500, 0, 3 );
assert( 'five fifty rounded up', '1K', \&format_memory, 550, 0, 3 );
assert( 'five fifty bee', '550b', \&format_memory, 550, 0, 4 );
assert( 'one kay', '1K', \&format_memory, 1000, 0, 3 );
assert( 'one zero zero zero bee', '1000b', \&format_memory, 1000, 0, 5 );
assert( 'one point oh kay', '1.0K', \&format_memory, 1000, 0, 4 );
assert( 'one oh oh one bee', '1001b', \&format_memory, 1001, 0, 5 );
assert( 'one poing oh kay', '1.0K', \&format_memory, 1001, 0, 4 );
assert( 'round up to one kay', '1K', \&format_memory, 550, 0, 2 );
assert( 'round down to 0K', '0K', \&format_memory, 500, 0, 2 ); # sprintf rounds 0.5 down
assert( 'twelve kay', '12K', \&format_memory, 12300, 0, 4 );
assert( 'one twenty three kay', '120K', \&format_memory, 123000, 0, 4 );
assert( 'twelve em', '12M', \&format_memory, 12300000, 0, 4 );
assert( 'eleven point seven em', '11.7M', \&format_memory, 12300000, 0, 5 );