From e8a3bf7cd17b181904dcc324099c555e7c5cc518 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 6 Dec 2017 13:03:15 -0300 Subject: [PATCH] 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 Signed-off-by: Marcel de Rooy 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 Signed-off-by: Nick Clemens --- t/db_dependent/TestBuilder.t | 5 ++++- t/lib/TestBuilder.pm | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/TestBuilder.t b/t/db_dependent/TestBuilder.t index 1a2c2fda3c..5ee0a6a40b 100644 --- a/t/db_dependent/TestBuilder.t +++ b/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" ); }; diff --git a/t/lib/TestBuilder.pm b/t/lib/TestBuilder.pm index 4ec6dba574..d42cb03346 100644 --- a/t/lib/TestBuilder.pm +++ b/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 { -- 2.39.5