BikePhysicsTest.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using AdditionalMathf;
  6. using NUnit.Framework;
  7. using Phscs;
  8. using UnityEditor;
  9. using UnityEngine;
  10. using UnityEngine.TestTools;
  11. public class BikePhysicsTest
  12. {
  13. private const float DELTA = 1/3.6f;
  14. [Test]
  15. public void ZeroSlopeDoesntChangeSpeed()
  16. {
  17. const float speed = 30f/3.6f;
  18. var slopeSpeed = BicyclePhysics.SpeedAtGradientForSpeedAtFlat(speed, 80f, 0f);
  19. Assert.AreEqual(speed, slopeSpeed, DELTA);
  20. }
  21. [Test]
  22. public void PositiveGradientAffectsSpeed()
  23. {
  24. const float speed = 30f/3.6f;
  25. const float mass = 80f;
  26. var grad = .05f;
  27. var slopeSpeed = BicyclePhysics.SpeedAtGradientForSpeedAtFlat(speed, mass, grad);
  28. Assert.AreEqual(16.34544/3.6f, slopeSpeed, DELTA);
  29. grad = .1f;
  30. slopeSpeed = BicyclePhysics.SpeedAtGradientForSpeedAtFlat(speed, mass, grad);
  31. Assert.AreEqual(9.44704/3.6f, slopeSpeed, DELTA);
  32. grad = .15f;
  33. slopeSpeed = BicyclePhysics.SpeedAtGradientForSpeedAtFlat(speed, mass, grad);
  34. Assert.AreEqual(6.43698/3.6f, slopeSpeed, DELTA);
  35. }
  36. [Test]
  37. public void NegativeGradientAffectsSpeed()
  38. {
  39. const float speed = 30f/3.6f;
  40. const float mass = 80f;
  41. var grad = -.05f;
  42. var slopeSpeed = BicyclePhysics.SpeedAtGradientForSpeedAtFlat(speed, mass, grad);
  43. Assert.AreEqual(44.5824/3.6f, slopeSpeed, DELTA);
  44. grad = -.1f;
  45. slopeSpeed = BicyclePhysics.SpeedAtGradientForSpeedAtFlat(speed, mass, grad);
  46. Assert.AreEqual(56.91384/3.6f, slopeSpeed, DELTA);
  47. grad = -.15f;
  48. slopeSpeed = BicyclePhysics.SpeedAtGradientForSpeedAtFlat(speed, mass, grad);
  49. Assert.AreEqual(67.43808/3.6f, slopeSpeed, DELTA);
  50. }
  51. }