當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript graph.Graph類代碼示例

本文整理匯總了TypeScript中vs/platform/instantiation/common/graph.Graph的典型用法代碼示例。如果您正苦於以下問題:TypeScript Graph類的具體用法?TypeScript Graph怎麽用?TypeScript Graph使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Graph類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: suite

suite('Graph', () => {
	let graph: Graph<string>;

	setup(() => {
		graph = new Graph<string>(s => s);
	});

	test('is possible to lookup nodes that don\'t exist', function () {
		assert.deepEqual(graph.lookup('ddd'), null);
	});

	test('inserts nodes when not there yet', function () {
		assert.deepEqual(graph.lookup('ddd'), null);
		assert.deepEqual(graph.lookupOrInsertNode('ddd').data, 'ddd');
		assert.deepEqual(graph.lookup('ddd').data, 'ddd');
	});

	test('can remove nodes and get length', function () {
		assert.ok(graph.isEmpty());
		assert.deepEqual(graph.lookup('ddd'), null);
		assert.deepEqual(graph.lookupOrInsertNode('ddd').data, 'ddd');
		assert.ok(!graph.isEmpty());
		graph.removeNode('ddd');
		assert.deepEqual(graph.lookup('ddd'), null);
		assert.ok(graph.isEmpty());
	});

	test('root', () => {
		graph.insertEdge('1', '2');
		let roots = graph.roots();
		assert.equal(roots.length, 1);
		assert.equal(roots[0].data, '2');

		graph.insertEdge('2', '1');
		roots = graph.roots();
		assert.equal(roots.length, 0);
	});

	test('root complex', function () {
		graph.insertEdge('1', '2');
		graph.insertEdge('1', '3');
		graph.insertEdge('3', '4');

		let roots = graph.roots();
		assert.equal(roots.length, 2);
		assert(['2', '4'].every(n => roots.some(node => node.data === n)));
	});
});
開發者ID:PKRoma,項目名稱:vscode,代碼行數:48,代碼來源:graph.test.ts

示例2: function

	test('root complex', function () {
		graph.insertEdge('1', '2');
		graph.insertEdge('1', '3');
		graph.insertEdge('3', '4');

		let roots = graph.roots();
		assert.equal(roots.length, 2);
		assert(['2', '4'].every(n => roots.some(node => node.data === n)));
	});
開發者ID:PKRoma,項目名稱:vscode,代碼行數:9,代碼來源:graph.test.ts

示例3:

	test('root', () => {
		graph.insertEdge('1', '2');
		let roots = graph.roots();
		assert.equal(roots.length, 1);
		assert.equal(roots[0].data, '2');

		graph.insertEdge('2', '1');
		roots = graph.roots();
		assert.equal(roots.length, 0);
	});
開發者ID:PKRoma,項目名稱:vscode,代碼行數:10,代碼來源:graph.test.ts


注:本文中的vs/platform/instantiation/common/graph.Graph類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。