[Feature] Add 'memorySearch' and 'memorySearchSync' for Nodejs

1) Add features.
2) Add unit tests.
3) Add benchmark.
This commit is contained in:
MaleDong
2018-07-31 15:48:05 +08:00
parent f4fba7db60
commit b9e9fcfd80
9 changed files with 4402 additions and 24 deletions

View File

@@ -0,0 +1,28 @@
// This test is used for tesing of exceptions
const IP2Region = require('../../ip2region');
describe('Constructor Test', () => {
let instance;
beforeAll(() => {
instance = new IP2Region({ dbPath: '../../data/ip2region.db' })
});
afterAll(() => {
instance.destroy();
});
test('IP invalid test', () => {
const invalidIps = ['255.234.233', '255.255.-1.255', null, undefined, '', 'x.255.y.200'];
for (const ip of invalidIps) {
expect(() => instance.btreeSearchSync(ip)).toThrow();
expect(() => instance.binarySearchSync(ip)).toThrow();
}
});
test('File Not Found test', () => {
expect(() => new IP2Region({ dbPath: 'A Bad File or Path Here' })).toThrow();
});
});