Skip to content

Commit

Permalink
Remove unused code paths
Browse files Browse the repository at this point in the history
  • Loading branch information
jarydkrish committed Dec 4, 2017
1 parent eb90761 commit fa1dce8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/UnitsHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions test/UnitsHelper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fa1dce8

Please sign in to comment.