Skip to content

Commit

Permalink
Merge pull request #15 from pranavacharya/metre-unit-support
Browse files Browse the repository at this point in the history
added support for metre unit
  • Loading branch information
pranavacharya authored Aug 13, 2020
2 parents 16e9a61 + 68eeeb7 commit 25082f6
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ pace.format('km', 'min').getPaceTimeString(); // 00:06:00

##### Distance

- m - metre
- km - kilometers
- mi - miles

Expand Down
4 changes: 4 additions & 0 deletions src/lib/distance.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
const units = {
m: {
ratio: 0.001,
name: 'metre'
},
mi: {
ratio: 1.60934,
name: 'miles'
Expand Down
3 changes: 2 additions & 1 deletion src/lib/pace.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class Pace {
* @param {Object} [optional] - optional params
* @param {String} [optional.distanceUnit] - unit of distance
* - default unit: km
* - available units: "km", "mi"
* - available units: "m", "km", "mi"
* @param {String} [optional.timeUnit] - unit of time
* - default unit: s
* - available units: "ms", "s", "min" , "h"
Expand Down Expand Up @@ -71,6 +71,7 @@ export default class Pace {
* - default unit - s/km
* @param {string} distanceUnit
* Available units
* - m
* - km
* - mi
* @param {string} timeUnit
Expand Down
8 changes: 6 additions & 2 deletions tests/distance.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ import { listUnit, convertUnit } from '../src/lib/distance';
describe('Distance', () => {
test('list units', () => {
expect(typeof listUnit()).toBe('object');
expect(listUnit()).toEqual(['mi', 'km']);
expect(listUnit()).toEqual(['m', 'mi', 'km']);
});

test('convertUnit', () => {
test('convertUnit - km to mi', () => {
expect(convertUnit(10, 'km', 'mi')).toBeCloseTo(6.2, 1);
});

test('convertUnit - km to m', () => {
expect(convertUnit(10, 'km', 'm')).toBe(10000);
});
});
2 changes: 1 addition & 1 deletion tests/pacecal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('Pace Class', () => {
expect(() => {
// invalid distanceUnit
// eslint-disable-next-line no-unused-vars
const pace = new Pace(6, 3600, { distanceUnit: 'm', timeUnit: 'min' });
const pace = new Pace(6, 3600, { distanceUnit: 'yard', timeUnit: 'min' });
}).toThrow(TypeError);
});

Expand Down

0 comments on commit 25082f6

Please sign in to comment.