mikhailemv

Untitled

Dec 3rd, 2021
687
321 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [TestFixture]
  2. public class AnglesToCoordinatesTask_Tests
  3. {
  4.     public static double GetDistance(PointF firstJoint, PointF secondJoint)
  5.     {
  6.         double dx = secondJoint.X - firstJoint.X;
  7.         double dy = secondJoint.Y - firstJoint.Y;
  8.         return Math.Sqrt(dx * dx + dy * dy);
  9.     }
  10.  
  11.     [TestCase(Math.PI / 2, Math.PI / 2, Math.PI, Manipulator.Forearm + Manipulator.Palm, Manipulator.UpperArm)]
  12.     [TestCase(Math.PI / 2, Math.PI, Math.PI, 0, Manipulator.Forearm + Manipulator.Palm + Manipulator.UpperArm)]
  13.     [TestCase(Math.PI / 2, Math.PI, Math.PI / 2, Manipulator.Palm, Manipulator.Forearm + Manipulator.UpperArm)]
  14.     [TestCase(Math.PI / 2, Math.PI, 3 * Math.PI / 2, -Manipulator.Palm, Manipulator.Forearm + Manipulator.UpperArm)]
  15.     [TestCase(-Math.PI / 2, Math.PI / 2, Math.PI, -Manipulator.Forearm - Manipulator.Palm, -Manipulator.UpperArm)]
  16.     [TestCase(-Math.PI / 2, Math.PI, Math.PI, 0, -Manipulator.Forearm - Manipulator.Palm - Manipulator.UpperArm)]
  17.     [TestCase(-Math.PI / 2, Math.PI, -3 * Math.PI / 2,
  18.               -Manipulator.Palm, -Manipulator.Forearm - Manipulator.UpperArm)]
  19.     [TestCase(Math.PI / 2, Math.PI / 2, 3 * Math.PI / 2,
  20.               Manipulator.Forearm, Manipulator.Palm + Manipulator.UpperArm)]
  21.     [TestCase(-Math.PI / 2, -Math.PI / 2, -3 * Math.PI / 2,
  22.               Manipulator.Forearm, -Manipulator.Palm - Manipulator.UpperArm)]
  23.     [TestCase(Math.PI / 2, Math.PI / 2, 0, Manipulator.Forearm - Manipulator.Palm, Manipulator.UpperArm)]
  24.     [TestCase(Math.PI / 2, 0, 3 * Math.PI / 2, Manipulator.Palm, Manipulator.UpperArm - Manipulator.Forearm)]
  25.  
  26.     public void TestGetJointPositions(
  27.         double shoulder, double elbow, double wrist,
  28.         double palmEndX, double palmEndY)
  29.     {
  30.         var joints = AnglesToCoordinatesTask.GetJointPositions(shoulder, elbow, wrist);
  31.         Assert.AreEqual(palmEndX, joints[2].X, 1e-5, "palm endX");
  32.         Assert.AreEqual(palmEndY, joints[2].Y, 1e-5, "palm endY");
  33.         Assert.AreEqual(Manipulator.UpperArm, GetDistance(joints[0], new PointF(0, 0)),
  34.             1e-5, "upper arm length");
  35.         Assert.AreEqual(Manipulator.Forearm, GetDistance(joints[1], joints[0]),
  36.             1e-5, "forearm length");
  37.         Assert.AreEqual(Manipulator.Palm, GetDistance(joints[2], joints[1]),
  38.             1e-5, "palm length");
  39.     }
  40. }
RAW Paste Data