Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import "package:test/test.dart"; | 5 import "package:test/test.dart"; |
| 6 | 6 |
| 7 import "package:collection/collection.dart"; | 7 import "package:collection/collection.dart"; |
| 8 | 8 |
| 9 void main() { | 9 void main() { |
| 10 group("mapMap()", () { | 10 group("mapMap()", () { |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 "foo": ["bar"], | 174 "foo": ["bar"], |
| 175 "bar": ["baz"], | 175 "bar": ["baz"], |
| 176 "baz": ["foo"] | 176 "baz": ["foo"] |
| 177 }), equals({ | 177 }), equals({ |
| 178 "foo": ["bar", "baz", "foo"], | 178 "foo": ["bar", "baz", "foo"], |
| 179 "bar": ["baz", "foo", "bar"], | 179 "bar": ["baz", "foo", "bar"], |
| 180 "baz": ["foo", "bar", "baz"] | 180 "baz": ["foo", "bar", "baz"] |
| 181 })); | 181 })); |
| 182 }); | 182 }); |
| 183 }); | 183 }); |
| 184 | |
| 185 group("stronglyConnectedComponents()", () { | |
| 186 test("returns an empty list for an empty graph", () { | |
| 187 expect(stronglyConnectedComponents({}), isEmpty); | |
| 188 }); | |
|
Lasse Reichstein Nielsen
2016/06/16 08:21:33
Also test with singleton graphs: {"a":[]} and {"a
nweiz
2016/06/20 21:19:38
Done.
| |
| 189 | |
| 190 test("returns individual vertices for a tree", () { | |
| 191 expect(stronglyConnectedComponents({ | |
| 192 "foo": ["bar"], | |
| 193 "bar": ["baz", "bang"], | |
| 194 "baz": ["qux"], | |
| 195 "bang": ["zap"], | |
| 196 "qux": [], | |
| 197 "zap": [] | |
| 198 }), equals([ | |
| 199 new Set.from(["foo"]), | |
| 200 new Set.from(["bar"]), | |
| 201 new Set.from(["bang"]), | |
| 202 new Set.from(["zap"]), | |
| 203 new Set.from(["baz"]), | |
| 204 new Set.from(["qux"]) | |
| 205 ])); | |
| 206 }); | |
| 207 | |
| 208 test("returns a single set for a fully cyclic graph", () { | |
| 209 expect(stronglyConnectedComponents({ | |
| 210 "foo": ["bar"], | |
| 211 "bar": ["baz"], | |
| 212 "baz": ["bang"], | |
| 213 "bang": ["foo"] | |
| 214 }), equals([new Set.from(["foo", "bar", "baz", "bang"])])); | |
| 215 }); | |
| 216 | |
| 217 test("returns separate sets for each strongly connected component", () { | |
| 218 // https://en.wikipedia.org/wiki/Strongly_connected_component#/media/File: Scc.png | |
| 219 expect(stronglyConnectedComponents({ | |
| 220 "a": ["b"], | |
| 221 "b": ["c", "e", "f"], | |
| 222 "c": ["d", "g"], | |
| 223 "d": ["c", "h"], | |
| 224 "e": ["a", "f"], | |
| 225 "f": ["g"], | |
| 226 "g": ["f"], | |
| 227 "h": ["g", "d"] | |
| 228 }), equals([ | |
| 229 new Set.from(["a", "b", "e"]), | |
| 230 new Set.from(["c", "d", "h"]), | |
| 231 new Set.from(["f", "g"]), | |
| 232 ])); | |
| 233 }); | |
| 234 | |
| 235 test("always returns components in topological order", () { | |
|
Lasse Reichstein Nielsen
2016/06/16 08:21:33
You are checking for a specific topological orderi
nweiz
2016/06/20 21:19:38
It's a noble goal to try to preserve the invariant
| |
| 236 expect(stronglyConnectedComponents({ | |
| 237 "bar": ["baz", "bang"], | |
| 238 "zap": [], | |
| 239 "baz": ["qux"], | |
| 240 "qux": [], | |
| 241 "foo": ["bar"], | |
| 242 "bang": ["zap"] | |
| 243 }), equals([ | |
| 244 new Set.from(["foo"]), | |
| 245 new Set.from(["bar"]), | |
| 246 new Set.from(["bang"]), | |
| 247 new Set.from(["zap"]), | |
| 248 new Set.from(["baz"]), | |
| 249 new Set.from(["qux"]) | |
| 250 ])); | |
| 251 }); | |
| 252 }); | |
| 184 } | 253 } |
| OLD | NEW |