|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var mod = require('../../src/others/minkowski-distance.js'); |
| 4 | +var minkowskiDistance = mod.minkowskiDistance; |
| 5 | + |
| 6 | +describe('Minkowski Distance', function () { |
| 7 | + it('should return 1 with points (0, 1), (1, 1) in order 1.', function () { |
| 8 | + expect(minkowskiDistance([0, 1], [1, 1], 1)).toBe(1); |
| 9 | + }); |
| 10 | + it('should return 2 with points (0, 1), (1, 1) in order 2.', function () { |
| 11 | + expect(minkowskiDistance([0, 1], [1, 1], 2)).toBe(1); |
| 12 | + }); |
| 13 | + it('should return 2 with points (0, 1, 4), (1, 1, 6) in order Positive Infinity.', function () { |
| 14 | + expect(minkowskiDistance([0, 1, 4], [1, 1, 6], Number.POSITIVE_INFINITY)).toBe(2); |
| 15 | + }); |
| 16 | + it('should return 0 with points (0, 1, 4), (1, 1, 6) in order Negative Infinity.', function () { |
| 17 | + expect(minkowskiDistance([0, 1, 4], [1, 1, 6], Number.NEGATIVE_INFINITY)).toBe(0); |
| 18 | + }); |
| 19 | + it('should return 8.372966759705923 with points (0, 3, 4, 5), (7, 6, 3, -1) in order 3.', function () { |
| 20 | + expect(minkowskiDistance([0, 1, 4], [1, 1, 6], Number.NEGATIVE_INFINITY)).toBe(0); |
| 21 | + }); |
| 22 | + it('should throw when 2 points are not in equal length', function () { |
| 23 | + expect( function () { |
| 24 | + minkowskiDistance([1, 2], [1], 1) |
| 25 | + }).toThrow('2 points must have same array length'); |
| 26 | + }); |
| 27 | + it('should throw when p is not defined', function () { |
| 28 | + expect( function () { |
| 29 | + minkowskiDistance([1, 2], [1, 2]) |
| 30 | + }).toThrow('p must be a number'); |
| 31 | + }); |
| 32 | + it('should throw when p is not a number', function () { |
| 33 | + expect( function () { |
| 34 | + minkowskiDistance([1, 2], [1, 2], NaN) |
| 35 | + }).toThrow('p must be a number'); |
| 36 | + }); |
| 37 | + it('should throw when p is less than 1', function () { |
| 38 | + expect( function () { |
| 39 | + minkowskiDistance([1, 2], [1, 2], 0) |
| 40 | + }).toThrow('p less than 1 will violate triangle inequality'); |
| 41 | + }); |
| 42 | +}); |
0 commit comments