From fa1dce83675367c87ac868093fb64c4cd7db092b Mon Sep 17 00:00:00 2001 From: Jaryd Krishnan Date: Mon, 4 Dec 2017 10:04:26 -0600 Subject: [PATCH] Remove unused code paths --- src/UnitsHelper.js | 8 ++------ test/UnitsHelper.test.js | 13 +++++++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/UnitsHelper.js b/src/UnitsHelper.js index 71bdcd9..11c1f11 100644 --- a/src/UnitsHelper.js +++ b/src/UnitsHelper.js @@ -88,18 +88,14 @@ export default class UnitsHelper { lbsPerGallon, ); const finalCalc = finalUnit.to(productUnit).toNumber(); - if (finalCalc > 0) { - totalPerUnit = product.price * finalCalc; - } + totalPerUnit = product.price * finalCalc; } else { // If all else fails, try to convert const lineItemInProductUnits = Math .unit(1, lineItemUnit) .to(productUnit) .toNumber(); - if (lineItemInProductUnits > 0) { - totalPerUnit = product.price * lineItemInProductUnits; - } + totalPerUnit = product.price * lineItemInProductUnits; } } catch (error) { totalPerUnit = product.price; diff --git a/test/UnitsHelper.test.js b/test/UnitsHelper.test.js index c830d04..f36aac4 100644 --- a/test/UnitsHelper.test.js +++ b/test/UnitsHelper.test.js @@ -79,6 +79,19 @@ describe('UnitsHelper', () => { expect(gallonsToTons.toNumber()).toBeCloseTo(1); }); + it('should convert liquids to solids based on the American assumption', () => { + const gallons = 8000; + const gallonsPerPound = 4; + const poundsPerGallon = 1 / gallonsPerPound; + const gallonsToTons = UnitsHelper.liquidToSolid( + gallons, + 'gallons', + 'tons', + poundsPerGallon, + ); + expect(gallonsToTons.toNumber()).toBeCloseTo(1); + }); + describe('isLiquid', () => { it('should correctly recognize a liquid product', () => { const liquidProduct = liquidProductInTons;