Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(654)

Unified Diff: test/graph_test.dart

Issue 1412903002: include fields in verify_deps, refactor graph dfs (Closed) Base URL: git@github.com:dart-lang/dart2js_info.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/all_test.dart ('k') | test/parse_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/graph_test.dart
diff --git a/test/graph_test.dart b/test/graph_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..4934adfeeb88124ad6cee45e25ca59e97f689494
--- /dev/null
+++ b/test/graph_test.dart
@@ -0,0 +1,73 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'package:dart2js_info/src/graph.dart';
+import 'package:test/test.dart';
+
+main() {
+ var graph = makeTestGraph();
+
+ test('preorder traversal', () {
+ expect(graph.preOrder('A').toList(), equals(['A', 'E', 'D', 'C', 'B']));
+ });
+
+ test('postorder traversal', () {
+ expect(graph.postOrder('A').toList(), equals(['C', 'E', 'D', 'B', 'A']));
+ });
+
+ test('topological sort', () {
+ expect(
+ graph.computeTopologicalSort(),
+ equals([
+ ['C'],
+ ['E'],
+ ['D', 'B', 'A']
+ ]));
+ });
+
+ test('contains path', () {
+ expect(graph.containsPath('A', 'C'), isTrue);
+ expect(graph.containsPath('B', 'E'), isTrue);
+ expect(graph.containsPath('C', 'A'), isFalse);
+ expect(graph.containsPath('E', 'B'), isFalse);
+ });
+
+ test('dominator tree', () {
+ // A dominates all other nodes in the graph, the resulting tree looks like
+ // A
+ // / / | |
+ // B C D E
+ var dom = graph.dominatorTree('A');
+ expect(dom.targetsOf('A').length, equals(4));
+ });
+
+ test('cycle finding', () {
+ expect(graph.findCycleContaining('B'), equals(['A', 'D', 'B']));
+ expect(graph.findCycleContaining('C'), equals(['C']));
+ });
+}
+
+/// Creates a simple test graph with the following structure:
+/// ```
+/// A -> E
+/// / ^ ^
+/// / \ /
+/// v v /
+/// B -> D
+/// \ /
+/// v v
+/// C
+/// ```
+Graph<String> makeTestGraph() {
+ var graph = new EdgeListGraph<String>();
+ graph.addEdge('A', 'B');
+ graph.addEdge('A', 'D');
+ graph.addEdge('A', 'E');
+ graph.addEdge('B', 'C');
+ graph.addEdge('B', 'D');
+ graph.addEdge('D', 'A');
+ graph.addEdge('D', 'C');
+ graph.addEdge('D', 'E');
+ return graph;
+}
« no previous file with comments | « test/all_test.dart ('k') | test/parse_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698