mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
rectMoreOrLess equals, prep for 64bit rects (#30942)
* rectMoreOrLess equals, prep for 64bit rects
This commit is contained in:
parent
783d80d799
commit
37bc48f26e
@ -326,7 +326,7 @@ void main() {
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(tester.getRect(find.byType(FloatingActionButton)), Rect.fromLTWH(16.0, 28.0, 56.0, 56.0));
|
||||
expect(tester.getRect(find.byType(FloatingActionButton)), rectMoreOrLessEquals(Rect.fromLTWH(16.0, 28.0, 56.0, 56.0)));
|
||||
});
|
||||
|
||||
testWidgets('End-top floating action button location RTL', (WidgetTester tester) async {
|
||||
@ -342,7 +342,7 @@ void main() {
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(tester.getRect(find.byType(FloatingActionButton)), Rect.fromLTWH(16.0, 28.0, 56.0, 56.0));
|
||||
expect(tester.getRect(find.byType(FloatingActionButton)), rectMoreOrLessEquals(Rect.fromLTWH(16.0, 28.0, 56.0, 56.0)));
|
||||
});
|
||||
|
||||
testWidgets('Start-top floating action button location RTL', (WidgetTester tester) async {
|
||||
@ -358,7 +358,7 @@ void main() {
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(tester.getRect(find.byType(FloatingActionButton)), Rect.fromLTWH(800.0 - 56.0 - 16.0, 28.0, 56.0, 56.0));
|
||||
expect(tester.getRect(find.byType(FloatingActionButton)), rectMoreOrLessEquals(Rect.fromLTWH(800.0 - 56.0 - 16.0, 28.0, 56.0, 56.0)));
|
||||
});
|
||||
|
||||
testWidgets('End-top floating action button location LTR', (WidgetTester tester) async {
|
||||
@ -371,7 +371,7 @@ void main() {
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(tester.getRect(find.byType(FloatingActionButton)), Rect.fromLTWH(800.0 - 56.0 - 16.0, 28.0, 56.0, 56.0));
|
||||
expect(tester.getRect(find.byType(FloatingActionButton)), rectMoreOrLessEquals(Rect.fromLTWH(800.0 - 56.0 - 16.0, 28.0, 56.0, 56.0)));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -762,13 +762,13 @@ void main() {
|
||||
|
||||
expect(tester.getRect(find.byKey(appBar)), Rect.fromLTRB(0.0, 0.0, 800.0, 43.0));
|
||||
expect(tester.getRect(find.byKey(body)), Rect.fromLTRB(0.0, 43.0, 800.0, 348.0));
|
||||
expect(tester.getRect(find.byKey(floatingActionButton)), Rect.fromLTRB(36.0, 255.0, 113.0, 332.0));
|
||||
expect(tester.getRect(find.byKey(floatingActionButton)), rectMoreOrLessEquals(Rect.fromLTRB(36.0, 255.0, 113.0, 332.0)));
|
||||
expect(tester.getRect(find.byKey(persistentFooterButton)), Rect.fromLTRB(28.0, 357.0, 128.0, 447.0)); // Note: has 8px each top/bottom padding.
|
||||
expect(tester.getRect(find.byKey(drawer)), Rect.fromLTRB(596.0, 0.0, 800.0, 600.0));
|
||||
expect(tester.getRect(find.byKey(bottomNavigationBar)), Rect.fromLTRB(0.0, 515.0, 800.0, 600.0));
|
||||
expect(tester.getRect(find.byKey(insideAppBar)), Rect.fromLTRB(20.0, 30.0, 750.0, 43.0));
|
||||
expect(tester.getRect(find.byKey(insideBody)), Rect.fromLTRB(20.0, 43.0, 750.0, 348.0));
|
||||
expect(tester.getRect(find.byKey(insideFloatingActionButton)), Rect.fromLTRB(36.0, 255.0, 113.0, 332.0));
|
||||
expect(tester.getRect(find.byKey(insideFloatingActionButton)), rectMoreOrLessEquals(Rect.fromLTRB(36.0, 255.0, 113.0, 332.0)));
|
||||
expect(tester.getRect(find.byKey(insidePersistentFooterButton)), Rect.fromLTRB(28.0, 357.0, 128.0, 447.0));
|
||||
expect(tester.getRect(find.byKey(insideDrawer)), Rect.fromLTRB(596.0, 30.0, 750.0, 540.0));
|
||||
expect(tester.getRect(find.byKey(insideBottomNavigationBar)), Rect.fromLTRB(20.0, 515.0, 750.0, 540.0));
|
||||
@ -857,12 +857,12 @@ void main() {
|
||||
|
||||
expect(tester.getRect(find.byKey(appBar)), Rect.fromLTRB(0.0, 0.0, 800.0, 43.0));
|
||||
expect(tester.getRect(find.byKey(body)), Rect.fromLTRB(0.0, 43.0, 800.0, 400.0));
|
||||
expect(tester.getRect(find.byKey(floatingActionButton)), Rect.fromLTRB(36.0, 307.0, 113.0, 384.0));
|
||||
expect(tester.getRect(find.byKey(floatingActionButton)), rectMoreOrLessEquals(Rect.fromLTRB(36.0, 307.0, 113.0, 384.0)));
|
||||
expect(tester.getRect(find.byKey(persistentFooterButton)), Rect.fromLTRB(28.0, 442.0, 128.0, 532.0)); // Note: has 8px each top/bottom padding.
|
||||
expect(tester.getRect(find.byKey(drawer)), Rect.fromLTRB(596.0, 0.0, 800.0, 600.0));
|
||||
expect(tester.getRect(find.byKey(insideAppBar)), Rect.fromLTRB(20.0, 30.0, 750.0, 43.0));
|
||||
expect(tester.getRect(find.byKey(insideBody)), Rect.fromLTRB(20.0, 43.0, 750.0, 400.0));
|
||||
expect(tester.getRect(find.byKey(insideFloatingActionButton)), Rect.fromLTRB(36.0, 307.0, 113.0, 384.0));
|
||||
expect(tester.getRect(find.byKey(insideFloatingActionButton)), rectMoreOrLessEquals(Rect.fromLTRB(36.0, 307.0, 113.0, 384.0)));
|
||||
expect(tester.getRect(find.byKey(insidePersistentFooterButton)), Rect.fromLTRB(28.0, 442.0, 128.0, 532.0));
|
||||
expect(tester.getRect(find.byKey(insideDrawer)), Rect.fromLTRB(596.0, 30.0, 750.0, 540.0));
|
||||
});
|
||||
|
@ -222,6 +222,23 @@ Matcher moreOrLessEquals(double value, { double epsilon = 1e-10 }) {
|
||||
return _MoreOrLessEquals(value, epsilon);
|
||||
}
|
||||
|
||||
/// Asserts that two [Rect]s are equal, within some tolerated error.
|
||||
///
|
||||
/// Two values are considered equal if the difference between them is within
|
||||
/// 1e-10 of the larger one. This is an arbitrary value which can be adjusted
|
||||
/// using the `epsilon` argument. This matcher is intended to compare floating
|
||||
/// point numbers that are the result of different sequences of operations, such
|
||||
/// that they may have accumulated slightly different errors.
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [moreOrLessEquals], which is for [double]s.
|
||||
/// * [within], which offers a generic version of this functionality that can
|
||||
/// be used to match [Rect]s as well as other types.
|
||||
Matcher rectMoreOrLessEquals(Rect value, { double epsilon = 1e-10 }) {
|
||||
return _IsWithinDistance<Rect>(_rectDistance, value, epsilon);
|
||||
}
|
||||
|
||||
/// Asserts that two [String]s are equal after normalizing likely hash codes.
|
||||
///
|
||||
/// A `#` followed by 5 hexadecimal digits is assumed to be a short hash code
|
||||
@ -1004,6 +1021,8 @@ double _sizeDistance(Size a, Size b) {
|
||||
///
|
||||
/// * [moreOrLessEquals], which is similar to this function, but specializes in
|
||||
/// [double]s and has an optional `epsilon` parameter.
|
||||
/// * [rectMoreOrLessEquals], which is similar to this function, but
|
||||
/// specializes in [Rect]s and has an optional `epsilon` parameter.
|
||||
/// * [closeTo], which specializes in numbers only.
|
||||
Matcher within<T>({
|
||||
@required num distance,
|
||||
|
@ -185,6 +185,23 @@ void main() {
|
||||
expect(-11.0, moreOrLessEquals(11.0, epsilon: 100.0));
|
||||
});
|
||||
|
||||
test('rectMoreOrLessEquals', () {
|
||||
expect(
|
||||
Rect.fromLTRB(0.0, 0.0, 10.0, 10.0),
|
||||
rectMoreOrLessEquals(Rect.fromLTRB(1e-11, 0.0, 10.0, 10.0000000001)),
|
||||
);
|
||||
|
||||
expect(
|
||||
Rect.fromLTRB(11.0, 11.0, 20.0, 20.0),
|
||||
isNot(rectMoreOrLessEquals(Rect.fromLTRB(-11.0, -11.0, 20.0, 20.0), epsilon: 1.0)),
|
||||
);
|
||||
|
||||
expect(
|
||||
Rect.fromLTRB(11.0, 11.0, 20.0, 20.0),
|
||||
rectMoreOrLessEquals(Rect.fromLTRB(-11.0, -11.0, 20.0, 20.0), epsilon: 100.0),
|
||||
);
|
||||
});
|
||||
|
||||
test('within', () {
|
||||
expect(0.0, within<double>(distance: 0.1, from: 0.05));
|
||||
expect(0.0, isNot(within<double>(distance: 0.1, from: 0.2)));
|
||||
|
Loading…
Reference in New Issue
Block a user