diff --git a/lib/ProductOpener/DataQualityFood.pm b/lib/ProductOpener/DataQualityFood.pm index 32bd04f641766..f0888b2f279bb 100644 --- a/lib/ProductOpener/DataQualityFood.pm +++ b/lib/ProductOpener/DataQualityFood.pm @@ -1341,7 +1341,9 @@ sub check_nutrition_data ($product_ref) { my $total_fiber = $soluble_fiber + $insoluble_fiber; - if ($total_fiber > $product_ref->{nutriments}{fiber_100g} + 0.001) { + # increased threshold from 0.001 to 0.01 (see issue #10491) + # make sure that floats stop after 2 decimals + if (sprintf("%.2f", $total_fiber) > sprintf("%.2f", $product_ref->{nutriments}{fiber_100g} + 0.01)) { push @{$product_ref->{data_quality_errors_tags}}, "en:nutrition-soluble-fiber-plus-insoluble-fiber-greater-than-fiber"; } diff --git a/tests/unit/dataqualityfood.t b/tests/unit/dataqualityfood.t index f21db9059377b..61038b68cc0e4 100644 --- a/tests/unit/dataqualityfood.t +++ b/tests/unit/dataqualityfood.t @@ -1983,4 +1983,38 @@ ok( 'insoluble-fiber_100g larger than fiber_100g' ) or diag Dumper $product_ref; +# Test case for sum fiber subnutriment comparison with fiber (0.01 difference should be fine) +$product_ref = { + nutriments => { + fiber_100g => 3.57, + 'soluble-fiber_100g' => 1.79, + 'insoluble-fiber_100g' => 1.79, + }, + data_quality_errors_tags => [], +}; + +ProductOpener::DataQuality::check_quality($product_ref); + +ok( + !has_tag($product_ref, 'data_quality_errors', 'en:nutrition-soluble-fiber-plus-insoluble-fiber-greater-than-fiber'), + 'insoluble-fiber_100g larger than fiber_100g' +) or diag Dumper $product_ref; + +# Test case for sum fiber subnutriment comparison with fiber (0.02 difference should be raise error) +$product_ref = { + nutriments => { + fiber_100g => 3.57, + 'soluble-fiber_100g' => 1.79, + 'insoluble-fiber_100g' => 1.80, + }, + data_quality_errors_tags => [], +}; + +ProductOpener::DataQuality::check_quality($product_ref); + +ok( + has_tag($product_ref, 'data_quality_errors', 'en:nutrition-soluble-fiber-plus-insoluble-fiber-greater-than-fiber'), + 'insoluble-fiber_100g larger than fiber_100g' +) or diag Dumper $product_ref; + done_testing();