2026-09-18 16:50:12 +08:00
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
|
import 'package:sequence_diagram/model/models.dart';
|
|
|
|
|
import 'package:sequence_diagram/model/units.dart';
|
|
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
|
group('units', () {
|
|
|
|
|
test('time conversion', () {
|
|
|
|
|
const UnitSettings u = UnitSettings(timeUnit: TimeUnit.s);
|
|
|
|
|
expect(tfmt(2400, u), '2.400 s');
|
|
|
|
|
expect(tfmt(467, u), '0.467 s');
|
|
|
|
|
const UnitSettings ms = UnitSettings(timeUnit: TimeUnit.ms);
|
|
|
|
|
expect(tfmt(467, ms), '467 ms');
|
|
|
|
|
expect(parseDuration('700ms', u), 700);
|
|
|
|
|
expect(parseDuration('0.7s', u), 700);
|
|
|
|
|
expect(parseDuration('0.7', u), 700);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('phase conversion', () {
|
|
|
|
|
expect(pfmt(105, const UnitSettings()), '105.0°');
|
|
|
|
|
expect(pfmt(105, const UnitSettings(phaseUnit: PhaseUnit.percent)), '29.17%');
|
|
|
|
|
expect(parsePhase('29.17%'), closeTo(105.012, 0.01));
|
|
|
|
|
expect(parsePhase('105°'), 105);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('snap and normalize', () {
|
|
|
|
|
expect(snapTo(103, 5), 105);
|
|
|
|
|
expect(normalizeAngle(-10), 350);
|
|
|
|
|
expect(normalizeAngle(370), 10);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
group('model', () {
|
|
|
|
|
test('wrap detection', () {
|
|
|
|
|
final Action a = Action(
|
|
|
|
|
id: 'A8',
|
|
|
|
|
name: '清洁',
|
|
|
|
|
stationId: 'ST3',
|
|
|
|
|
driver: '',
|
|
|
|
|
startAngle: 340,
|
|
|
|
|
durationAngle: 45,
|
|
|
|
|
layer: 7,
|
|
|
|
|
color: kActionPalette[0],
|
|
|
|
|
);
|
|
|
|
|
expect(a.wrap, isTrue);
|
|
|
|
|
expect(a.endAngle, 385);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('json round trip', () {
|
|
|
|
|
final Project p = Project.demo();
|
|
|
|
|
final String encoded = p.encode();
|
|
|
|
|
final Project decoded = Project.decode(encoded);
|
|
|
|
|
expect(decoded.actions.length, p.actions.length);
|
|
|
|
|
expect(decoded.stations.length, p.stations.length);
|
|
|
|
|
expect(decoded.phaseZones.length, p.phaseZones.length);
|
|
|
|
|
expect(decoded.actions.last.deps.first.type, DepType.fs);
|
2026-09-18 17:14:27 +08:00
|
|
|
expect(decoded.cycle.durationMs, 3600);
|
2026-09-18 16:50:12 +08:00
|
|
|
expect(decoded.actions.last.color, p.actions.last.color);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|