<commit_before>/*jshint esversion: 6 */

const InvertedIndex = require('../../src/inverted-index.js').InvertedIndex;

beforeEach(() => {
  index = new InvertedIndex();
  index2 = new InvertedIndex();
});

describe("Read book data", () => {

  beforeEach(() => {
    file = index.loadFile('/Users/warengamaina/Documents/D0/inverted-index/jasmine/books.json');
  });

  //reads json file and asserts it is not empty
  it("not empty", () => {
    expect(file).not.toBe(null);
  });

  //checks if file content is a valid JSON array
  it("valid json", () => {
    function isJson(file) {
      try {
        JSON.parse(file);
      } catch (e) {
        return false;
      }
      return true;
    }
    expect(isJson(file)).toBe(true);
  });
});



describe("Populate index", () => {
  beforeEach(function() {
    index.loadFile('/Users/warengamaina/Documents/D0/inverted-index/jasmine/books.json');
    file = index.createIndex();
  });

  //checks if index is created
  it("is created", () => {
    expect(index.index_object).not.toBe(null);
  });

});

describe("Search index", () => {
  beforeEach(function() {
    index.loadFile('/Users/warengamaina/Documents/D0/inverted-index/jasmine/books.json');
    file = index.createIndex();

    index2.loadFile('/Users/warengamaina/Documents/D0/inverted-index/jasmine/test.json');
    fileTwo = index2.createIndex();
  });


  //Ensures index returns the correct results when searched.
  it("is correct", () => {
    expect(index.searchIndex('books.json', file, 'alice')).toBe('books.json: alice: 0');
    expect(index.searchIndex('test.json', fileTwo, 'comical')).toBe('test.json: comical: 1');
  });

  //Ensure searchIndex can handle an array of search terms.
  it("can handle an array of search terms", () => {
    expect(index.searchIndex('books.json', file, 'alliance', 'alice', 'powerful', 'wonderland'))
      .toEqual('books.json: alliance: 1,alice: 0,powerful: 1,wonderland: 0');
  });


  //Ensure searchIndex can handle a varied number of search terms as arguments.
  it("can handle varied number of search terms", () => {
    expect(index.searchIndex('books.json', file, ['a', 'alice'], 'book', 'me', ['help'])).
    toEqual('books.json: a: 0,1,alice: 0');
  });
<commit_msg>changed directory<commit_after>/*jshint esversion: 6 */

const path = require('path');

const InvertedIndex = require('../../src/inverted-index.js').InvertedIndex;

beforeEach(() => {
  index = new InvertedIndex();
  index2 = new InvertedIndex();
});

describe("Read book data", () => {

  beforeEach(() => {
    file = index.loadFile(path.join(__dirname, '..', '/jasmine/books.json'));
  });

  //reads json file and asserts it is not empty
  it("not empty", () => {
    expect(file).not.toBe(null);
  });

  //checks if file content is a valid JSON array
  it("valid json", () => {
    function isJson(file) {
      try {
        JSON.parse(file);
      } catch (e) {
        return false;
      }
      return true;
    }
    expect(isJson(file)).toBe(true);
  });
});



describe("Populate index", () => {
  beforeEach(function() {
    index.loadFile(path.join(__dirname, '..', '/jasmine/books.json'));
    file = index.createIndex();
  });

  //checks if index is created
  it("is created", () => {
    expect(index.index_object).not.toBe(null);
  });

});

describe("Search index", () => {
  beforeEach(function() {
    index.loadFile(path.join(__dirname, '..', '/jasmine/books.json'));
    file = index.createIndex();

    index2.loadFile(path.join(__dirname, '..', '/jasmine/test.json'));
    fileTwo = index2.createIndex();
  });


  //Ensures index returns the correct results when searched.
  it("is correct", () => {
    expect(index.searchIndex('books.json', file, 'alice')).toBe('books.json: alice: 0');
    expect(index.searchIndex('test.json', fileTwo, 'comical')).toBe('test.json: comical: 1');
  });

  //Ensure searchIndex can handle an array of search terms.
  it("can handle an array of search terms", () => {
    expect(index.searchIndex('books.json', file, 'alliance', 'alice', 'powerful', 'wonderland'))
      .toEqual('books.json: alliance: 1,alice: 0,powerful: 1,wonderland: 0');
  });


  //Ensure searchIndex can handle a varied number of search terms as arguments.
  it("can handle varied number of search terms", () => {
    expect(index.searchIndex('books.json', file, ['a', 'alice'], 'book', 'me', ['help'])).
    toEqual('books.json: a: 0,1,alice: 0');
  });

{'fraction_non_alphanumeric': 0.19254237288135592, 'fraction_numerical': 0.006779661016949152, 'mean_word_length': 3.5025432349949135, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3617250', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1438, 'n_words': 316}