<commit_before>import Graph from '../src/Graph.js';
import GraphQuery from '../src/GraphQuery.js';

let expect = require('chai').expect;
let crypto = require('crypto');
let levelup = require('levelup');
let db;
let graph;

beforeEach(() => {
  db = levelup(crypto.randomBytes(64).toString('hex'), {
    db: require('memdown'),
    keyEncoding: 'json',
    valueEncoding: 'json'
  });
  graph = new Graph({db: db});
});

describe('Graph', function() {

  describe('Constructor', function() {

    it('Should Initialize', () => {
      expect(graph).to.be.instanceof(Graph);
    });

  });

  describe('init', function() {

    it('Should ignore multiple calls to init', done => {
      graph.init()
        .then(ignored => graph.init())
        .then(ignored => done())
        .catch(error => done(error));
    });
<commit_msg>proper test for double init<commit_after>import Graph from '../src/Graph.js';
import GraphQuery from '../src/GraphQuery.js';

let expect = require('chai').expect;
let crypto = require('crypto');
let levelup = require('levelup');
let db;
let graph;

beforeEach(() => {
  db = levelup(crypto.randomBytes(64).toString('hex'), {
    db: require('memdown'),
    keyEncoding: 'json',
    valueEncoding: 'json'
  });
  graph = new Graph({db: db});
});

describe('Graph', function() {

  describe('Constructor', function() {

    it('Should Initialize', () => {
      expect(graph).to.be.instanceof(Graph);
    });

  });

  describe('init', function() {

    it('Should ignore multiple calls to init', done => {
      Promise.all([
          graph.addNode('1234', 'label'),
          graph.addNode('5678', 'label'),
          graph.addNode('9012', 'label')
        ])
        .then(values => {
          values[0].setProperty('foo', 'bar');
          values[1].setProperty('foo', 'bar');
          values[2].setProperty('foo', 'bar');
        })
        .then(ignored => {
          graph = new Graph({db: db});
          for (let node of graph.getNodes()) {
            throw new Error('Should have had 0 nodes');
          }
          return graph.init();
        })
        .then(ignored => graph.init()) // Should only load nodes once
        .then(graph => {
          let expectedIDs = ['1234', '5678', '9012'];
          for (let node of graph.getNodes()) {
            expect(expectedIDs).to.include(node.id);
            // Remove id from the expected array
            expectedIDs.splice(expectedIDs.indexOf(node.id), 1);
            expect(node._properties).to.deep.equal({foo: 'bar'});
          }
          expect(expectedIDs).to.deep.equal([]);
          done();
        })
        .catch(error => done(error));
    });

{'fraction_non_alphanumeric': 0.1856873822975518, 'fraction_numerical': 0.012429378531073447, 'mean_word_length': 2.5940460081190797, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '1012819', 'n_tokens_mistral': 811, 'n_tokens_neox': 779, 'n_words': 177}