public void GravitationalAcceleration_DoubleDataReturnsCorrectValue() { // prereq Approx_Works(); Scientific_Works(); // arrange // Earth radius (meters) 6.371 x 10^6 double distance = PMath.Scientific(6.371, 6); // kg double massA = 68; // Earth mass (kg) 5.97237f x 10^24 double massB = PMath.Scientific(5.97237, 24); // m/s/s double expected = 9.80665d; // act double gravity = PMath.GravitationalAcceleration(massA, massB, distance); // assert Assert.AreEqual(expected, gravity, "Gravitational Force: {0} != {1}", expected, gravity); }
public void EscapeVelocity_ReturnsCorrectValue() { // prereq Approx_Works(); Scientific_Works(); GravitationalAcceleration_FloatDataReturnsCorrectValue(); // arrange // mean Earth radius (km => meters) float distance = (float)PMath.Scientific(6.371, 6); // typical person mass (kg) float personMass = 70; // Earth mass (kg) // Ref: https://en.wikipedia.org/wiki/Earth_mass double earthMass = PMath.Scientific(5.97237, 24); // force is m/s/s float force = PMath.GravitationalAcceleration(personMass, (float)earthMass, distance); // escape velocity on earth is 11.2 km/s (km/s => m/s) float expected = 11.2f * 1000; // act (m/s) double velocity = PMath.EscapeVelocity(force, distance); // assert Assert.IsTrue(PMath.Approx(expected, (float)velocity, 1), "Escape Velocity: expected " + expected + " m/s != actual " + velocity + " m/s"); }
public void Scientific_Works() { // arrange // Earth mass (kg) 5.97237f x 10^24 double coefficient = 5.97237; int exponent = 24; double actual = coefficient * Mathd.Pow(10, exponent); // act double result = PMath.Scientific(coefficient, exponent); // assert Assert.AreEqual(actual, result); }