mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-03 04:18:25 +08:00
Add float range to test suite where needed
This commit is contained in:
@ -23,6 +23,9 @@ void effectTest(
|
|||||||
double expectedAngle = 0.0,
|
double expectedAngle = 0.0,
|
||||||
Vector2 expectedPosition,
|
Vector2 expectedPosition,
|
||||||
Vector2 expectedSize,
|
Vector2 expectedSize,
|
||||||
|
// Only use when checking a value that is not in
|
||||||
|
// the start, end or peak of an iteration
|
||||||
|
double floatRange = 0.0,
|
||||||
}) async {
|
}) async {
|
||||||
expectedPosition ??= Vector2.zero();
|
expectedPosition ??= Vector2.zero();
|
||||||
expectedSize ??= Vector2.all(100.0);
|
expectedSize ??= Vector2.all(100.0);
|
||||||
@ -39,9 +42,28 @@ void effectTest(
|
|||||||
game.update(stepDelta);
|
game.update(stepDelta);
|
||||||
timeLeft -= stepDelta;
|
timeLeft -= stepDelta;
|
||||||
}
|
}
|
||||||
expect(component.position, expectedPosition);
|
if (floatRange != 0) {
|
||||||
expect(component.angle, expectedAngle);
|
bool acceptableVector(Vector2 vector, Vector2 expectedVector) {
|
||||||
expect(component.size, expectedSize);
|
return (expectedVector - vector).length < floatRange;
|
||||||
|
}
|
||||||
|
|
||||||
|
final bool acceptablePosition =
|
||||||
|
acceptableVector(component.position, expectedPosition);
|
||||||
|
final bool acceptableSize = acceptableVector(component.size, expectedSize);
|
||||||
|
final bool acceptableAngle =
|
||||||
|
(expectedAngle - component.angle).abs() < floatRange;
|
||||||
|
assert(acceptablePosition, "Position is not correct");
|
||||||
|
assert(acceptableAngle, "Angle is not correct");
|
||||||
|
assert(acceptableSize, "Size is not correct");
|
||||||
|
} else {
|
||||||
|
expect(
|
||||||
|
component.position,
|
||||||
|
expectedPosition,
|
||||||
|
reason: "Position is not correct",
|
||||||
|
);
|
||||||
|
expect(component.angle, expectedAngle, reason: "Angle is not correct");
|
||||||
|
expect(component.size, expectedSize, reason: "Size is not correct");
|
||||||
|
}
|
||||||
expect(effect.hasFinished(), hasFinished);
|
expect(effect.hasFinished(), hasFinished);
|
||||||
expect(callback.isCalled, hasFinished);
|
expect(callback.isCalled, hasFinished);
|
||||||
game.update(0.0); // Since effects are removed before they are updated
|
game.update(0.0); // Since effects are removed before they are updated
|
||||||
|
|||||||
@ -94,10 +94,8 @@ void main() {
|
|||||||
positionComponent,
|
positionComponent,
|
||||||
moveEffect,
|
moveEffect,
|
||||||
expectedPosition: path.last,
|
expectedPosition: path.last,
|
||||||
iterations: 1.0,
|
iterations: 3.0,
|
||||||
hasFinished: false,
|
hasFinished: false,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: test that tests speed, and not only duration
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -81,14 +81,11 @@ void main() {
|
|||||||
testWidgets('RotateEffect alternation can peak', (WidgetTester tester) async {
|
testWidgets('RotateEffect alternation can peak', (WidgetTester tester) async {
|
||||||
final RotateEffect rotateEffect = effect(false, true);
|
final RotateEffect rotateEffect = effect(false, true);
|
||||||
final PositionComponent positionComponent = component();
|
final PositionComponent positionComponent = component();
|
||||||
effectTest(
|
effectTest(tester, positionComponent, rotateEffect,
|
||||||
tester,
|
expectedAngle: angleArgument,
|
||||||
positionComponent,
|
hasFinished: false,
|
||||||
rotateEffect,
|
iterations: 0.5,
|
||||||
expectedAngle: angleArgument,
|
floatRange: 0.000001);
|
||||||
hasFinished: false,
|
|
||||||
iterations: 0.5,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('RotateEffect can be infinite', (WidgetTester tester) async {
|
testWidgets('RotateEffect can be infinite', (WidgetTester tester) async {
|
||||||
@ -99,7 +96,7 @@ void main() {
|
|||||||
positionComponent,
|
positionComponent,
|
||||||
rotateEffect,
|
rotateEffect,
|
||||||
expectedAngle: angleArgument,
|
expectedAngle: angleArgument,
|
||||||
iterations: 1.0,
|
iterations: 3.0,
|
||||||
hasFinished: false,
|
hasFinished: false,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -94,7 +94,7 @@ void main() {
|
|||||||
positionComponent,
|
positionComponent,
|
||||||
scaleEffect,
|
scaleEffect,
|
||||||
expectedSize: argumentSize,
|
expectedSize: argumentSize,
|
||||||
iterations: 1.0,
|
iterations: 3.0,
|
||||||
hasFinished: false,
|
hasFinished: false,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user