c1f140bc78
Pure-Dart SCC ranking and column placement over the landed graph identities. Every extent and gap is caller supplied; missing measurements are rejected rather than defaulted. Focused tests cover linear, diamond, cycle, self-loop, disconnected, terminal, expanded-text and invalid-input cases.
117 lines
3.6 KiB
Dart
117 lines
3.6 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/features/graph/domain/graph_definition.dart';
|
|
import 'package:pipelines_app/features/graph/domain/graph_protocol.dart';
|
|
import 'package:pipelines_app/features/graph/layout/graph_ranks.dart';
|
|
|
|
import 'layout_fixtures.dart';
|
|
|
|
GraphRanks _ranksFor(Map<String, dynamic> graph) {
|
|
return assignGraphRanks(graphNodes(graph), graphEdges(graph));
|
|
}
|
|
|
|
void main() {
|
|
test('linear definitions rank one stage per column', () {
|
|
final ranks = _ranksFor(linearGraphFixture());
|
|
|
|
expect(ranks.rankOf, <String, int>{
|
|
'plan': 0,
|
|
'build': 1,
|
|
'ship': 2,
|
|
failureEnd: 3,
|
|
successEnd: 3,
|
|
});
|
|
expect(ranks.rankCount, 4);
|
|
expect(ranks.components, <List<String>>[
|
|
<String>['plan'],
|
|
<String>['build'],
|
|
<String>['ship'],
|
|
<String>[failureEnd],
|
|
<String>[successEnd],
|
|
]);
|
|
});
|
|
|
|
test('diamond fan-out shares a rank and converges after it', () {
|
|
final ranks = _ranksFor(diamondGraphFixture());
|
|
|
|
expect(ranks.rankOf['a'], 0);
|
|
expect(ranks.rankOf['b'], ranks.rankOf['c']);
|
|
expect(ranks.rankOf['b'], 1);
|
|
expect(ranks.rankOf['d'], 2);
|
|
expect(ranks.rankOf[failureEnd], 1);
|
|
expect(ranks.rankOf[successEnd], 3);
|
|
expect(ranks.rankCount, 4);
|
|
});
|
|
|
|
test('a cycle collapses to one shared rank instead of recursing', () {
|
|
final ranks = _ranksFor(cycleGraph());
|
|
|
|
expect(ranks.rankOf['a'], 0);
|
|
expect(ranks.rankOf['b'], 0);
|
|
expect(ranks.rankOf[failureEnd], 1);
|
|
expect(ranks.rankOf[successEnd], 1);
|
|
expect(ranks.rankCount, 2);
|
|
expect(ranks.components, contains(equals(<String>['a', 'b'])));
|
|
});
|
|
|
|
test('a self edge stays inside its own component and adds no rank', () {
|
|
final ranks = _ranksFor(selfLoopGraphFixture());
|
|
|
|
expect(ranks.rankOf, <String, int>{
|
|
'a': 0,
|
|
'b': 1,
|
|
failureEnd: 2,
|
|
successEnd: 2,
|
|
});
|
|
expect(ranks.components, contains(equals(<String>['a'])));
|
|
expect(ranks.components, contains(equals(<String>['b'])));
|
|
});
|
|
|
|
test('disconnected stages stay at rank zero', () {
|
|
final ranks = _ranksFor(disconnectedGraph());
|
|
|
|
expect(ranks.rankOf['a'], 0);
|
|
expect(ranks.rankOf['b'], 0);
|
|
expect(ranks.rankOf['c'], 0);
|
|
expect(ranks.rankOf[failureEnd], 1);
|
|
expect(ranks.rankOf[successEnd], 1);
|
|
expect(ranks.rankCount, 2);
|
|
});
|
|
|
|
test('unknown and empty edge targets never become ranks or nodes', () {
|
|
final graph = incompleteGraphFixture();
|
|
final nodes = graphNodes(graph);
|
|
final ranks = assignGraphRanks(nodes, graphEdges(graph));
|
|
|
|
expect(nodes.map((node) => node.key), isNot(contains('ghost')));
|
|
expect(ranks.rankOf.containsKey('ghost'), isFalse);
|
|
expect(ranks.rankOf.containsKey(''), isFalse);
|
|
expect(ranks.rankOf['a'], 0);
|
|
expect(ranks.rankOf['b'], 0);
|
|
expect(ranks.rankOf[failureEnd], 1);
|
|
expect(ranks.rankOf[successEnd], 1);
|
|
});
|
|
|
|
test('ranks are stable across repeated assignments', () {
|
|
final graph = diamondGraphFixture();
|
|
final nodes = graphNodes(graph);
|
|
final edges = graphEdges(graph);
|
|
|
|
final first = assignGraphRanks(nodes, edges);
|
|
final second = assignGraphRanks(nodes, edges);
|
|
|
|
expect(second.rankOf, first.rankOf);
|
|
expect(second.rankCount, first.rankCount);
|
|
expect(second.components, first.components);
|
|
});
|
|
|
|
test('a long chain is walked iteratively without overflow', () {
|
|
const length = 2000;
|
|
final ranks = _ranksFor(chainGraph(length));
|
|
|
|
expect(ranks.rankCount, length + 1);
|
|
expect(ranks.rankOf['s0'], 0);
|
|
expect(ranks.rankOf['s${length - 1}'], length - 1);
|
|
expect(ranks.rankOf[successEnd], length);
|
|
});
|
|
}
|