Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
f980d665
Unverified
Commit
f980d665
authored
Jul 11, 2022
by
Jonah Williams
Committed by
GitHub
Jul 11, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a matcher for Matrix4 that includes epsilon (#107326)
parent
acb0a476
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
0 deletions
+53
-0
matchers.dart
packages/flutter_test/lib/src/matchers.dart
+20
-0
matchers_test.dart
packages/flutter_test/test/matchers_test.dart
+33
-0
No files found.
packages/flutter_test/lib/src/matchers.dart
View file @
f980d665
...
...
@@ -266,6 +266,18 @@ Matcher rectMoreOrLessEquals(Rect value, { double epsilon = precisionErrorTolera
return
_IsWithinDistance
<
Rect
>(
_rectDistance
,
value
,
epsilon
);
}
/// Asserts that two [Matrix4]s are equal, within some tolerated error.
///
/// {@macro flutter.flutter_test.moreOrLessEquals}
///
/// See also:
///
/// * [moreOrLessEquals], which is for [double]s.
/// * [offsetMoreOrLessEquals], which is for [Offset]s.
Matcher
matrixMoreOrLessEquals
(
Matrix4
value
,
{
double
epsilon
=
precisionErrorTolerance
})
{
return
_IsWithinDistance
<
Matrix4
>(
_matrixDistance
,
value
,
epsilon
);
}
/// Asserts that two [Offset]s are equal, within some tolerated error.
///
/// {@macro flutter.flutter_test.moreOrLessEquals}
...
...
@@ -1144,6 +1156,14 @@ double _rectDistance(Rect a, Rect b) {
return
delta
;
}
double
_matrixDistance
(
Matrix4
a
,
Matrix4
b
)
{
double
delta
=
0.0
;
for
(
int
i
=
0
;
i
<
16
;
i
+=
1
)
{
delta
=
math
.
max
<
double
>((
a
[
i
]
-
b
[
i
]).
abs
(),
delta
);
}
return
delta
;
}
double
_sizeDistance
(
Size
a
,
Size
b
)
{
// TODO(a14n): remove ignore when lint is updated, https://github.com/dart-lang/linter/issues/1843
// ignore: unnecessary_parenthesis
...
...
packages/flutter_test/test/matchers_test.dart
View file @
f980d665
...
...
@@ -4,6 +4,7 @@
// flutter_ignore_for_file: golden_tag (see analyze.dart)
import
'dart:math'
as
math
;
import
'dart:typed_data'
;
import
'package:flutter/rendering.dart'
;
...
...
@@ -197,6 +198,38 @@ void main() {
expect
(-
11.0
,
moreOrLessEquals
(
11.0
,
epsilon:
100.0
));
});
test
(
'matrixMoreOrLessEquals'
,
()
{
expect
(
Matrix4
.
rotationZ
(
math
.
pi
),
matrixMoreOrLessEquals
(
Matrix4
.
fromList
(<
double
>[
-
1
,
0
,
0
,
0
,
0
,
-
1
,
0
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
0
,
1
,
]))
);
expect
(
Matrix4
.
rotationZ
(
math
.
pi
),
matrixMoreOrLessEquals
(
Matrix4
.
fromList
(<
double
>[
-
2
,
0
,
0
,
0
,
0
,
-
2
,
0
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
0
,
1
,
]),
epsilon:
2
)
);
expect
(
Matrix4
.
rotationZ
(
math
.
pi
),
isNot
(
matrixMoreOrLessEquals
(
Matrix4
.
fromList
(<
double
>[
-
2
,
0
,
0
,
0
,
0
,
-
2
,
0
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
0
,
1
,
])))
);
});
test
(
'rectMoreOrLessEquals'
,
()
{
expect
(
const
Rect
.
fromLTRB
(
0.0
,
0.0
,
10.0
,
10.0
),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment