Browse Source

Bug 19759: Make TestBuilder generates only 2 decimals for float

For instance items.replacementprice is decimal(8,2) but more than 2 decimals are generated.

It leads to issues when we compare expected objects:

    #          got: '135623.866142537'
    #     expected: '135623.87'

Test plan:
  prove t/db_dependent/TestBuilder.t
must return green

Signed-off-by: Dominic Pichette <dominic@inlibro.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Somehow I have the feeling that we should allow more decimals sometimes
and perhaps have a number of decimals parameter or so. Think of fields
like currency or discount.
But the current issues justify this change.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
18.05.x
Jonathan Druart 6 years ago
parent
commit
54d13ca4af
  1. 5
      t/db_dependent/TestBuilder.t
  2. 2
      t/lib/TestBuilder.pm

5
t/db_dependent/TestBuilder.t

@ -85,7 +85,7 @@ subtest 'Build all sources' => sub {
subtest 'Test length of some generated fields' => sub {
plan tests => 2;
plan tests => 3;
# Test the length of a returned character field
my $bookseller = $builder->build({ source => 'Aqbookseller' });
@ -94,6 +94,9 @@ subtest 'Test length of some generated fields' => sub {
'The length for a generated string (phone) should not be zero' );
is( length( $bookseller->{phone} ) <= $max, 1,
'Check maximum length for a generated string (phone)' );
my $item = $builder->build({ source => 'Item' });
is( $item->{replacementprice}, sprintf("%.2f", $item->{replacementprice}), "The number of decimals for floats should not be more than 2" );
};

2
t/lib/TestBuilder.pm

@ -417,7 +417,7 @@ sub _gen_real {
if( defined( $params->{info}->{size} ) ) {
$max = 10 ** ($params->{info}->{size}->[0] - $params->{info}->{size}->[1]);
}
return rand($max) + 1;
return sprintf("%.2f", rand($max)+1);
}
sub _gen_date {

Loading…
Cancel
Save