Pie*_*lle -4 c# trigonometry xunit xunit.net
好的,这就是情况......
我目前正在为我的数学和物理学课程做一个项目.
我完成了解决方案的编码,并运行了我老师为我们制作的xUnit测试.
其中90%的人失败了.
我有一个Calculator.cs文件,其中包含我编码的所有方法.每个三角函数方法都返回一个元组,然后在一个xUnit.Assert.Equal中使用Tuple的项目(expectedResult,Math.Round(calculatorTuple.Item1,4)) ...
例如......我有一个名为Trig_Calculate_Adjacent_Hypotenuse的方法,它接受两个双精度作为它的参数(角度,度数和相反)
计算器发现Adjacent等于15.4235 ...但我的实际计算显示它是56.7128.因此,当测试运行时,它会执行Assert.Equal(56.7128,15.4235)并发现这两个答案不相等.(明显)
我多次查看了我的Calculator.cs文件中的代码......并且在我的生活中找不到问题.
这是我的方法,所以你可以看看它:
public static Tuple<double,double> Trig_Calculate_Adjacent_Hypotenuse(double Angle, double Opposite)
{
double Hypotenuse;
double Adjacent;
// SOH CAH TOA
// Using TOA to find Adjacent
// so Adjacent = Opposite / Tan(Angle)
// so Adjacent = 10 / Tan(10)
// which means Adjacent = 56.7128
// However my calculator finds 15.4235 instead...
Adjacent = Opposite / Math.Tan(Calculator.DegreesToRadians(Angle));
// Using SOH to find Hypotenuse
// so Hypotenuse = Opposite / Sin(Angle)
// so Hypotenuse = 10 / Sin(10)
// which means Hypotenuse = 57.5877
// However my calculator finds something different... (unknown due to Adjacent's failure)
Hypotenuse = Opposite / Math.Sin(Calculator.DegreesToRadians(Angle));
return new Tuple<double, double>(Adjacent, Hypotenuse);
}
Run Code Online (Sandbox Code Playgroud)
这是测试方法:
[Theory]
// Student Data
[InlineData(10, 10, 56.7128, 57.5877)]
public void TestCalculateAdjacentHypotenuse(double Angle, double Opposite, double Adjacent, double Hypotenuse)
{
// Act - performing the action
Tuple<double, double> results = Calculator.Trig_Calculate_Adjacent_Hypotenuse(Angle, Opposite);
// Assert - did we get back the correct answer
Assert.Equal(Adjacent, Math.Round(results.Item1, 4));
Assert.Equal(Hypotenuse, Math.Round(results.Item2, 4));
}
Run Code Online (Sandbox Code Playgroud)
我希望你们能帮助我找出问题所在!:)
谢谢!