Commit c3aaf8aa authored by Chinmay Garde's avatar Chinmay Garde

Test individial spring types

parent ab7a6dd6
......@@ -12,7 +12,7 @@ class SpringDesc {
final double springConstant;
/// The damping coefficient.
/// Note: Not to be confused with the damping ratio (zeta). Use the separate
/// Note: Not to be confused with the damping ratio. Use the separate
/// constructor provided for this purpose
final double damping;
......
......@@ -74,4 +74,62 @@ void main() {
var other = new Spring(new SpringDesc(1.0, 100.0, 20.0), 0.0, 20.0, 20.0);
expect(other.type, SpringType.criticallyDamped);
});
test('crit_spring', () {
var crit = new Spring(
new SpringDesc.withDampingRatio(1.0, 100.0, 1.0), 0.0, 500.0, 0.0);
expect(crit.type, SpringType.criticallyDamped);
expect(crit.isDone(0.0), false);
expect(crit.x(0.0), 0.0);
expect(crit.dx(0.0), 5000.0);
expect(crit.x(0.25).floor(), 458.0);
expect(crit.x(0.50).floor(), 496.0);
expect(crit.x(0.75).floor(), 499.0);
expect(crit.dx(0.25).floor(), 410);
expect(crit.dx(0.50).floor(), 33);
expect(crit.dx(0.75).floor(), 2);
expect(crit.isDone(1.50), true);
expect(crit.x(1.5) > 499.0 && crit.x(1.5) < 501.0, true);
expect(crit.dx(1.5) < 0.1, true /* basically within tolerance */);
});
test('overdamped_spring', () {
var over = new Spring(
new SpringDesc.withDampingRatio(1.0, 100.0, 1.25), 0.0, 500.0, 0.0);
expect(over.type, SpringType.overDamped);
expect(over.isDone(0.0), false);
expect(over.x(0.0), 0.0);
expect(over.x(0.5).floor(), 445.0);
expect(over.x(1.0).floor(), 495.0);
expect(over.x(1.5).floor(), 499.0);
expect(over.dx(0.5).floor(), 273.0);
expect(over.dx(1.0).floor(), 22.0);
expect(over.dx(1.5).floor(), 1.0);
expect(over.isDone(3.0), true);
});
test('underdamped_spring', () {
var under = new Spring(
new SpringDesc.withDampingRatio(1.0, 100.0, 0.25), 0.0, 300.0, 0.0);
expect(under.type, SpringType.underDamped);
expect(under.isDone(0.0), false);
// Overshot with negative velocity
expect(under.x(1.0).floor(), 325);
expect(under.dx(1.0).floor(), -65);
expect(under.dx(6.0).floor(), 0.0);
expect(under.x(6.0).floor(), 299);
expect(under.isDone(6.0), true);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment