-
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 36 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 |
|---|---|---|
|
|
@@ -11,4 +11,5 @@ spec/*.html | |
| *.html | ||
| karma.conf.js | ||
| Profile | ||
| build/ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,303 @@ | ||
| (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move the invocation into the parens that contain the function wrap-iife There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move the invocation into the parens that contain the function wrap-iife |
||
| module.exports=[ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Expected indentation of 2 spaces but found 0 indent |
||
| { | ||
| "title": "Alice in Wonderland", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Strings must use singlequote quotes |
||
| "text": "Alice falls into a rabbit hole and enters a world full of imagination." | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line 5 exceeds the maximum line length of 80 max-len |
||
| }, | ||
|
|
||
| { | ||
| "title": "The Lord of the Rings: The Fellowship of the Ring.", | ||
| "text": "An unusual alliance of man, elf, dwarf, wizard and hobbit seek to destroy a powerful ring." | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line 10 exceeds the maximum line length of 80 max-len |
||
| } | ||
| ] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing semicolon semi |
||
|
|
||
| },{}],2:[function(require,module,exports){ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Block must not be padded by blank lines padded-blocks |
||
| const validBookFile = require('../samples/books.json'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Expected indentation of 2 spaces but found 0 indent |
||
|
|
||
| describe('InvertedIndex class', () => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Expected indentation of 2 spaces but found 0 indent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Expected indentation of 2 spaces but found 0 indent |
||
| beforeAll(() => { | ||
| const indexInstance = new InvertedIndex(); | ||
| const validBook = [{ title: 'Welcome to Test Environment', | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'validBook' is assigned a value but never used no-unused-vars |
||
| text: 'Enjoy this file' }]; | ||
| const books = [ | ||
| { | ||
| title: 'Alice in Wonderland', | ||
| text: | ||
| 'Alice falls into a rabbit hole and enters a world full of imagination.' | ||
| }, | ||
|
|
||
| { | ||
| title: 'The Lord of the Rings: The Fellowship of the Ring.', | ||
| text: `An unusual alliance of man, elf, dwarf, | ||
| wizard and hobbit seek to destroy a powerful ring.` | ||
| }, | ||
| { | ||
| title: 'The Lord of the Rings: The Fellowship of the Ring.', | ||
| text: `An unusual alliance of man, elf, dwarf, | ||
| wizard and hobbit seek to destroy a powerful ring.` | ||
| } | ||
| ]; | ||
| const anotherBook = [{ | ||
| title: 'Alice the Great', | ||
| text: | ||
| 'There is no better way to greatness than not giving up' | ||
| }, | ||
|
|
||
| { | ||
| title: 'Are you there for Development', | ||
| text: `I have tried so many times but it's been unyielding | ||
| but I have made up my mind to develop no matter the obstacle` | ||
| }]; | ||
| indexInstance.createIndex(books, 'books'); | ||
| indexInstance.createIndex(anotherBook, 'anotherBook'); | ||
| }); | ||
| describe('InvertedIndex class', () => { | ||
| it('should check that the class has a createIndex method', () => { | ||
| expect(typeof indexInstance.createIndex).toBe('function'); | ||
| }); | ||
|
|
||
| it('should check that the class has a readFile method', () => { | ||
| expect(typeof InvertedIndex.readFile).toBe('function'); | ||
| }); | ||
|
|
||
| it('should check that the class has a validateFile method', () => { | ||
| expect(typeof InvertedIndex.validateFile).toBe('function'); | ||
| }); | ||
|
|
||
| it('should check that the class has a tokenize method', () => { | ||
| expect(typeof InvertedIndex.tokenize).toBe('function'); | ||
| }); | ||
|
|
||
| it('should check that the class has a getDocumentTokens method', () => { | ||
| expect(typeof InvertedIndex.getDocumentTokens).toBe('function'); | ||
| }); | ||
|
|
||
| it('should check that the class has a getIndex method', () => { | ||
| expect(typeof indexInstance.getIndex).toBe('function'); | ||
| }); | ||
|
|
||
| it('should check that the class has a searchIndex method', () => { | ||
| expect(typeof indexInstance.searchIndex).toBe('function'); | ||
| }); | ||
|
|
||
| it('should check that the class has a getSearchResults method', () => { | ||
| expect(typeof indexInstance.getSearchResults).toBe('function'); | ||
| }); | ||
|
|
||
| it('should check that the class has a getDocuments method', () => { | ||
| expect(typeof indexInstance.getDocuments).toBe('function'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Read File', () => { | ||
| it('should return false for an invalid filename extension', () => { | ||
| const badFile = { name: 'badfileextension.jpg' }; | ||
| const anotherBadFile = { name: 'badfileextension.jsona' }; | ||
| InvertedIndex.readFile(badFile).then((response) => { | ||
| expect(response).toBeFalsy(); | ||
| }); | ||
| InvertedIndex.readFile(anotherBadFile).then((response) => { | ||
| expect(response).toBeFalsy(); | ||
| }); | ||
| }); | ||
| const bookFile = new File([JSON.stringify(validBookFile)], | ||
| 'books.json', { type: 'application/json' }); | ||
| it('should return appropriate value for a valid json file', () => { | ||
| InvertedIndex.readFile(bookFile).then((response) => { | ||
| expect(response[0].title).toEqual(books[0].title); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Create Index', () => { | ||
| it('should return mapped indices to words in a JSON file', () => { | ||
| const expectedResult = | ||
| { alice: [0], | ||
| falls: [0], | ||
| into: [0], | ||
| a: [0, 1, 2], | ||
| rabbit: [0], | ||
| hole: [0], | ||
| and: [0, 1, 2], | ||
| enters: [0], | ||
| world: [0], | ||
| full: [0], | ||
| of: [0, 1, 2], | ||
| imagination: [0], | ||
| in: [0], | ||
| wonderland: [0], | ||
| an: [1, 2], | ||
| unusual: [1, 2], | ||
| alliance: [1, 2], | ||
| man: [1, 2], | ||
| elf: [1, 2], | ||
| dwarf: [1, 2], | ||
| wizard: [1, 2], | ||
| hobbit: [1, 2], | ||
| seek: [1, 2], | ||
| to: [1, 2], | ||
| destroy: [1, 2], | ||
| powerful: [1, 2], | ||
| ring: [1, 2], | ||
| the: [1, 2], | ||
| lord: [1, 2], | ||
| rings: [1, 2], | ||
| fellowship: [1, 2] }; | ||
| expect(indexInstance.filesIndexed.books.index) | ||
| .toEqual(expectedResult); | ||
| }); | ||
| it('should return false for file with no content', () => { | ||
| const term = {}; | ||
| expect(indexInstance.createIndex(term, 'term')).toBeFalsy(); | ||
| }); | ||
| }); | ||
| describe('Search Index', () => { | ||
| it('should search through single files that are indexed', () => { | ||
| const requiredOutput = { alice: [0], | ||
| and: [0, 1, 2], | ||
| unusual: [1, 2], | ||
| imagination: [0] }; | ||
| const searchTerm = indexInstance | ||
| .searchIndex('Alice, and her unusual imagination', 'books'); | ||
| expect(Object.keys(searchTerm[0].indexes)) | ||
| .toEqual(Object.keys(requiredOutput)); | ||
| expect(searchTerm[0].indexes).toEqual(requiredOutput); | ||
| }); | ||
| it('should return false for an empty String', () => { | ||
| const term = ''; | ||
| expect(indexInstance.searchIndex(term, 'books')) | ||
| .toBeFalsy(); | ||
| }); | ||
| it('should return an empty object for words not found', () => { | ||
| const term = 'Aeroplane'; | ||
| const expectedOutput = indexInstance.searchIndex(term, 'books'); | ||
| expect(expectedOutput[0].indexes).toEqual({ }); | ||
| }); | ||
| it('should return appropriate result for when all files is selected', | ||
| () => { | ||
| const expectedOutput = | ||
| [{ indexes: { alice: [0], the: [1, 2] }, | ||
| searchedFile: 'books', | ||
| documents: [0, 1, 2] }, | ||
| { indexes: { alice: [0], | ||
| is: [0], | ||
| the: [0, 1] }, | ||
| searchedFile: 'anotherBook', | ||
| documents: [0, 1] }, | ||
| { indexes: { }, | ||
| searchedFile: 'term', | ||
| documents: [] }]; | ||
| expect(indexInstance | ||
| .searchIndex('Alice is the', 'all')).toEqual(expectedOutput); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Tokenize words', () => { | ||
| it('should strip out special characters from text in documents', () => { | ||
| let excerpt = 'Alice l##$oves her ima&&gination?'; | ||
| const expectedTokens = ['alice', 'loves', 'her', 'imagination']; | ||
| excerpt = InvertedIndex.tokenize(excerpt); | ||
| expect(excerpt).toEqual(expectedTokens); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Get index', () => { | ||
| it('should return the appropriate output for the given filename', () => { | ||
| const filename = 'books'; | ||
| const expectedOutput = { alice: [0], | ||
| falls: [0], | ||
| into: [0], | ||
| a: [0, 1, 2], | ||
| rabbit: [0], | ||
| hole: [0], | ||
| and: [0, 1, 2], | ||
| enters: [0], | ||
| world: [0], | ||
| full: [0], | ||
| of: [0, 1, 2], | ||
| imagination: [0], | ||
| in: [0], | ||
| wonderland: [0], | ||
| an: [1, 2], | ||
| unusual: [1, 2], | ||
| alliance: [1, 2], | ||
| man: [1, 2], | ||
| elf: [1, 2], | ||
| dwarf: [1, 2], | ||
| wizard: [1, 2], | ||
| hobbit: [1, 2], | ||
| seek: [1, 2], | ||
| to: [1, 2], | ||
| destroy: [1, 2], | ||
| powerful: [1, 2], | ||
| ring: [1, 2], | ||
| the: [1, 2], | ||
| lord: [1, 2], | ||
| rings: [1, 2], | ||
| fellowship: [1, 2] }; | ||
| expect(indexInstance.getIndex(filename)) | ||
| .toEqual(expectedOutput); | ||
| }); | ||
| it('should return false for an empty filename', () => { | ||
| const filename = ''; | ||
| expect(indexInstance.getIndex(filename)) | ||
| .toBeFalsy(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Validate File', () => { | ||
| it('should return false for incorrect document structure', () => { | ||
| const term = [{ t1: 'Welcome home', text: 'This is really home' }]; | ||
| expect(InvertedIndex.validateFile(term, 'term')).toBeFalsy(); | ||
| }); | ||
| it('should return true for correct document structure', () => { | ||
| const term = [{ title: 'Welcome home', text: 'This is really home' }]; | ||
| expect(InvertedIndex.validateFile(term, 'term')).toBeTruthy(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Get Document Tokens', () => { | ||
| it('should return the appropriate object for a given document', | ||
| () => { | ||
| const expectedOutput = { documentCount: 0, | ||
| textTokens: ['welcome', 'this', 'is', 'a', 'test', 'document'] }; | ||
| const documentCount = 0; | ||
| const term = [{ text: 'Welcome', title: 'This is a test document' }]; | ||
| expect(InvertedIndex | ||
| .getDocumentTokens(term, documentCount)).toEqual(expectedOutput); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Get Document Data', () => { | ||
| it('should return the appropriate array of documents for a given file', | ||
| () => { | ||
| const expectedOutput = [0, 1, 2]; | ||
| expect(indexInstance | ||
| .getDocuments('books')).toEqual(expectedOutput); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Get Search result Data', () => { | ||
| it('should return the appropriate result for tokens searched', | ||
| () => { | ||
| const words = 'Alice is a girl'; | ||
| const expectedOutput = { alice: [0], a: [0, 1, 2] }; | ||
| expect(indexInstance | ||
| .getSearchResults(words, 'books')).toEqual(expectedOutput); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Get Construct Index Data', () => { | ||
| it('should return the appropriate indexed words for a given document', | ||
| () => { | ||
| const documentTokens = [{ documentCount: 0, | ||
| textTokens: ['welcome', 'this', 'is', 'a', 'test', 'document'] }]; | ||
| const expectedOutput = | ||
| { welcome: [0], this: [0], is: [0], a: [0], test: [0], document: [0] }; | ||
| expect(InvertedIndex.constructIndex(documentTokens)) | ||
| .toEqual(expectedOutput); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| },{"../samples/books.json":1}]},{},[2]) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Block must not be padded by blank lines padded-blocks |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,3 +33,8 @@ | |
| .padding10{ | ||
| padding: 10px; | ||
| } | ||
|
|
||
| #myTable{ | ||
| z-index: 1; | ||
| overflow-y: scroll; | ||
| } | ||
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.
Move the invocation into the parens that contain the function wrap-iife
A space is required after ',' comma-spacing
Requires a space after '{' block-spacing
Missing space before opening brace space-before-blocks
Missing JSDoc comment require-jsdoc
Expected space(s) after "if" keyword-spacing
Unexpected var, use let or const instead no-var
All 'var' declarations must be at the top of the function scope vars-on-top
Infix operators must be spaced space-infix-ops
Expected '===' and instead saw '==' eqeqeq
Strings must use singlequote quotes
Missing whitespace after semicolon semi-spacing
Expected space(s) before "return" keyword-spacing
'i' was used before it was defined no-use-before-define
Unexpected string concatenation prefer-template
Missing semicolon semi
Requires a space before '}' block-spacing
Expected space(s) before "var" keyword-spacing
A space is required after '{' object-curly-spacing
Missing space before value for key 'exports' key-spacing
A space is required before '}' object-curly-spacing
Unexpected function expression prefer-arrow-callback
Missing space before function parentheses space-before-function-paren
'e' is already declared in the upper scope no-shadow
'n' is already declared in the upper scope no-shadow
Unnecessary use of conditional expression for default assignment no-unneeded-ternary
Expected space(s) after "for" keyword-spacing
Unary operator '++' used no-plusplus
Missing space before value for key '1' key-spacing
'exports' is defined but never used no-unused-vars
Block must not be padded by blank lines padded-blocks