Files
EasyDesignCollection/test/snap_test.dart
T

73 lines
2.1 KiB
Dart
Raw Permalink Normal View History

// 动作条整体拖拽吸附:起点/终点同时匹配最近端点、整 5° 与分区边界。
import 'package:flutter_test/flutter_test.dart';
import 'package:sequence_diagram/modules/sequence/layout/snap.dart';
import 'package:sequence_diagram/model/models.dart';
Project _project(List<Action> actions) {
return Project(
name: 'snap',
cycle: const Cycle(durationMs: 2400),
stations: const <Station>[
Station(id: 'ST1', name: 'S', order: 0, color: 0xFF4CC9F0),
],
actions: actions,
units: const UnitSettings(),
viewState: const ViewState(mode: ViewMode.bar),
);
}
Action _a(String id, double start, double duration) {
return Action(
id: id,
name: id,
stationId: 'ST1',
driver: '',
startAngle: start,
durationAngle: duration,
layer: 0,
color: 0xFF4CC9F0,
);
}
void main() {
test('整体拖动:起点吸附到上游动作结束角', () {
final Project p = _project(<Action>[_a('A1', 0, 40), _a('A2', 80, 40)]);
final (double start, double? guide) = snapActionStart(
project: p,
excludeId: 'A2',
rawStart: 41.5,
duration: 40,
toleranceDeg: 3.5,
);
expect(start, closeTo(40, 0.001));
expect(guide, closeTo(40, 0.001));
});
test('整体拖动:终点吸附到下游动作起始角', () {
final Project p = _project(<Action>[_a('A1', 100, 40), _a('A2', 63, 38)]);
final (double start, double? guide) = snapActionStart(
project: p,
excludeId: 'A2',
rawStart: 63,
duration: 38,
toleranceDeg: 2.5,
);
// 末端 101 距 A1 起点 100 仅 1°,优先于起点附近的 5° 网格。
expect(start, closeTo(62, 0.001));
expect(guide, closeTo(100, 0.001));
});
test('整体拖动:容差外不吸附', () {
final Project p = _project(<Action>[_a('A1', 0, 40), _a('A2', 123.4, 40)]);
final (double start, double? guide) = snapActionStart(
project: p,
excludeId: 'A2',
rawStart: 123.4,
duration: 40,
toleranceDeg: 1.0,
);
expect(start, closeTo(123.4, 0.001));
expect(guide, isNull);
});
}