{"size": 2082, "ext": "js", "max_stars_repo_path": "node_modules/can-debug/src/graph/graph-test.js", "max_stars_repo_name": "JFAquinoPando/place-my-order", "max_stars_repo_stars_event_min_datetime": "2020-02-12T21:54:41.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-12T21:54:41.000Z", "max_issues_repo_path": "node_modules/can-debug/src/graph/graph-test.js", "max_issues_repo_name": "JFAquinoPando/place-my-order", "max_issues_repo_issues_event_min_datetime": "2017-06-29T17:18:03.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-27T19:58:47.000Z", "max_forks_repo_path": "node_modules/can-debug/src/graph/graph-test.js", "max_forks_repo_name": "JFAquinoPando/place-my-order", "max_forks_repo_forks_event_min_datetime": "2018-05-02T14:02:21.000Z", "max_forks_repo_forks_event_max_datetime": "2018-05-02T14:02:21.000Z"}
{"max_stars_count": 1, "max_issues_count": 37, "max_forks_count": 1, "avg_line_length": 18.5892857143, "max_line_length": 53, "alphanum_fraction": 0.6248799232}
var Graph = require("./graph");
var QUnit = require("steal-qunit");

QUnit.module("Graph");

QUnit.test("addNode", function(assert) {
	var g = new Graph();
	var one = "1";

	g.addNode(one);

	assert.ok(
		g.findNode(function(node) {
			return node === one;
		})
	);
});

QUnit.test("addArrow", function(assert) {
	var g = new Graph();
	var one = "1";
	var two = "2";

	g.addNode(one);
	g.addNode(two);
	g.addArrow(one, two);

	assert.ok(g.hasArrow(one, two));
});

QUnit.test("getArrowMeta", function(assert) {
	var g = new Graph();
	var one = "1";
	var two = "2";
	var meta = { type: "twoWay" };

	g.addNode(one);
	g.addNode(two);
	g.addArrow(one, two, meta);

	assert.equal(g.getArrowMeta(one, two), meta);
});

QUnit.test("setArrowMeta", function(assert) {
	var g = new Graph();
	var one = "1";
	var two = "2";
	var meta = { type: "twoWay" };

	g.addNode(one);
	g.addNode(two);
	g.addArrow(one, two);
	g.setArrowMeta(one, two, meta);

	assert.equal(g.getArrowMeta(one, two), meta);
});

QUnit.test("getNeighbors", function(assert) {
	var g = new Graph();
	var one = "1";
	var two = "2";
	var three = "3";

	g.addNode(one);
	g.addNode(two);
	g.addNode(three);

	// 1 -> 2 -> 3
	// 1 -> 3
	g.addArrow(one, two);
	g.addArrow(one, three);
	g.addArrow(two, three);

	var oneNeighbors = new Set();
	oneNeighbors.add(two);
	oneNeighbors.add(three);
	assert.deepEqual(g.getNeighbors(one), oneNeighbors);

	var twoNeighbors = new Set();
	twoNeighbors.add(three);
	assert.deepEqual(g.getNeighbors(two), twoNeighbors);

	assert.deepEqual(g.getNeighbors(three), new Set());
});

QUnit.test("reverse", function(assert) {
	var one = "1";
	var two = "2";
	var three = "3";

	var g = new Graph();
	g.addNode(one);
	g.addNode(two);
	g.addNode(three);

	// 1 -> 2 -> 3
	// 1 -> 3
	g.addArrow(one, two);
	g.addArrow(one, three);
	g.addArrow(two, three);

	var r = g.reverse();
	assert.ok(r.hasArrow(two, one));
	assert.ok(!r.hasArrow(one, two));

	assert.ok(r.hasArrow(three, one));
	assert.ok(!r.hasArrow(one, three));

	assert.ok(r.hasArrow(three, two));
	assert.ok(!r.hasArrow(two, three));
});
