-
Notifications
You must be signed in to change notification settings - Fork 0
Pull Request for peer review #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 15 commits
d03eaec
aee1c1a
3700ef6
df12b74
4f60e10
532e8ac
d3f1837
c759871
d36cd89
4d2a824
cc1d6d4
741c47e
816e73b
d35e282
d2ade4d
620a020
20a1e60
63f7b74
a448fd7
502afb9
77ba367
226e490
bb870c8
3693d9c
f440817
c6c7d88
de2d505
b8b0720
c128075
7011454
0fd96e3
435916b
b10f134
6fca590
d586adf
c3dc52b
cc14b1e
3ed238c
8414503
dd07287
f669ede
9e83c02
b505061
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| engines: | ||
| eslint: | ||
| enabled: true | ||
| duplication: | ||
| enabled: true | ||
| config: | ||
| languages: | ||
| - javascript | ||
| csslint: | ||
| enabled: false | ||
| # ... CONFIG CONTENT ... | ||
| checks: | ||
| comma-dangle: | ||
| enabled: false | ||
| import/no-unresolved: | ||
| enabled: false | ||
| no-console: | ||
| enabled: false | ||
| strict: | ||
| enabled: false | ||
| no-unused-vars: | ||
| enabled: false | ||
| no-undef: | ||
| enabled: false | ||
| class-methods-use-this: | ||
| enabled: false | ||
| no-param-reassign: | ||
| enabled: false | ||
| array-callback-return: | ||
| enabled: false | ||
| fixme: | ||
| enabled: true | ||
| ratings: | ||
| paths: | ||
| - "src/invertedindex.js" | ||
| exclude_paths: | ||
| - "samples/*" | ||
| - "*.json" | ||
| - "src/app.js" | ||
| - "src/module.js" | ||
| - "css/*" | ||
| - "index.html" | ||
| - "specs/*" | ||
| - .travis.yml | ||
| - .eslintrc.json | ||
| - "spec/*" | ||
| - "images/*" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
|
|
||
| describe('InvertedIndex class', () => { | ||
| beforeEach(() => { | ||
| beforeAll(() => { | ||
| this.indexInstance = new InvertedIndex(); | ||
| this.validBook = [{ title: 'Welcome to Test Environment', | ||
| text: 'Enjoy this file' }]; | ||
|
|
@@ -100,6 +100,10 @@ describe('InvertedIndex class', () => { | |
| const term = { t1: 'Welcome home', text: 'This is really home' }; | ||
| expect(this.indexInstance.createIndex(term, 'term')).toBeFalsy(); | ||
| }); | ||
| it('should return false for file with no content', () => { | ||
| const term = {}; | ||
| expect(this.indexInstance.createIndex(term, 'term')).toBeFalsy(); | ||
| }); | ||
| }); | ||
| describe('Search Index', () => { | ||
| it('should search through single files that are indexed', () => { | ||
|
|
@@ -118,6 +122,24 @@ describe('InvertedIndex class', () => { | |
| expect(this.indexInstance.searchIndex(term, 'books')) | ||
| .toBeFalsy(); | ||
| }); | ||
| it('should return an empty object for an words not found', () => { | ||
| const term = 'Aeroplane'; | ||
| const expectedOutput = this.indexInstance.searchIndex(term, 'books'); | ||
| expect(expectedOutput[0].indexes).toEqual({ }); | ||
| }); | ||
| it('should return an array of objects if filename is all', () => { | ||
| const books1 = [{title: 'Alice in Wonderland too', | ||
|
||
| text: 'Alice adventure in the wonderland was full of drama and action'}]; | ||
|
||
| this.indexInstance.createIndex(books, 'books'); | ||
| this.indexInstance.createIndex(books1, 'books1'); | ||
| const expectedOutput = [{ indexes: { alice: [0], wonderland: [0] }, | ||
| searchedFile: 'books', | ||
| documents: [0, 1, 2] }, | ||
| { indexes: { alice: [0], wonderland: [0] }, | ||
|
||
| searchedFile: 'books1', | ||
| documents: [0] }]; | ||
| expect(this.indexInstance.searchIndex('Alice Wonderland', 'all')).toEqual(expectedOutput); | ||
|
||
| }); | ||
| }); | ||
|
|
||
| describe('Tokenize words', () => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ let instance = null; | |
| /** | ||
| * @class InvertedIndex class | ||
| * Contains methods for InvertedIndex | ||
| * Only allows single instance of the object to be created | ||
| */ | ||
| class InvertedIndex { | ||
| /** | ||
|
|
@@ -72,7 +73,7 @@ class InvertedIndex { | |
| let documentNum = 0; | ||
| try { | ||
| if (Object.keys(inputData).length < 1) { | ||
| this.handleError(filename, 'File contains no document', true); | ||
| this.handleError(filename, 'File contains no document', true); | ||
|
||
| } | ||
| Object.keys(inputData).forEach((eachIndex) => { | ||
| if (!this.validateFile(inputData[eachIndex])) { | ||
|
|
@@ -84,6 +85,7 @@ class InvertedIndex { | |
| this.filesIndexed[filename].numOfDocs = documentNum; | ||
| this.filesIndexed[filename].index = this.constructIndex(words); | ||
| return true; | ||
|
|
||
|
||
| } catch (err) { | ||
| if (this.error.status) { | ||
| return false; | ||
|
|
@@ -178,7 +180,6 @@ class InvertedIndex { | |
| */ | ||
| searchIndex(searchTerm, filename) { | ||
| if ((typeof searchTerm === 'string' && searchTerm.trim() === '') || | ||
| (typeof searchTerm === 'object' && searchTerm.length === 0) || | ||
| searchTerm === undefined) { | ||
| return false; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multiple spaces found before 'this' no-multi-spaces