Test Friction simulation

This commit is contained in:
Chinmay Garde 2015-07-06 12:19:37 -07:00
parent 8c91b9b7c7
commit 30965c0984
2 changed files with 22 additions and 2 deletions

View File

@ -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);

View File

@ -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);
});
}