2018-08-19 13:17:59 +00:00
|
|
|
import { expect, tap } from '@pushrocks/tapbundle';
|
|
|
|
import * as smartfuzzy from '../ts/index';
|
|
|
|
|
|
|
|
let testSmartfuzzy: smartfuzzy.Smartfuzzy;
|
|
|
|
|
|
|
|
tap.test('should create an instance of Smartfuzzy', async () => {
|
|
|
|
testSmartfuzzy = new smartfuzzy.Smartfuzzy([
|
|
|
|
'Sony',
|
|
|
|
'Deutsche Bahn',
|
|
|
|
'Apple Inc.',
|
|
|
|
"Trader Joe's"
|
|
|
|
]);
|
|
|
|
expect(testSmartfuzzy).to.be.instanceof(smartfuzzy.Smartfuzzy);
|
|
|
|
});
|
|
|
|
|
|
|
|
tap.test('should compute a score', async () => {
|
2018-08-19 18:52:52 +00:00
|
|
|
const result = testSmartfuzzy.getChangeScoreForString('Apple');
|
|
|
|
console.log(result);
|
2018-08-19 13:17:59 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
tap.test('should get closest match', async () => {
|
2018-08-19 18:52:52 +00:00
|
|
|
const result = testSmartfuzzy.getClosestMatchForString('Apple');
|
|
|
|
console.log(result);
|
|
|
|
});
|
|
|
|
|
|
|
|
tap.test('should sort objects', async () => {
|
|
|
|
class Car {
|
|
|
|
constructor(public brand: string) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
let testObjectSorter: smartfuzzy.ObjectSorter<Car>;
|
|
|
|
|
|
|
|
testObjectSorter = new smartfuzzy.ObjectSorter([
|
|
|
|
new Car('BMW'),
|
|
|
|
new Car('Mercedes Benz'),
|
|
|
|
new Car('Volvo')
|
|
|
|
]);
|
|
|
|
|
|
|
|
const result = testObjectSorter.sort('Volvo', ['brand']);
|
|
|
|
console.log(result);
|
2018-08-19 13:17:59 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
tap.start();
|