Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
update requested changes
  • Loading branch information
jettcalleja committed May 13, 2017
commit f789338a64744d5609b94b5c9d815a276ae06158
6 changes: 3 additions & 3 deletions src/others/minkowski-distance.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@
var i;

if (lx !== ly) {
throw '2 points must have same array length';
throw 'Both vectors should have same dimension';
}

if (isNaN(p)) {
throw 'p must be a number';
throw 'The order "p" must be a number';
}

if (p === Number.POSITIVE_INFINITY) {
return chebyshevDistance(x, y, lx, p, Math.max);
} else if (p === Number.NEGATIVE_INFINITY) {
return chebyshevDistance(x, y, lx, p, Math.min);
} else if (p < 1) {
throw 'p less than 1 will violate triangle inequality';
throw 'Order less than 1 will violate the triangle inequality';
} else {
d = 0;

Expand Down
12 changes: 6 additions & 6 deletions test/others/minkowski-distance.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@ describe('Minkowski Distance', function () {
expect(minkowskiDistance([0, 1, 4], [1, 1, 6], Number.NEGATIVE_INFINITY)).toBe(0);
});
it('should return 8.372966759705923 with points (0, 3, 4, 5), (7, 6, 3, -1) in order 3.', function () {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Description doesn't match the content.

expect(minkowskiDistance([0, 1, 4], [1, 1, 6], Number.NEGATIVE_INFINITY)).toBe(0);
expect(minkowskiDistance([0, 3, 4, 5], [7, 6, 3, -1], 3)).toBe(8.372966759705923);
});
it('should throw when 2 points are not in equal length', function () {
it('should throw when both vectors don\'t have same dimension', function () {
expect(function () {
minkowskiDistance([1, 2], [1], 1)
}).toThrow('2 points must have same array length');
}).toThrow('Both vectors should have same dimension');
});
it('should throw when p is not defined', function () {
expect(function () {
minkowskiDistance([1, 2], [1, 2])
}).toThrow('p must be a number');
}).toThrow('The order "p" must be a number');
});
it('should throw when p is not a number', function () {
expect(function () {
minkowskiDistance([1, 2], [1, 2], NaN)
}).toThrow('p must be a number');
}).toThrow('The order "p" must be a number');
});
it('should throw when p is less than 1', function () {
expect(function () {
minkowskiDistance([1, 2], [1, 2], 0)
}).toThrow('p less than 1 will violate triangle inequality');
}).toThrow('Order less than 1 will violate the triangle inequality');
});
});