when I testing the code, it returns an error:
At least one of the tests failed!
Test name: GetJointPositions_Test(1.5707963267948966d,0,0,0,330.0f)
Message:
palm endY
Expected: 330.0d +/- 1.0000000000000001E-05d
But was: 210.0d
Off by: 120.0d
I tried to change the test, but then this practice does not count on the site where I complete the task
using System;
using Avalonia;
using NUnit.Framework;
using static Manipulation.Manipulator;
namespace Manipulation
{
public static class AnglesToCoordinatesTask
{
/// <summary>
/// По значению углов суставов возвращает массив координат суставов
/// в порядке new []{elbow, wrist, palmEnd}
/// </summary>
public static Point[] GetJointPositions(double shoulder, double elbow, double wrist)
{
var elbowX = UpperArm * Math.Cos(shoulder);
var elbowY = UpperArm * Math.Sin(shoulder);
var elbowPos = new Point(elbowX, elbowY);
var wristAng = shoulder + elbow;
var wristX = elbowX + Forearm * Math.Cos(wristAng);
var wristY = elbowY + Forearm * Math.Sin(wristAng);
var wristPos = new Point(wristX, wristY);
var palmEndAng = wristAng + wrist;
var palmEndX = wristX + Palm * Math.Cos(palmEndAng);
var palmEndY = wristY + Palm * (-Math.Sin(palmEndAng));
var palmEndPos = new Point(palmEndX, palmEndY);
return new[]
{
elbowPos,
wristPos,
palmEndPos
};
}
}
[TestFixture]
public class AnglesToCoordinatesTask_Tests
{
[TestCase(0, 0, 0, UpperArm + Forearm + Palm, 0)]
[TestCase(Math.PI / 2, 0, 0, 0, UpperArm + Forearm + Palm)]
[TestCase(Math.PI, 0, 0, -UpperArm - Forearm - Palm, 0)]
[TestCase(0, Math.PI / 2, 0, UpperArm, UpperArm + Forearm)]
[TestCase(Math.PI / 2, Math.PI / 2, Math.PI / 2, -Forearm, UpperArm - Palm)]
[TestCase(0, Math.PI / 2, 0, UpperArm, UpperArm + Forearm)]
[TestCase(0, Math.PI / 2, 0, UpperArm, UpperArm + Forearm)]
public void GetJointPositions_Test(
double shoulder, double elbow, double wrist,
double palmEndX, double palmEndY)
{
var joints = AnglesToCoordinatesTask.GetJointPositions(shoulder, elbow, wrist);
Assert.That(joints[2].X, Is.EqualTo(palmEndX).Within(1e-5), "palm endX");
Assert.That(joints[2].Y, Is.EqualTo(palmEndY).Within(1e-5), "palm endY");
Assert.That(dis(new Point(0, 0), joints[0]), Is.EqualTo(UpperArm).Within(1e-5), "dis shoulder to elbow");
Assert.That(dis(joints[0], joints[1]), Is.EqualTo(Forearm).Within(1e-5), "dis elbow to wrist");
Assert.That(dis(joints[1], joints[2]), Is.EqualTo(Palm).Within(1e-5), "dis wrist to palm end");
}
private double dis(Point a, Point b)
{
return Math.Sqrt(Math.Pow(a.X - b.X, 2) + Math.Pow(a.Y - b.Y, 2));
}
}
}
New contributor
Night Creature is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.