mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Test Friction simulation
This commit is contained in:
parent
8c91b9b7c7
commit
30965c0984
@ -17,7 +17,7 @@ class Friction extends Simulation {
|
|||||||
_v = velocity;
|
_v = velocity;
|
||||||
|
|
||||||
double x(double time) =>
|
double x(double time) =>
|
||||||
_x + _v + Math.pow(_drag, time) / _dragNaturalLog - _v / _dragNaturalLog;
|
_x + _v * Math.pow(_drag, time) / _dragNaturalLog - _v / _dragNaturalLog;
|
||||||
|
|
||||||
double dx(double time) => _v * Math.pow(_drag, time);
|
double dx(double time) => _v * Math.pow(_drag, time);
|
||||||
|
|
||||||
|
@ -8,4 +8,24 @@ import 'package:test/test.dart';
|
|||||||
|
|
||||||
import 'package:newton/newton.dart';
|
import 'package:newton/newton.dart';
|
||||||
|
|
||||||
void main() {}
|
typedef bool SimulationTestHandler(int millis);
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
test('test_friction', () {
|
||||||
|
var friction = new Friction(0.3, 100.0, 400.0);
|
||||||
|
|
||||||
|
expect(friction.isDone(0.0), false);
|
||||||
|
expect(friction.x(0.0), 100);
|
||||||
|
expect(friction.dx(0.0), 400.0);
|
||||||
|
|
||||||
|
expect(friction.x(1.0) > 330 && friction.x(1.0) < 335, true);
|
||||||
|
|
||||||
|
expect(friction.dx(1.0), 120.0);
|
||||||
|
expect(friction.dx(2.0), 36.0);
|
||||||
|
expect(friction.dx(3.0), 10.8);
|
||||||
|
expect(friction.dx(4.0) < 3.5, true);
|
||||||
|
|
||||||
|
expect(friction.isDone(5.0), true);
|
||||||
|
expect(friction.x(5.0) > 431 && friction.x(5.0) < 432, true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user