gravity_simulation_test.dart 1.09 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6 7 8
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/physics.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
9
  test('Gravity simulation 1', () {
10 11
    expect(GravitySimulation(9.81, 10.0, 0.0, 0.0), hasOneLineDescription);
    expect(GravitySimulation(9.81, 10.0, 0.0, 0.0).x(10.0), moreOrLessEquals(50.0 * 9.81 + 10.0));
12
  });
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32

  test('Gravity simulation 2', () {
    final GravitySimulation gravity = GravitySimulation(-10, 0.0, 6.0, 10.0);

    expect(gravity.x(0.0), equals(0.0));
    expect(gravity.dx(0.0), equals(10.0));
    expect(gravity.isDone(0.0), isFalse);

    expect(gravity.x(1.0), equals(5.0));
    expect(gravity.dx(1.0), equals(0.0));
    expect(gravity.isDone(0.2), isFalse);

    expect(gravity.x(2.0), equals(0.0));
    expect(gravity.dx(2.0), equals(-10.0));
    expect(gravity.isDone(2.0), isFalse);

    expect(gravity.x(3.0), equals(-15.0));
    expect(gravity.dx(3.0), equals(-20.0));
    expect(gravity.isDone(3.0), isTrue);
  });
33
}