{"size": 2152, "ext": "js", "max_stars_repo_path": "test/test.js", "max_stars_repo_name": "doowb/ngraph.frombinary", "max_stars_repo_stars_event_min_datetime": "2016-11-05T22:20:09.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-30T15:24:00.000Z", "max_issues_repo_path": "test/test.js", "max_issues_repo_name": "doowb/ngraph.frombinary", "max_issues_repo_issues_event_min_datetime": "2018-08-24T14:13:20.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-20T04:01:54.000Z", "max_forks_repo_path": "test/test.js", "max_forks_repo_name": "doowb/ngraph.frombinary", "max_forks_repo_forks_event_min_datetime": "2021-01-31T02:36:57.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-31T02:36:57.000Z"}
{"max_stars_count": 4, "max_issues_count": 2, "max_forks_count": 1, "avg_line_length": 29.0810810811, "max_line_length": 79, "alphanum_fraction": 0.6291821561}
'use strict';

require('mocha');
var path = require('path');
var del = require('delete');
var mkdirp = require('mkdirp');
var assert = require('assert');
var save = require('ngraph.tobinary');
var Graph = require('ngraph.graph');
var load = require('../');

describe('ngraph.frombinary', function() {
  beforeEach(function() {
    mkdirp.sync(path.join(__dirname, 'actual'));
  });

  afterEach(function() {
    del.sync(path.join(__dirname, 'actual'));
  });

  it('should export a function', function() {
    assert.equal(typeof load, 'function');
  });

  it('should throw an error when invalid args are passed', function(cb) {
    try {
      load();
      cb(new Error('expected an error'));
    } catch (err) {
      assert(err);
      assert.equal(err.message, 'expected the first argument to be an object');
      cb();
    }
  });

  it('should load a graph from a given metadata file', function() {
    var graph = new Graph({uniqueLinkIds: false});
    graph = load(graph, {cwd: path.join(__dirname, 'fixtures')});
    assert.equal(graph.getNodesCount(), 4);
    assert.equal(graph.getLinksCount(), 3);

    var i = 0;
    var labels = ['a', 'b', 'c', 'd'];
    graph.forEachNode(function(node) {
      assert.equal(node.id, labels[i++]);
    });
  });

  it('should load a graph from a saved graph', function() {
    var graph = new Graph({uniqueLinkIds: false});
    graph.addLink('foo', 'bar');
    graph.addLink('bar', 'baz');
    graph.addLink('baz', 'bang');
    graph.addLink('baz', 'foo');

    save(graph, {outDir: path.join(__dirname, 'actual')});
    var actual = new Graph({uniqueLinkIds: false});
    actual = load(actual, {cwd: path.join(__dirname, 'actual')});

    assert.equal(actual.getNodesCount(), graph.getNodesCount());
    assert.equal(actual.getLinksCount(), graph.getLinksCount());

    graph.forEachNode(function(node) {
      var actualNode = actual.getNode(node.id);
      assert(actualNode);
      assert.deepEqual(actualNode, node);

      var expectedLinks = graph.getLinks(node.id);
      var actualLinks = actual.getLinks(actualNode.id);
      assert.deepEqual(actualLinks, expectedLinks);
    });
  });
});
