diff --git a/packages/newton/lib/src/friction.dart b/packages/newton/lib/src/friction.dart index c0d23209822..a055ac7d039 100644 --- a/packages/newton/lib/src/friction.dart +++ b/packages/newton/lib/src/friction.dart @@ -17,7 +17,7 @@ class Friction extends Simulation { _v = velocity; 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); diff --git a/packages/newton/test/newton_test.dart b/packages/newton/test/newton_test.dart index fb3c3435157..f3d94d23787 100644 --- a/packages/newton/test/newton_test.dart +++ b/packages/newton/test/newton_test.dart @@ -8,4 +8,24 @@ import 'package:test/test.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); + }); +}